clustermetrics: add support for stopwatch type#164371
Open
kyle-a-wong wants to merge 1 commit intocockroachdb:masterfrom
Open
clustermetrics: add support for stopwatch type#164371kyle-a-wong wants to merge 1 commit intocockroachdb:masterfrom
kyle-a-wong wants to merge 1 commit intocockroachdb:masterfrom
Conversation
Contributor
|
Merging to
|
Member
jasonlmfong
approved these changes
Feb 25, 2026
Comment on lines
148
to
159
| swTimestamp2 := time.Now().UnixNano() | ||
| r.Exec(t, fmt.Sprintf(`INSERT INTO system.cluster_metrics | ||
| (id, name, labels, type, value, node_id) | ||
| VALUES (601, 'test.stopwatch_labeled', '{"store": "2"}', 'STOPWATCH', %d, 1)`, | ||
| swTimestamp2)) | ||
|
|
||
| testutils.SucceedsSoon(t, func() error { | ||
| return checkStopwatchVecElapsed( | ||
| reg, "test.stopwatch_labeled", | ||
| map[string]string{"store": "2"}, 0, | ||
| ) | ||
| }) |
Member
There was a problem hiding this comment.
maybe also put this in the past for like 5 seconds and check that, since checking elapsed 0 seems too trivial
Comment on lines
+537
to
+558
| // requireStopwatchElapsed asserts that a scalar *metric.Gauge (backed by a | ||
| // functional gauge) reports an elapsed time of at least minElapsed. | ||
| func requireStopwatchElapsed( | ||
| t *testing.T, reg metric.RegistryReader, name string, minElapsed time.Duration, | ||
| ) { | ||
| t.Helper() | ||
| var g *metric.Gauge | ||
| reg.Each(func(n string, v interface{}) { | ||
| if n == name { | ||
| if gauge, ok := v.(*metric.Gauge); ok { | ||
| g = gauge | ||
| } | ||
| } | ||
| }) | ||
| require.NotNilf(t, g, "stopwatch gauge %q not found in registry", name) | ||
| elapsedNanos := g.Value() | ||
| require.Greater(t, elapsedNanos, int64(0), | ||
| "stopwatch %q should report positive elapsed time", name) | ||
| require.GreaterOrEqual(t, elapsedNanos, int64(minElapsed), | ||
| "stopwatch %q elapsed %s should be >= %s", | ||
| name, time.Duration(elapsedNanos), minElapsed) | ||
| } |
Member
There was a problem hiding this comment.
i see, this threw me off a bit but then i see that the call to g.Value() hits the code to do the subtraction
faaa5f2 to
743860a
Compare
kyle-a-wong
commented
Feb 26, 2026
Contributor
Author
kyle-a-wong
left a comment
There was a problem hiding this comment.
Rebased on master which added new metric.Gauge types to use and removed the stopwatch.go files from the previous commit
Comment on lines
148
to
159
| swTimestamp2 := time.Now().UnixNano() | ||
| r.Exec(t, fmt.Sprintf(`INSERT INTO system.cluster_metrics | ||
| (id, name, labels, type, value, node_id) | ||
| VALUES (601, 'test.stopwatch_labeled', '{"store": "2"}', 'STOPWATCH', %d, 1)`, | ||
| swTimestamp2)) | ||
|
|
||
| testutils.SucceedsSoon(t, func() error { | ||
| return checkStopwatchVecElapsed( | ||
| reg, "test.stopwatch_labeled", | ||
| map[string]string{"store": "2"}, 0, | ||
| ) | ||
| }) |
Adds support for stopwatch type metrics on the cluster metric read path. Stopwatch metrics are gauges that report the duration of time (in unix nanos) that has passed since it was last updated. Epic: https://cockroachlabs.atlassian.net/browse/CRDB-58342 Resolves: https://cockroachlabs.atlassian.net/browse/CRDB-60768 Release note: None
743860a to
1af2348
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for stopwatch type metrics on the cluster metric read path. Stopwatch metrics are gauges that report the duration of time (in unix nanos) that has passed since it was last updated.
Epic: https://cockroachlabs.atlassian.net/browse/CRDB-58342
Resolves: https://cockroachlabs.atlassian.net/browse/CRDB-60768
Release note: None