Skip to content

pkg/sql: SQL metrics with app_name and db_name labels #143203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arjunmahishi
Copy link
Contributor

@arjunmahishi arjunmahishi commented Mar 20, 2025

NOTE: The first commit in this PR will be merged as part of #142822. This PR has to be merged after the changes in #142822 are merged.


This commit introduces a new SQLCounter type, a wrapper around the
AggCounter from the aggmetric package. This metric type helps manage
labels added to SQL metrics based on cluster settings.

Two new cluster settings added:

  • sql.application_name_metrics.enabled - enables app_name label
  • sql.db_name_metrics.enabled - enables db_name label

When enabled, these settings add app_name and db_name labels to SQL
metrics of type SQLCounter, allowing tracking of metrics by application
and database.

This commit also implements the SetOnChange mechanism for these cluster
settings, ensuring metrics are automatically redeclared with relevant
labels when settings change.

Epic: CRDB-43153
Jira: CRDB-48253
Release note: None

Currently, Agg metrics internally use btree to store the label set of
metrics. But we are not actually using any of the btree specific features
like range queries or ordered iteration. We are only adding, deleting, looking
up exact keys and iterating over all the keys. A hash map based data structure
is a better fit for this use case. This commit replaces the btree with
an UnorderedCache.

This UnorderedCache is configured with an LRU based eviction policy and sets a
max size limit on the number of items stored in the cache. This will also help
us manage the cardinality of the metrics.

Release note: none
@cockroach-teamcity
Copy link
Member

This change is Reviewable

This commit introduces a new SQLCounter type, a wrapper around the
AggCounter from the aggmetric package. This metric type helps manage
labels added to SQL metrics based on cluster settings.

Two new cluster settings added:
- sql.application_name_metrics.enabled - enables app_name label
- sql.db_name_metrics.enabled - enables db_name label

When enabled, these settings add 'app_name' and 'db_name' labels to SQL
metrics of type SQLCounter, allowing tracking of metrics by application
and database.

This commit also implements the SetOnChange mechanism for these cluster
settings, ensuring metrics are automatically redeclared with relevant
labels when settings change.

Epic: CRDB-43153
Jira: CRDB-48253
Release note: None
@arjunmahishi arjunmahishi force-pushed the aggmetrics-lru_db-app-label branch from 8902542 to 3f0d854 Compare March 20, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants