Skip to content
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

Merged
merged 10 commits into from
Jun 29, 2023
Merged

Add the appmetrics package #182

merged 10 commits into from
Jun 29, 2023

Conversation

bluekeyes
Copy link
Member

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.

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.
bluekeyes and others added 2 commits June 25, 2023 16:02
We need to get the field value each time because the initial value is
always going to be nil.
@bluekeyes bluekeyes marked this pull request as ready for review June 26, 2023 23:36
@bluekeyes bluekeyes requested a review from a team June 26, 2023 23:43
m.r = r

// Add the bare metric immediately so emitters can find it in the registry
r.GetOrRegister(m.name, m.newMetric)
Copy link
Member Author

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.

appmetrics/tags.go Outdated Show resolved Hide resolved
Copy link

@nvelat nvelat left a 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

appmetrics/appmetrics.go Show resolved Hide resolved
appmetrics/appmetrics.go Outdated Show resolved Hide resolved
@bluekeyes bluekeyes merged commit 63236d7 into develop Jun 29, 2023
3 checks passed
@bluekeyes bluekeyes deleted the bkeyes/appmetrics branch June 29, 2023 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants