-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add new Emitter API to start and stop metrics #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
IDK where it was there to begin with. The [go module spec][1] says: > The toolchain directive only has an effect when the module is the main > module and the default toolchain’s version is less than the suggested > toolchain’s version. So removing this should not have any impact. [1]: https://go.dev/ref/mod#go-mod-file-toolchain
This brings us inline with the minimal go version required by dd-trace-go and also allows using `cmp.Or` which is introduced by a later commit in this PR.
logger *slog.Logger | ||
baseTags []string | ||
unknownMetricLogOnce *sync.Once | ||
unsupportedKindLogOnce *sync.Once | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: follow-up PR - refactor this into the Emitter type
1e843fb
to
7914529
Compare
There was a problem hiding this comment.
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 a new Emitter API to start and stop the reporting of runtime metrics to a statsd client. Key changes include:
- Refactoring runtime metrics reporting by replacing the global Start function with an Emitter type that provides explicit start/stop semantics.
- Updating tests to exercise the new Emitter API and its idempotent Stop behavior.
- Simplifying base tags handling and updating go.mod for a newer Go version.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
pkg/runtimemetrics/tags_test.go | Updated tests to directly call getBaseTags inline with tag assertions. |
pkg/runtimemetrics/tags.go | Simplified getBaseTags by removing unnecessary mutex locking and global state. |
pkg/runtimetrics/runtime_metrics_test.go | Revised unit tests to leverage the new Emitter API and check for idempotence. |
pkg/runtimemetrics/runtime_metrics.go | Introduced Options and Emitter, refactored runtime metric store usage, and improved logging. |
go.mod | Updated the Go version and removed the explicit toolchain specification. |
Comments suppressed due to low confidence (1)
pkg/runtimemetrics/runtime_metrics.go:44
- [nitpick] Consider adding a comment to clarify the behavior and intent of using cmp.Or for selecting default values, to improve code clarity for future maintainers.
logger: cmp.Or(opts.Logger, slog.Default()),
tick := time.Tick(e.period) | ||
for { | ||
select { | ||
case <-e.stop: | ||
return | ||
case <-tick: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing time.Tick with time.NewTicker to allow proper cleanup of the ticker when the emitter is stopped, thereby avoiding potential resource leaks.
tick := time.Tick(e.period) | |
for { | |
select { | |
case <-e.stop: | |
return | |
case <-tick: | |
ticker := time.NewTicker(e.period) | |
defer ticker.Stop() | |
for { | |
select { | |
case <-e.stop: | |
return | |
case <-ticker.C: |
Copilot uses AI. Check for mistakes.
No description provided.