From c19c6df63bdb8b6a65ea3e2321d21466fabeb715 Mon Sep 17 00:00:00 2001 From: ZhouXing19 Date: Fri, 15 Aug 2025 16:38:56 -0400 Subject: [PATCH] metric: add labels for `sql.*.started.count` Previously, only metrics for *executed* `SELECT|UPDATE|DELETE|INSERT` statements are labeled, while their *started* equivalent are not labeled. This commit is to label these metrics. Ref #143536 Release note (ops change): sql.select.started.count, sql.insert.started.count, sql.update.started.count, sql.delete.started.count are now labeled with sql.started.count. --- docs/generated/metrics/metrics.yaml | 140 +++++++++++++++------------- pkg/sql/exec_util.go | 48 ++++++---- 2 files changed, 108 insertions(+), 80 deletions(-) diff --git a/docs/generated/metrics/metrics.yaml b/docs/generated/metrics/metrics.yaml index 501b0b9e37c6..e616d674f967 100644 --- a/docs/generated/metrics/metrics.yaml +++ b/docs/generated/metrics/metrics.yaml @@ -518,6 +518,25 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE + - name: sql.delete.started.count + exported_name: sql_delete_started_count + labeled_name: 'sql.started.count{query_type: delete}' + description: Number of SQL DELETE statements started + y_axis_label: SQL Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE + how_to_use: This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application. + - name: sql.delete.started.count.internal + exported_name: sql_delete_started_count_internal + labeled_name: 'sql.started.count{query_type: delete, query_internal: true}' + description: Number of SQL DELETE statements started (internal queries) + y_axis_label: SQL Internal Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE - name: sql.distsql.contended_queries.count exported_name: sql_distsql_contended_queries_count description: Number of SQL queries that experienced contention @@ -584,6 +603,25 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE + - name: sql.insert.started.count + exported_name: sql_insert_started_count + labeled_name: 'sql.started.count{query_type: insert}' + description: Number of SQL INSERT statements started + y_axis_label: SQL Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE + how_to_use: This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application. + - name: sql.insert.started.count.internal + exported_name: sql_insert_started_count_internal + labeled_name: 'sql.started.count{query_type: insert, query_internal: true}' + description: Number of SQL INSERT statements started (internal queries) + y_axis_label: SQL Internal Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE - name: sql.mem.root.current exported_name: sql_mem_root_current description: Current sql statement memory usage for root @@ -780,6 +818,25 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE + - name: sql.select.started.count + exported_name: sql_select_started_count + labeled_name: 'sql.started.count{query_type: select}' + description: Number of SQL SELECT statements started + y_axis_label: SQL Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE + how_to_use: This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application. + - name: sql.select.started.count.internal + exported_name: sql_select_started_count_internal + labeled_name: 'sql.started.count{query_type: select, query_internal: true}' + description: Number of SQL SELECT statements started (internal queries) + y_axis_label: SQL Internal Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE - name: sql.service.latency exported_name: sql_service_latency description: Latency of SQL request execution @@ -944,6 +1001,25 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE + - name: sql.update.started.count + exported_name: sql_update_started_count + labeled_name: 'sql.started.count{query_type: update}' + description: Number of SQL UPDATE statements started + y_axis_label: SQL Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE + how_to_use: This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application. + - name: sql.update.started.count.internal + exported_name: sql_update_started_count_internal + labeled_name: 'sql.started.count{query_type: update, query_internal: true}' + description: Number of SQL UPDATE statements started (internal queries) + y_axis_label: SQL Internal Statements + type: COUNTER + unit: COUNT + aggregation: AVG + derivative: NON_NEGATIVE_DERIVATIVE - name: txn.restarts.serializable exported_name: txn_restarts_serializable description: Number of restarts due to a forwarded commit timestamp and isolation=SERIALIZABLE @@ -7717,22 +7793,6 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.delete.started.count - exported_name: sql_delete_started_count - description: Number of SQL DELETE statements started - y_axis_label: SQL Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.delete.started.count.internal - exported_name: sql_delete_started_count_internal - description: Number of SQL DELETE statements started (internal queries) - y_axis_label: SQL Internal Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - name: sql.disk.distsql.current exported_name: sql_disk_distsql_current description: Current sql statement disk usage for distsql @@ -8157,22 +8217,6 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.insert.started.count - exported_name: sql_insert_started_count - description: Number of SQL INSERT statements started - y_axis_label: SQL Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.insert.started.count.internal - exported_name: sql_insert_started_count_internal - description: Number of SQL INSERT statements started (internal queries) - y_axis_label: SQL Internal Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - name: sql.insights.anomaly_detection.evictions exported_name: sql_insights_anomaly_detection_evictions description: Evictions of fingerprint latency summaries due to memory pressure @@ -8837,22 +8881,6 @@ layers: unit: COUNT aggregation: AVG derivative: NONE - - name: sql.select.started.count - exported_name: sql_select_started_count - description: Number of SQL SELECT statements started - y_axis_label: SQL Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.select.started.count.internal - exported_name: sql_select_started_count_internal - description: Number of SQL SELECT statements started (internal queries) - y_axis_label: SQL Internal Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - name: sql.service.latency.consistent exported_name: sql_service_latency_consistent description: Latency of SQL request execution of non-historical queries @@ -9293,22 +9321,6 @@ layers: unit: COUNT aggregation: AVG derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.update.started.count - exported_name: sql_update_started_count - description: Number of SQL UPDATE statements started - y_axis_label: SQL Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - - name: sql.update.started.count.internal - exported_name: sql_update_started_count_internal - description: Number of SQL UPDATE statements started (internal queries) - y_axis_label: SQL Internal Statements - type: COUNTER - unit: COUNT - aggregation: AVG - derivative: NON_NEGATIVE_DERIVATIVE - name: sql.vecindex.pending_splits_merges exported_name: sql_vecindex_pending_splits_merges description: Total number of vector index splits and merges waiting to be processed diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index f5e513aeced0..3d83c79a3c23 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -1016,28 +1016,44 @@ var ( Unit: metric.Unit_COUNT, } MetaSelectStarted = metric.Metadata{ - Name: "sql.select.started.count", - Help: "Number of SQL SELECT statements started", - Measurement: "SQL Statements", - Unit: metric.Unit_COUNT, + Name: "sql.select.started.count", + Help: "Number of SQL SELECT statements started", + Measurement: "SQL Statements", + Unit: metric.Unit_COUNT, + LabeledName: "sql.started.count", + StaticLabels: metric.MakeLabelPairs(metric.LabelQueryType, "select"), + Category: metric.Metadata_SQL, + HowToUse: "This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application.", } MetaUpdateStarted = metric.Metadata{ - Name: "sql.update.started.count", - Help: "Number of SQL UPDATE statements started", - Measurement: "SQL Statements", - Unit: metric.Unit_COUNT, + Name: "sql.update.started.count", + Help: "Number of SQL UPDATE statements started", + Measurement: "SQL Statements", + Unit: metric.Unit_COUNT, + LabeledName: "sql.started.count", + StaticLabels: metric.MakeLabelPairs(metric.LabelQueryType, "update"), + Category: metric.Metadata_SQL, + HowToUse: "This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application.", } MetaInsertStarted = metric.Metadata{ - Name: "sql.insert.started.count", - Help: "Number of SQL INSERT statements started", - Measurement: "SQL Statements", - Unit: metric.Unit_COUNT, + Name: "sql.insert.started.count", + Help: "Number of SQL INSERT statements started", + Measurement: "SQL Statements", + Unit: metric.Unit_COUNT, + LabeledName: "sql.started.count", + StaticLabels: metric.MakeLabelPairs(metric.LabelQueryType, "insert"), + Category: metric.Metadata_SQL, + HowToUse: "This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application.", } MetaDeleteStarted = metric.Metadata{ - Name: "sql.delete.started.count", - Help: "Number of SQL DELETE statements started", - Measurement: "SQL Statements", - Unit: metric.Unit_COUNT, + Name: "sql.delete.started.count", + Help: "Number of SQL DELETE statements started", + Measurement: "SQL Statements", + Unit: metric.Unit_COUNT, + LabeledName: "sql.started.count", + StaticLabels: metric.MakeLabelPairs(metric.LabelQueryType, "delete"), + Category: metric.Metadata_SQL, + HowToUse: "This high-level metric reflects workload volume. Monitor this metric to identify abnormal application behavior or patterns over time. If abnormal patterns emerge, apply the metric's time range to the SQL Activity pages to investigate interesting outliers or patterns. For example, on the Transactions page and the Statements page, sort on the Execution Count column. To find problematic sessions, on the Sessions page, sort on the Transaction Count column. Find the sessions with high transaction counts and trace back to a user or application.", } MetaCRUDStarted = metric.Metadata{ Name: "sql.crud_query.started.count",