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

Webhook conversion metrics [request/error counts and latency metrics] #118292

Merged
merged 4 commits into from
Jun 7, 2023

Conversation

cchapla
Copy link
Contributor

@cchapla cchapla commented May 26, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Adds webhook conversion metrics for requests count for success/failures and latency.

Which issue(s) this PR fixes:

Ref #117167

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Kube-apiserver adds two new alpha metrics `conversion_webhook_request_total` and `conversion_webhook_duration_seconds` that allow users to monitor requests to CRD conversion webhooks, split by result, and failure_type (In case of failure).

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 26, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 26, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: cchapla / name: CC (8df1a5e)

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 26, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 26, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @cchapla!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @cchapla. Thanks for your PR.

I'm waiting for a kubernetes 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 26, 2023
@cici37
Copy link
Contributor

cici37 commented May 30, 2023

/triage accepted
/sig instrumentation
/cc @logicalhan

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 30, 2023
@shyamjvs
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 30, 2023
@shyamjvs
Copy link
Member

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 30, 2023
&metrics.HistogramOpts{
Name: "webhook_conversion_duration_seconds",
Help: "Webhook conversion request latency",
Buckets: metrics.ExponentialBuckets(0.001, 2, 15),
Copy link
Member

Choose a reason for hiding this comment

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

It's not obvious to me what the actual buckets are from looking at this.

@@ -0,0 +1,268 @@
/*
Copyright 2019 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Copyright 2019 The Kubernetes Authors.
Copyright 2023 The Kubernetes Authors.

webhookConversionLatency: Metrics.webhookConversionLatency,
},
args: args{
ctx: context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

I'd just eliminate this and pass it in to the function directly.

webhookConversionLatency: Metrics.webhookConversionLatency,
},
args: args{
ctx: context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

same

webhookConversionLatency: Metrics.webhookConversionLatency,
},
args: args{
ctx: context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

same

webhookConversionLatency: Metrics.webhookConversionLatency,
},
args: args{
ctx: context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

same

webhookConversionLatency: Metrics.webhookConversionLatency,
},
args: args{
ctx: context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

same

webhookConversionLatency: Metrics.webhookConversionLatency,
},
args: args{
ctx: context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

same

Comment on lines 210 to 262
func expectCounterValue(t *testing.T, name string, labelFilter map[string]string, wantCount int) {
metrics, err := legacyregistry.DefaultGatherer.Gather()
if err != nil {
t.Fatalf("Failed to gather metrics: %s", err)
}

counterSum := 0
for _, mf := range metrics {
if mf.GetName() != name {
continue // Ignore other metrics.
}
for _, metric := range mf.GetMetric() {
if !testutil.LabelsMatch(metric, labelFilter) {
continue
}
counterSum += int(metric.GetCounter().GetValue())
}
}
if wantCount != counterSum {
t.Errorf("Wanted count %d, got %d for metric %s with labels %#+v", wantCount, counterSum, name, labelFilter)
for _, mf := range metrics {
if mf.GetName() == name {
for _, metric := range mf.GetMetric() {
t.Logf("\tnear match: %s", metric.String())
}
}
}
}
}

func expectHistogramCountTotal(t *testing.T, name string, labelFilter map[string]string, wantCount int) {
metrics, err := legacyregistry.DefaultGatherer.Gather()
if err != nil {
t.Fatalf("Failed to gather metrics: %s", err)
}

counterSum := 0
for _, mf := range metrics {
if mf.GetName() != name {
continue // Ignore other metrics.
}
for _, metric := range mf.GetMetric() {
if !testutil.LabelsMatch(metric, labelFilter) {
continue
}
counterSum += int(metric.GetHistogram().GetSampleCount())
}
}
if wantCount != counterSum {
t.Errorf("Wanted count %d, got %d for metric %s with labels %#+v", wantCount, counterSum, name, labelFilter)
for _, mf := range metrics {
if mf.GetName() == name {
for _, metric := range mf.GetMetric() {
Copy link
Member

Choose a reason for hiding this comment

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

I would move these into component-base/metrics/testutils, make them public and rename them assertXCount or whatnot.

func newWebhookConversionMetrics() *WebhookConversionMetrics {
webhookConversionRequest := metrics.NewCounterVec(
&metrics.CounterOpts{
Name: "webhook_conversion_requests",
Copy link
Member

Choose a reason for hiding this comment

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

  1. Subsytem should be "apiserver"
  2. Counters should be suffixed _total.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we also provide "Namespace = apiextensions-apiserver" ?

Copy link
Member

Choose a reason for hiding this comment

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

No, I'd just use "apiserver" as the Namespace. Otherwise the metric name with be prefixed apiserver_apiextensions_apiserver_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not clear.
you mean both subsystem and namespace will be "apiserver" or have to just provide namespace without subsystem ?

Making both apiserver will create name like "apiserver_apiserver_webhook_conversion_duration_seconds"

Copy link
Member

Choose a reason for hiding this comment

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

The metric name is comprised as <Namespace>_<Subsystem>_<Name>. So if you specify "apiextensions-apiserver" as a namespace and "apiserver" as a subsystem, you end up with apiextensions_apiserver_apiserver as a prefix to your metric name.

I'm just saying only use oneof {Namespace,Subsystem}, do not use both. And use "apiserver", since that's what we use everywhere else.

@k8s-ci-robot k8s-ci-robot added the sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. label May 31, 2023
Name: "webhook_conversion_duration_seconds",
Namespace: namespace,
Help: "Webhook conversion request latency",
// 0.001, 0.002, 0.004, .... 16.384 [1ms, 2ms, 4ms, ...., 16,384 ms]
Copy link
Member

Choose a reason for hiding this comment

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

16 seconds is a weird upper bound, maybe add one more bucket? Webhooks default timeout at 10 seconds, but can be configured to timeout at 30.

Copy link
Contributor Author

@cchapla cchapla May 31, 2023

Choose a reason for hiding this comment

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

Yeah. Now that you point out 16.384 seconds.

How about directly using:
0.01, 0.02, 0.05, 1, 2, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60
Or maybe we could directly have 60 after 30 just in case..

Copy link
Member

Choose a reason for hiding this comment

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

That is much better.

@cchapla cchapla requested a review from logicalhan May 31, 2023 19:13
wantLabels map[string]string
expectedRequestValue int
}{
// TODO: Add test cases.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: Add test cases.

expectedRequestValue int
expectedLatencyCount int
}{
// TODO: Add test cases.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: Add test cases.

Copy link
Member

@logicalhan logicalhan left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks for the iterations!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 930dd39309502bbe473eb161321e89cdccacf91f

@cchapla
Copy link
Contributor Author

cchapla commented Jun 1, 2023

/assign @deads2k

@dims
Copy link
Member

dims commented Jun 6, 2023

/approved

(applying approved here as @logicalhan's approval does not seem to cover staging/src/k8s.io/apiextensions-apiserver directory. Yes! the changes look good to me as well!)

cc @deads2k @sttts @jpbetz

@dims
Copy link
Member

dims commented Jun 6, 2023

/approve

(whoops typo!)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cchapla, dims, logicalhan

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 7, 2023
@k8s-ci-robot k8s-ci-robot merged commit 9ede836 into kubernetes:master Jun 7, 2023
12 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jun 7, 2023
@shyamjvs
Copy link
Member

shyamjvs commented Jun 7, 2023

@cchapla can you update the release-note to make the new metrics and their meaning clear? Something like:

Kube-apiserver adds two new alpha metrics `webhook_conversion_request_total` and `webhook_conversion_duration_seconds` that allow users to monitor requests to CRD conversion webhooks, split by result.

Also @kubernetes/sig-instrumentation-approvers - I know it's a bit late, but can someone quickly check if the metric convention used here is ok? Is conversion_webhook a better prefix than webhook_conversion? @cchapla can fix it in a follow-up PR if needed.

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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants