Skip to content

Conversation

@dhartunian
Copy link
Collaborator

@dhartunian dhartunian commented Mar 26, 2025

A new metrics endpoint that's Prometheus-compatible, is now available
at /metrics similarly to /_status/vars. This endpoint will emit
statically labeled metrics if the metric metadata defines static
labels and a labeled name.

Here's an example of what this looks like on a demo cluster with
multitenancy using the few metrics that have been migrated in this PR
from SQL:

http GET http://localhost:8080/_status/vars cluster==system | grep sql_insert_count
# HELP sql_insert_count_internal Number of SQL INSERT statements successfully executed (internal queries)
# TYPE sql_insert_count_internal counter
sql_insert_count_internal{node_id="1",tenant="system"} 138
sql_insert_count_internal{node_id="1",tenant="demoapp"} 152
# HELP sql_insert_count Number of SQL INSERT statements successfully executed
# TYPE sql_insert_count counter
sql_insert_count{node_id="1",tenant="system"} 2
sql_insert_count{node_id="1",tenant="demoapp"} 73

~/go/src/github.com/cockroachdb/cockroach remotes/dhartunian/davidh/push-orrrntktwptm* ≡
❯ 
http GET http://localhost:8080/metrics cluster==system | grep sql_insert_count

~/go/src/github.com/cockroachdb/cockroach remotes/dhartunian/davidh/push-orrrntktwptm* ≡
❯ 
http GET http://localhost:8080/metrics cluster==system | grep sql_count
# HELP sql_count Number of SQL UPDATE statements successfully executed (internal queries)
# TYPE sql_count counter
sql_count{node_id="1",tenant="system",query_type="select",query_internal="true"} 172
sql_count{node_id="1",tenant="system",query_type="update"} 0
sql_count{node_id="1",tenant="system",query_type="update",query_internal="true"} 67
sql_count{node_id="1",tenant="system",query_type="select"} 0
sql_count{node_id="1",tenant="system",query_type="delete",query_internal="true"} 29
sql_count{node_id="1",tenant="system",query_type="insert",query_internal="true"} 138
sql_count{node_id="1",tenant="system",query_type="delete"} 0
sql_count{node_id="1",tenant="system",query_type="insert"} 2
sql_count{node_id="1",tenant="demoapp",query_type="update",query_internal="true"} 124
sql_count{node_id="1",tenant="demoapp",query_type="update"} 0
sql_count{node_id="1",tenant="demoapp",query_type="insert"} 269
sql_count{node_id="1",tenant="demoapp",query_type="insert",query_internal="true"} 152
sql_count{node_id="1",tenant="demoapp",query_type="select",query_internal="true"} 243
sql_count{node_id="1",tenant="demoapp",query_type="delete",query_internal="true"} 57
sql_count{node_id="1",tenant="demoapp",query_type="select"} 593
sql_count{node_id="1",tenant="demoapp",query_type="delete"} 0

Resolves: #142570

Release note (ops change): Prometheus metrics are now also available
at the /metrics endpoint in addition to /_status/vars. This new
endpoint will evolve more rapidly as we migrate metrics to use labels
where previously different metric names were defined. Customers can
continue to use /_status/vars where the names will not change.


First commit can be reviewed here: #143511

@dhartunian dhartunian requested review from a team as code owners March 26, 2025 21:32
@dhartunian dhartunian requested review from Abhinav1299, aa-joshi, angles-n-daemons, arjunmahishi and xinhaoz and removed request for a team March 26, 2025 21:32
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@dhartunian dhartunian changed the title metric: add static labels to metric metadata metric: add /metrics endpoint with static labels Mar 26, 2025
@dhartunian dhartunian force-pushed the davidh/push-mzpxkrsmywnu branch 2 times, most recently from a895084 to cc9d0a8 Compare March 27, 2025 16:58
metric.WithIncludeAggregateMetrics(includeAggregateMetrics),
metric.WithUseStaticLabels(useStaticLabels),
}
mr.mu.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this makes any difference, but I like when objects are locked as the first stage of a function, even if the critical section is further along. It's almost as if it's part of the function signature which I find useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dhartunian dhartunian force-pushed the davidh/push-mzpxkrsmywnu branch from cc9d0a8 to 44da15e Compare April 7, 2025 22:38
@dhartunian dhartunian requested a review from a team as a code owner April 7, 2025 22:38
A new metrics endpoint that's Prometheus-compatible, is now available
at `/metrics` similarly to `/_status/vars`. This endpoint will emit
statically labeled metrics if the metric metadata defines static
labels and a labeled name.

