-
Notifications
You must be signed in to change notification settings - Fork 423
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
Don't pass metrics around #423
Don't pass metrics around #423
Conversation
* Remove need to pass metrics object around, but: * Still allow a Registerer to be passed avoids duplicate metrics registration errors during unit testing.
/retest |
@@ -14,6 +14,16 @@ const ( | |||
Success = "success" | |||
) | |||
|
|||
var authenticatorMetrics Metrics | |||
|
|||
func InitMetrics(registerer prometheus.Registerer) { |
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.
could we try using an init function to avoid calling InitMetrics
at all? Test and prod code will benefit from not having to call InitMetrics. Let me know how that looks.
Also if we did that, we could also try getting rid of the metrics
struct and make ConfigMapWatchFailures
and Latency
top level vars. It's optional, but would like to know your thoughts
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.
The reason I call InitMetrics() explicitly is because we check metric counts in a many of our unit tests using this function, so we need a way to clear the metrics after each test run. Otherwise, we will need to refactor the tests to call prometheus.Unregister()
in every test (we can use a TestMain here with setup and teardown functions to avoid explicit calls for each test). Do you prefer that approach?
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 stumbled across another approach of sampling the metric before and after the test is run and verifying the ending value is what is expected.
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.
so we need a way to clear the metrics after each test run
How do we clean up today?
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.
We don't need to because we create a new metrics namespace for each test setup.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jyotimahapatra, nckturner The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
@jyotimahapatra: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/lgtm |
Registerer
to be passed in avoids duplicate metricsregistration errors during unit testing.
Testing by hitting metrics endpoint: