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

Don't pass metrics around #423

Merged

Conversation

nckturner
Copy link
Contributor

  • Remove need to pass metrics object around, but:
  • Still allow a Registerer to be passed in avoids duplicate metrics
    registration errors during unit testing.

Testing by hitting metrics endpoint:

$ curl --cacert _output/dev/authenticator/state/cert.pem https://localhost:21362/metrics | grep aws_iam_authenticator
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                                                                                              
                                 Dload  Upload   Total   Spent    Left  Speed                                                                                                                
100  7784    0  7784    0     # HELP aws_iam_authenticator_authenticate_latency_seconds Authenticate call latency                                                                            
0  # TYPE aws_iam_authenticator_authenticate_latency_seconds histogram                                                                                                                       
19aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.005"} 2                                                                                                   
00aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.01"} 2                                                                                                    
kaws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.025"} 3                                                                                                    
  aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.05"} 4                                                                                                    
  aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.1"} 4                                                                                                     
  aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.25"} 4                                                                                                    
0aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="0.5"} 4                                                                                                      
 -aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="1"} 4                                                                                                       
-:aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="2.5"} 4                                                                                                     
-aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="5"} 4                                                                                                        
-aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="10"} 4                                                                                                       
:aws_iam_authenticator_authenticate_latency_seconds_bucket{result="success",le="+Inf"} 4                                                                                                     
--aws_iam_authenticator_authenticate_latency_seconds_sum{result="success"} 0.061571109                                                                                                       
 -aws_iam_authenticator_authenticate_latency_seconds_count{result="success"} 4                                                                                                               
-:# HELP aws_iam_authenticator_configmap_watch_failures EKS Configmap watch failures                                                                                                         
--# TYPE aws_iam_authenticator_configmap_watch_failures counter                                                                                                                              
:-aws_iam_authenticator_configmap_watch_failures 0                                                                                                                                           
- --:--:-- 1900k      

* Remove need to pass metrics object around, but:
* Still allow a Registerer to be passed avoids duplicate metrics
  registration errors during unit testing.
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 18, 2022
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 18, 2022
@nckturner
Copy link
Contributor Author

/retest

@@ -14,6 +14,16 @@ const (
Success = "success"
)

var authenticatorMetrics Metrics

func InitMetrics(registerer prometheus.Registerer) {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jyotimahapatra
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@jyotimahapatra: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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.

@wongma7
Copy link
Contributor

wongma7 commented Feb 10, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 10, 2022
@k8s-ci-robot k8s-ci-robot merged commit 057fa8f into kubernetes-sigs:master Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants