Skip to content

Commit 04321e2

Browse files
committed
Adding error.user
1 parent ad48328 commit 04321e2

File tree

9 files changed

+737
-13
lines changed

9 files changed

+737
-13
lines changed

docs/content/metrics/domains/error.global/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ None.
4646
|no | |Do not return the total number of errors raised|
4747
|only| |Only return the total number of errors raised|
4848

49-
If `all` is not set to `yes` the total will only reflect those error that are specifically included or not excluded from collection.
49+
If `all` is not set to `yes` the total will only reflect those errors that are specifically included or not excluded from collection.
5050

5151
### `truncate-table`
5252

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: "errro.user"
3+
---
4+
5+
The `errro.user` domain includes server error metrics grouped by user from [error summary tables](https://dev.mysql.com/doc/refman/en/performance-schema-error-summary-tables.html).
6+
7+
{{< toc >}}
8+
9+
## Usage
10+
11+
For example:
12+
13+
```
14+
mysql> SELECT * FROM performance_schema.events_errors_summary_by_user_by_error WHERE error_number = 3024 AND USER IN ('example')\G
15+
*************************** 1. row ***************************
16+
USER: example
17+
ERROR_NUMBER: 3024
18+
ERROR_NAME: ER_QUERY_TIMEOUT
19+
SQL_STATE: HY000
20+
SUM_ERROR_RAISED: 1
21+
SUM_ERROR_HANDLED: 0
22+
FIRST_SEEN: 2025-04-30 16:30:16
23+
LAST_SEEN: 2025-04-30 16:30:16
24+
```
25+
26+
The `SUM_ERR_RAISED` value is used for the Blip `raised` metric. `ERROR_NUMBER`, `ERROR_NAME`, and `USER` are used to group the metric.
27+
28+
## Derived Metrics
29+
30+
None.
31+
32+
## Options
33+
34+
### `all`
35+
36+
|Value|Default|Description|
37+
|-----|-------|-----------|
38+
|yes |&check; |Collect metrics on _all_ errors (not recommended)|
39+
|no | |Collect only metrics for the errors listed in the plan|
40+
|exclude| |Collect metrics only for errors that are not listed in the plan|
41+
42+
### `total`
43+
44+
|Value|Default|Description|
45+
|-----|-------|-----------|
46+
|yes |&check; |Return the total number of errors raised|
47+
|no | |Do not return the total number of errors raised|
48+
|only| |Only return the total number of errors raised|
49+
50+
If `all` is not set to `yes` the total will only reflect those errors that are specifically included or not excluded from collection.
51+
52+
### `include`
53+
54+
| | |
55+
|---|---|
56+
|**Value Type**|CSV string of users|
57+
|**Default**||
58+
59+
A comma-separated list of users to include. Overrides option `exclude`.
60+
61+
### `exclude`
62+
63+
| | |
64+
|---|---|
65+
|**Value Type**|CSV string of users|
66+
|**Default**|event_scheduler|
67+
68+
A comma-separated list of users to exclude. Ignored if `include` is set.
69+
70+
### `truncate-table`
71+
72+
|Value|Default|Description|
73+
|---|---|---|
74+
|yes| |Truncate table after each successful collection|
75+
|no|&check; |Do not truncate table|
76+
77+
If the table is truncated (default), the metrics are delta counters.
78+
Else, the values are cumulative counters.
79+
80+
### `truncate-timeout`
81+
82+
| | |
83+
|---|---|
84+
|**Value Type**|[Duration string](https://pkg.go.dev/time#ParseDuration)|250ms|
85+
|**Default**|250ms|
86+
87+
Sets `@@session.lock_wait_timeout` to avoid waiting too long when truncating the table.
88+
Normally, truncating a table is nearly instantaneous, but metadata locks can block the operation.
89+
90+
### `truncate-on-startup`
91+
92+
|Value|Default|Description|
93+
|---|---|---|
94+
|yes|&check;|Truncate source table on start of metric collection|
95+
|no| |Do not truncate source table on startup|
96+
97+
Truncates the source table when Blip starts. The timeout use will be the same as specified by `truncate-timeout`.
98+
99+
## Group Keys
100+
101+
|Key|Value|
102+
|---|---|
103+
|`error_nunmber`|The error number or an empty string for a total|
104+
|`error_name`|The short error name or an empty string for a total|
105+
106+
## Meta
107+
108+
None.
109+
110+
## Error Policies
111+
112+
|Name|MySQL Error|
113+
|----|-----------|
114+
|`truncate-timeout`|Error truncating table|
115+
116+
## MySQL Config
117+
118+
See
119+
* [29.12.20.11 Error Summary Tables](https://dev.mysql.com/doc/refman/8.4/en/performance-schema-error-summary-tables.html)
120+
121+
and related pages in the MySQL manual.
122+
123+
## Changelog
124+
125+
|Blip Version|Change|
126+
|------------|------|
127+
|TBD |Domain added|

docs/content/metrics/quick-ref.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The rest are reserved for future use.
2020
|error|MySQL, client, and query errors||
2121
|error.client|Client errors||
2222
|[error.global](domains#error.global)|Global error counts and rates [`Error Summary Tables`](https://dev.mysql.com/doc/refman/8.4/en/performance-schema-error-summary-tables.html)|TBD|
23+
|[error.user](domains#error.user)|Error counts and rates by user [`Error Summary Tables`](https://dev.mysql.com/doc/refman/8.4/en/performance-schema-error-summary-tables.html)|TBD|
2324
|error.query|Query errors||
2425
|error.repl|Replication errors||
2526
|event|[MySQL Event Scheduler](https://dev.mysql.com/doc/refman/8.0/en/event-scheduler.html)||

metrics/error.global/error.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ const (
2727

2828
GRP_ERR_NUMBER = "error_number"
2929
GRP_ERR_NAME = "error_name"
30+
31+
TRUNCATE_QUERY = "TRUNCATE TABLE performance_schema.events_errors_summary_global_by_error"
3032
)
3133

3234
type errorLevelOptions struct {
3335
query string
3436
params []any
3537
truncate bool
36-
truncateQuery string
3738
truncateTimeout time.Duration
3839
lockWaitQuery string
3940
stop bool
@@ -42,7 +43,7 @@ type errorLevelOptions struct {
4243
emitTotal bool
4344
}
4445

45-
// ErrorGlobal collects error summary information for the error.server domain.
46+
// ErrorGlobal collects error summary information for the error.global domain.
4647
// https://dev.mysql.com/doc/refman/8.4/en/performance-schema-error-summary-tables.html
4748
type ErrorGlobal struct {
4849
db *sql.DB
@@ -237,15 +238,12 @@ func (t *ErrorGlobal) Collect(ctx context.Context, levelName string) ([]blip.Met
237238
errors int64
238239
errorNum string
239240
errorName string
240-
values []any
241241
total float64
242242
)
243243

244-
values = []any{&errors, &errorNum, &errorName}
245-
246244
// Are we truncating the table?
247245
for rows.Next() {
248-
if err = rows.Scan(values...); err != nil {
246+
if err = rows.Scan(&errors, &errorNum, &errorName); err != nil {
249247
return nil, err
250248
}
251249

@@ -299,7 +297,7 @@ func (t *ErrorGlobal) truncate(ctx context.Context, levelName string) error {
299297
if err == nil {
300298
trCtx, cancelFn := context.WithTimeout(ctx, o.truncateTimeout)
301299
defer cancelFn()
302-
_, err = conn.ExecContext(trCtx, o.truncateQuery)
300+
_, err = conn.ExecContext(trCtx, TRUNCATE_QUERY)
303301
}
304302
}
305303

metrics/error.global/query.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313

1414
func ErrorsQuery(dom blip.Domain) (*errorLevelOptions, error) {
1515
var query string
16-
var truncateQuery string
1716
query = "SELECT SUM_ERROR_RAISED, ERROR_NUMBER, ERROR_NAME FROM performance_schema.events_errors_summary_global_by_error"
18-
truncateQuery = "TRUNCATE TABLE performance_schema.events_errors_summary_global_by_error"
1917

2018
if dom.Options[OPT_TOTAL] == "only" {
2119
query = "SELECT SUM(SUM_ERROR_RAISED), '' ERROR_NUMBER, '' ERROR_NAME FROM performance_schema.events_errors_summary_global_by_error"
@@ -27,9 +25,8 @@ func ErrorsQuery(dom blip.Domain) (*errorLevelOptions, error) {
2725
}
2826

2927
return &errorLevelOptions{
30-
query: query + where,
31-
params: params,
32-
truncateQuery: truncateQuery,
28+
query: query + where,
29+
params: params,
3330
}, nil
3431
}
3532

0 commit comments

Comments
 (0)