Skip to content

feat: add scopes - #209

Open
nrwiersma wants to merge 1 commit into
mainfrom
scopes
Open

feat: add scopes#209
nrwiersma wants to merge 1 commit into
mainfrom
scopes

Conversation

@nrwiersma

Copy link
Copy Markdown
Member

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?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 new Scope type with metric tracking + bulk deletion.
  • Add registry support for storing/replacing scopes by id, and introduce reportMu to 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 thread scope.go
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants