Skip to content

fix: Use prometheus summary for high watermark metric - #21906

Merged
grobinson-grafana merged 2 commits into
mainfrom
grobison/use-summary-for-high-watermark-metric
May 14, 2026
Merged

fix: Use prometheus summary for high watermark metric#21906
grobinson-grafana merged 2 commits into
mainfrom
grobison/use-summary-for-high-watermark-metric

Conversation

@grobinson-grafana

@grobinson-grafana grobinson-grafana commented May 14, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Having discussed with various Grafanaistas, this seems preferred to a high watermark gauge.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

Note

Medium Risk
Changes the pattern_ingester_tee_buffered_bytes metric type/semantics and updates buffering accounting paths, which can affect dashboards/alerts and adds per-update Summary observations on hot paths.

Overview
Switches pattern_ingester_tee_buffered_bytes from a custom max-sample collector to a Prometheus Summary, recording the buffered-bytes value via Observe() on each reservation/release and removing the prior start/stop lifecycle registration.

Refactors tryReserveBufferedBytes into reserveBufferedBytes so buffered bytes are always tracked while only enforcing MaxBufferedBytes when it’s positive, and updates TestPatternTee_MaxBufferedBytes to reflect the new “limit disabled” behavior.

Reviewed by Cursor Bugbot for commit 26b85f5. Bugbot is set up for automated code reviews on this repo. Configure here.

@grobinson-grafana
grobinson-grafana requested a review from a team as a code owner May 14, 2026 10:13
@grobinson-grafana grobinson-grafana changed the title fix: use prometheus summary for high watermark metric May 14, 2026
cursor[bot]

This comment was marked as outdated.

@grobinson-grafana
grobinson-grafana force-pushed the grobison/use-summary-for-high-watermark-metric branch from 5703baa to 26b85f5 Compare May 14, 2026 10:18
bufferedBytes: promauto.With(reg).NewSummary(prometheus.SummaryOpts{
Name: "pattern_ingester_tee_buffered_bytes",
Help: "The current number of bytes buffered in the tee.",
Objectives: map[float64]float64{1.0: 0.1},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We only care about the maximum value, hence 1.0.

@joe-elliott joe-elliott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@pull-request-size pull-request-size Bot added size/L and removed size/M labels May 14, 2026
Comment thread pkg/pattern/tee_service.go Outdated
// It is safe for concurrent use.
func (ts *TeeService) releaseBufferedBytes(size int) {
newVal := ts.bufferedBytes.Add(-int64(size))
ts.metrics.bufferedBytes.Observe(float64(newVal))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't believe we need to update the summary in releaseBufferedBytes, that will be taken care of the next time someone calls reserveBufferedBytes.

@joe-elliott joe-elliott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice cleanup

// the same value.
//
// It is safe for concurrent use.
func (ts *TeeService) reserveBufferedBytes(size int) bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i don't think we should make the change here, but would this make sense to be a semaphore?

https://pkg.go.dev/golang.org/x/sync/semaphore

@grobinson-grafana grobinson-grafana May 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are a few differences in that x/sync/semaphore uses mutexes instead of atomics, and I'm not sure we need a waiters list with first-come first-serve semantics. I'd be curious to experiment with it if it has benefits.

@grobinson-grafana
grobinson-grafana merged commit 5deb669 into main May 14, 2026
90 checks passed
@grobinson-grafana
grobinson-grafana deleted the grobison/use-summary-for-high-watermark-metric branch May 14, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants