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

Test for etcd metrics #19242

Merged
merged 1 commit into from
Jan 23, 2025
Merged

Test for etcd metrics #19242

merged 1 commit into from
Jan 23, 2025

Conversation

dims
Copy link
Contributor

@dims dims commented Jan 21, 2025

Test ONLY change to ensure #19195 does not cause a regression.

NOTE: the following 3 metrics are NOT listed here as there is no way for us to thread in "extensive" metrics in current tests suite. #19195 has the changes needed for that. So when we update that PR, we will add these metrics as the PR has the changes for updating the tests suite.

  • grpc_server_handling_seconds_bucket
  • grpc_server_handling_seconds_count
  • grpc_server_handling_seconds_sum

@k8s-ci-robot
Copy link

Hi @dims. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.81%. Comparing base (7c56ef2) to head (19d405c).
Report is 23 commits behind head on main.

Additional details and impacted files

see 25 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #19242      +/-   ##
==========================================
+ Coverage   68.77%   68.81%   +0.04%     
==========================================
  Files         420      420              
  Lines       35649    35675      +26     
==========================================
+ Hits        24518    24551      +33     
+ Misses       9705     9699       -6     
+ Partials     1426     1425       -1     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c56ef2...19d405c. Read the comment docs.

@serathius
Copy link
Member

Can we first merge the test?

@ahrtr
Copy link
Member

ahrtr commented Jan 23, 2025

The test being added here will fail until #19195 lands

The test should be an independent change. We should finish & merge the test firstly. Afterwards, you need to rebase #19195.

I think you just need to start an etcd instance (and probably write a couple of key/values), then get all the metrics using /metrics endpoint. Please refer to https://github.com/ahrtr/etcd-diagnosis/blob/main/plugins/metrics/plugin.go

@dims
Copy link
Contributor Author

dims commented Jan 23, 2025

@serathius @ahrtr updated this PR, this can go first. 3 metrics are not captured currently in this test (see notes in PR text). When i update the other PR will get added.

Comment on lines +191 to +214
srv := &http.Server{Handler: promhttp.Handler()}
srv.SetKeepAlivesEnabled(false)

ln, err := transport.NewUnixListener(addr)
if err != nil {
t.Errorf("Error: %v occurred while listening on addr: %v", err, addr)
}

donec := make(chan struct{})
defer func() {
ln.Close()
<-donec
}()

// listen for all Prometheus metrics
go func() {
defer close(donec)

serr := srv.Serve(ln)
if serr != nil && !transport.IsClosedConnError(serr) {
t.Errorf("Err serving http requests: %v", serr)
}
}()

url := "unix://" + addr + "/metrics"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking whether e2e test here would better, more accurate and would not require this custom code. But don't want to block on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏🏾

}
}

func getMetricsList(t *testing.T, url string) []string {
Copy link
Member

@serathius serathius Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI "github.com/prometheus/common/expfmt" is package has a parser for metrics. Example usage https://github.com/kubernetes-sigs/metrics-server/blob/0dcee07ea614e8354ec740dfc3f528a572cacec4/test/e2e_test.go#L315-L329

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serathius I will update the implementation of this test as suggested in the other PR when i rebase!

@ahrtr
Copy link
Member

ahrtr commented Jan 23, 2025

This PR follows the existing integration test cases.

I am not sure how other maintainers think, but personally I don't think the existing integration tests on metrics (see below) are appropriate,

For integration test, I think it would be better to simulate the embedded use case (start etcd by calling StartEtcd); but the current integration test creates the EtcdServer, provision all listeners, etc. directly, it does too much hack on etcd itself. It's hard to maintain, also hard to ensure it's testing exactly the same implementation as production environment. Even in the test, it also does too much hack. (i.e. register/listen prometheus metrics, etc.)

func StartEtcd(inCfg *Config) (e *Etcd, err error) {

Ideally, we should test etcd as a black box, so e2e test is much better. If we test it in integrate test, we should start etcd via StartEtcd.

Of course, it's not this PR's problem. So I am OK to let this PR in and we can discuss it separately and probably add an e2e test separately.

@dims
Copy link
Contributor Author

dims commented Jan 23, 2025

So I am OK to let this PR in and we can discuss it separately and probably add an e2e test separately.

thanks @ahrtr !

@dims
Copy link
Contributor Author

dims commented Jan 23, 2025

/ok-to-test

@k8s-ci-robot
Copy link

@dims: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-test

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-sigs/prow repository.

@dims
Copy link
Contributor Author

dims commented Jan 23, 2025

/ok-to-test

Signed-off-by: Davanum Srinivas <[email protected]>
@dims dims force-pushed the test-for-etcd-metrics branch from 9a2cb80 to 19d405c Compare January 23, 2025 15:30
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, dims, serathius

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

@ahrtr ahrtr merged commit c8646cd into etcd-io:main Jan 23, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants