metrics: COM_STMT_CLOSE incorrectly inherits previous stmt type
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
1. Start TiDB server.
2. Connect with a MySQL client that uses binary protocol prepared statements.
3. Execute the following sequence:
- `COM_STMT_PREPARE` with `SELECT ...`
- `COM_STMT_EXECUTE`
- `COM_STMT_CLOSE`
4. Observe `QueryDurationHistogram` (or related metrics) labeled by `sqlType`.
`sum(rate(tidb_server_handle_query_duration_seconds_count{k8s_cluster="$k8s_cluster",tidb_cluster="$tidb_cluster", sql_type!="internal"}[1m])) by (sql_type)`
The promQL above is used in the right plot (CPS by SQL Type) of the following screenshot (the left plot is QPS for comparison):
### 2. What did you expect to see? (Required)
Only the `COM_STMT_EXECUTE` step should carry the real statement type (`Select`, `Update`, etc.).
`COM_STMT_PREPARE` and `COM_STMT_CLOSE` should use a generic label (e.g. `General`).
### 3. What did you see instead (Required)
`COM_STMT_CLOSE` is labeled with the previous statement type (e.g. `Select`), which pollutes the metrics for non-execute commands.
### 4. What is your TiDB version? (Required)
7670ef5ff229c8a477b55030fe550a11ad33c747
Contributor guide
Assessment
This issue has not been assessed yet.