Here's an example of what this looks like on a demo cluster with
multitenancy using the few metrics that have been migrated in this PR
from SQL:

```
http GET http://localhost:8080/_status/vars cluster==system | grep sql_insert_count
# HELP sql_insert_count_internal Number of SQL INSERT statements successfully executed (internal queries)
# TYPE sql_insert_count_internal counter
sql_insert_count_internal{node_id="1",tenant="system"} 138
sql_insert_count_internal{node_id="1",tenant="demoapp"} 152
# HELP sql_insert_count Number of SQL INSERT statements successfully executed
# TYPE sql_insert_count counter
sql_insert_count{node_id="1",tenant="system"} 2
sql_insert_count{node_id="1",tenant="demoapp"} 73

~/go/src/github.com/cockroachdb/cockroach remotes/dhartunian/davidh/push-orrrntktwptm* ≡
❯ 
http GET http://localhost:8080/metrics cluster==system | grep sql_insert_count

~/go/src/github.com/cockroachdb/cockroach remotes/dhartunian/davidh/push-orrrntktwptm* ≡
❯ 
http GET http://localhost:8080/metrics cluster==system | grep sql_count
# HELP sql_count Number of SQL UPDATE statements successfully executed (internal queries)
# TYPE sql_count counter
sql_count{node_id="1",tenant="system",query_type="select",query_internal="true"} 172
sql_count{node_id="1",tenant="system",query_type="update"} 0
sql_count{node_id="1",tenant="system",query_type="update",query_internal="true"} 67
sql_count{node_id="1",tenant="system",query_type="select"} 0
sql_count{node_id="1",tenant="system",query_type="delete",query_internal="true"} 29
sql_count{node_id="1",tenant="system",query_type="insert",query_internal="true"} 138
sql_count{node_id="1",tenant="system",query_type="delete"} 0
sql_count{node_id="1",tenant="system",query_type="insert"} 2
sql_count{node_id="1",tenant="demoapp",query_type="update",query_internal="true"} 124
sql_count{node_id="1",tenant="demoapp",query_type="update"} 0
sql_count{node_id="1",tenant="demoapp",query_type="insert"} 269
sql_count{node_id="1",tenant="demoapp",query_type="insert",query_internal="true"} 152
sql_count{node_id="1",tenant="demoapp",query_type="select",query_internal="true"} 243
sql_count{node_id="1",tenant="demoapp",query_type="delete",query_internal="true"} 57
sql_count{node_id="1",tenant="demoapp",query_type="select"} 593
sql_count{node_id="1",tenant="demoapp",query_type="delete"} 0
```

Resolves: cockroachdb#142570

Release note (ops change): Prometheus metrics are now also available
at the `/metrics` endpoint in addition to `/_status/vars`. This new
endpoint will evolve more rapidly as we migrate metrics to use labels
where previously different metric names were defined. Customers can
continue to use `/_status/vars` where the names will not change.
@dhartunian dhartunian force-pushed the davidh/push-mzpxkrsmywnu branch from 44da15e to b87e008 Compare April 9, 2025 15:53
@dhartunian
Copy link
Collaborator Author

TFTR!

bors r=angles-n-daemons

@craig
Copy link
Contributor

craig bot commented Apr 9, 2025

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Apr 9, 2025

@craig craig bot merged commit 75f3693 into cockroachdb:master Apr 9, 2025
24 checks passed
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Aug 15, 2025
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 cockroachdb#143536

Release note (ops change): TBD

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Aug 18, 2025
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 cockroachdb#143536

Release note (ops change): TBD

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Aug 18, 2025
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 cockroachdb#143536

Release note (ops change): TBD

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Aug 28, 2025
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 cockroachdb#143536

Release note (ops change): TBD

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Sep 24, 2025
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 cockroachdb#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.

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Sep 29, 2025
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 cockroachdb#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.

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
blathers-crl bot pushed a commit that referenced this pull request Sep 29, 2025
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.

<what was there before: Previously, ...>
<why it needed to change: This was inadequate because ...>
<what you did about it: To address this, this patch ...>
ZhouXing19 added a commit to ZhouXing19/cockroach that referenced this pull request Sep 29, 2025
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 cockroachdb#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

metric: add static labeling capability to metric metadata

3 participants