-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 linter helpers to testutil #743
Conversation
Also, change all the `dto.MetricFamily` arguments to pointers to be more consistent with what we do in client_golang in general. Signed-off-by: beorn7 <beorn@grafana.com>
Signed-off-by: beorn7 <beorn@grafana.com>
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.
Awesome! 🤗
LGTM, some tiny suggestions only.
prometheus/testutil/lint.go
Outdated
) | ||
|
||
// CollectAndLint registers the provided Collector with a newly created | ||
// pedantic Registry. It then does the same as GatherAndLint, gathering the |
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.
// pedantic Registry. It then does the same as GatherAndLint, gathering the | |
// pedantic Registry. It then does the same as GatherAndLint, gathers the |
Kind of scared to suggest this to you, but .... am I right here? 😄
Previous version was reading oddly
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.
I could argue why my version is correct. But I agree it's convoluted. I'll reword to avoid the complication.
@@ -29,7 +29,8 @@ import ( | |||
// A Linter is a Prometheus metrics linter. It identifies issues with metric | |||
// names, types, and metadata, and reports them to the caller. | |||
type Linter struct { | |||
r io.Reader | |||
r io.Reader |
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.
I would comment that this is oneof
between two. I was bit confused and I can imagine package devs might be as well..
Not relevant to package users
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.
It would actually work with both having values, just that you don't have a constructor doing so (but we might have in the future). I'll add a comment explaining that.
if err != nil { | ||
return nil, fmt.Errorf("gathering metrics failed: %s", err) | ||
} | ||
if metricNames != nil { |
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.
I think I would prefer len(metricNames) > 0
, less surprising.
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.
My thinking was that the linter will never recognize fewer problems in future versions, but it might recognize more. I changed the comment to clarify that.
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.
Thx!
Signed-off-by: beorn7 <beorn@grafana.com>
Awesome! |
@beorn7 I can help clean up
I was wondering if we can deprecate promlint in |
@RainbowMango Yes, I'll cut v1.6.0 ASAP (hopefully today). Once it is released, it would be very much appreciated if you could help switching over the prometheus/prometheus code. |
OK. Will do. |
This for one adds direct
MetricFamily
support topromlint
.It then adds helpers
CollectAndLint
andGatherAndLint
akin toCollectAndCompare
andGatherAndCompare
to thetestutil
package, which simplifies to integrate linting into testing of instrumented code.@RainbowMango