Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces scopes to Statter: a globally-identified sub-statter that can track metrics created through it and later delete them as a batch, enabling unique metric sets per scope id (e.g., build revision gauges) and simpler cleanup when an entity goes away.
Changes:
- Add
Statter.Scope(id, tags...)/Statter.HasScope(id)and a newScopetype with metric tracking + bulk deletion. - Add registry support for storing/replacing scopes by id, and introduce
reportMuto coordinate reporting with metric deletion. - Refactor metric constructors to expose “created” status so scopes can track only newly-created metric instances; add tests, examples, docs, and benchmarks.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| statter.go | Adds public Scope/HasScope API; refactors metric getters to report whether a metric was created; adjusts metric deletion semantics. |
| registry.go | Adds scope storage/rotation logic; adds reportMu to serialize reporting against deletions. |
| scope.go | Introduces Scope implementation, metric tracking, and bulk deletion behavior. |
| scope_test.go | Adds integration-style tests covering scope resolve/rotate/delete/idempotency/concurrency behaviors. |
| statter_internal_test.go | Adds internal regression test ensuring scopes don’t pollute the statter cache. |
| README.md | Documents the new Scope feature and deletion semantics (including reporter removal support). |
| example_test.go | Adds runnable examples for Statter.Scope and Scope.Delete. |
| doc.go | Updates package docs to describe scopes and backend-removal behavior. |
| bench_test.go | Adds benchmarks for scope resolve, scope gauge usage, and rotation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+59
to
+69
| func (sc *Scope) matches(parent *Statter, tags []Tag) bool { | ||
| if sc.parent != parent || len(sc.tags) != len(tags) { | ||
| return false | ||
| } | ||
| for i, tag := range tags { | ||
| if sc.tags[i] != tag { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } |
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.
Goal of this PR
This adds scopes to the Statter to allow unique metric sets and simple bulk removal of metrics when they relate to a specific entitiy.
How did I test it?