-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add the appmetrics package #182
Conversation
This package contains utilities that make it easier to construct and register metrics structs because you only have to specify the metric name and type in one place. It should hopefully help standardize how we configure metrics in various applications. One disadvantage is that it doesn't handle tagged metrics right now, since the metric names change based on the tag values. I'll have to think about how to implement this.
Define a functional guage by using the specific structs instead the plain gauge interface with a struct tag. Also, require a specific function field or method named after the metric field instead of allowing customization with tags.
I realized that the Tagged[M] interface could work after all because we can get the type parameter from the return type of the Tag() method. We have to implement our own interface check since different instantiations of the interface are different types, but this isn't too bad for a single method.
We need to get the field value each time because the initial value is always going to be nil.
m.r = r | ||
|
||
// Add the bare metric immediately so emitters can find it in the registry | ||
r.GetOrRegister(m.name, m.newMetric) |
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.
Not sure if this is a good idea or not, but I've definitely tricked myself not being able to find an expected metric because it hadn't reported any values yet.
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.
This is super cool, love the tagging with metric name at struct declaration. It definitely will make using metrics downstream easier
This package contains utilities that make it easier to construct and register metrics structs because you only have to specify the metric name and type in one place. It should hopefully help standardize how we configure metrics in various applications.
There's a bit of magic involved, so it's probably best to read the included docs and look at the examples to understand how this works. I'll also put together an example in a real internal application.
There were a few iterations on tagged and functional metrics, which you can see in the commit history, but I'm relatively happy with the final version shown here.