Skip to content

metrics: refactor functional gauge to accept gauge value in callback#163499

Open
kyle-a-wong wants to merge 1 commit intocockroachdb:masterfrom
kyle-a-wong:update_functional_gauge
Open

metrics: refactor functional gauge to accept gauge value in callback#163499
kyle-a-wong wants to merge 1 commit intocockroachdb:masterfrom
kyle-a-wong:update_functional_gauge

Conversation

@kyle-a-wong
Copy link
Contributor

Refactors functional gauges to take the gauges
current value as an argument. Now, functional
gauges can be used with the Update, Inc, and
Dec methods if desired

Epic: None
Release note: None

@kyle-a-wong kyle-a-wong requested review from a team as code owners February 13, 2026 17:25
@kyle-a-wong kyle-a-wong requested review from angles-n-daemons and arjunmahishi and removed request for a team February 13, 2026 17:25
@trunk-io
Copy link
Contributor

trunk-io bot commented Feb 13, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

@kyle-a-wong kyle-a-wong requested review from aerfrei and removed request for a team February 13, 2026 17:25
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

@dhartunian made 2 comments.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aerfrei, @angles-n-daemons, @arjunmahishi, and @kyle-a-wong).


-- commits line 7 at r1:
Can you link to the epic and other work to explain the motivation for this?

There's a bit of confusion that this introduces about whether Inc/Dec/Update do anything in a Functional Gauge. I wonder if we should have two different kinds of functional gauges. Maybe FunctionalGauge and DerivedGauge? The new API is now more subtle and error-prone.


pkg/util/metric/aggmetric/gauge.go line 47 at r1 (raw file):

) *AggGauge {
	g := &AggGauge{}
	gaugeFn := func(_ int64) int64 {

Hmm I guess the existing API was confusing too...So an aggregate functional gauge is derived from values directly, but it's a function of all the children, not the internal value of the aggregate. This is confusing. Maybe we should rethink the API/implementation or at the very least carefully document the behavior. Calling Inc/Dec/Update on a functional AggGauge will not do anything.

@kyle-a-wong kyle-a-wong force-pushed the update_functional_gauge branch from d6e99ab to 2aded15 Compare February 14, 2026 03:52
@github-actions
Copy link

Potential Bug(s) Detected

The three-stage Claude Code analysis has identified potential bug(s) in this PR that may warrant investigation.

Next Steps:
Please review the detailed findings in the workflow run.

Note: When viewing the workflow output, scroll to the bottom to find the Final Analysis Summary.

After you review the findings, please tag the issue as follows:

  • If the detected issue is real or was helpful in any way, please tag the issue with O-AI-Review-Real-Issue-Found
  • If the detected issue was not helpful in any way, please tag the issue with O-AI-Review-Not-Helpful

@github-actions github-actions bot added the o-AI-Review-Potential-Issue-Detected AI reviewer found potential issue. Never assign manually—auto-applied by GH action only. label Feb 14, 2026
@kyle-a-wong kyle-a-wong force-pushed the update_functional_gauge branch 4 times, most recently from 31266b5 to cb88536 Compare February 14, 2026 20:40
Defines a new DerivedGauge that is a special implementation
of Gauge that computes a derived gauge value, based on the
call back used to make the DerivedGauge and the last updated
value of the gauge. This replaces the old "Functional Gauge"
implentation.

Renames the agg gauge functional gauge to "derived gauge" to
align with the new derived gauge type.

Defines a new DerivedGaugeVec type that is the Prometheus
vector equivalent of DerivedGauge.

Defines a new FunctionalGauge type, that calls the provided
callback to compute the gauges value.

By defining these as concrete types, the API of each type
becomes more clear and sensible. For example, the previous
"functional gauge" was just normal gauge, This gauge has
Update, Inc, Dec methods, but they didn't do anything to
the gauge's reported value.

Epic: None
Release note: None
@kyle-a-wong kyle-a-wong force-pushed the update_functional_gauge branch from cb88536 to 443394a Compare February 14, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

o-AI-Review-Potential-Issue-Detected AI reviewer found potential issue. Never assign manually—auto-applied by GH action only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants