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

Update kubevirt_rest_client_request_latency_seconds to count list cal… #12716

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

Sreeja1725
Copy link

@Sreeja1725 Sreeja1725 commented Sep 2, 2024

What this PR does

Currently, when a list call is made using field-selector or label-selector those calls are inaccurately counted as get calls. This MR will solve this issue.

Why we need it and why it was done in this way

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

 Update kubevirt_rest_client_request_latency_seconds to count list calls if made using query params

@kubevirt-bot kubevirt-bot added the dco-signoff: no Indicates the PR's author has not DCO signed all their commits. label Sep 2, 2024
@kubevirt-bot kubevirt-bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. sig/observability Denotes an issue or PR that relates to observability. labels Sep 2, 2024
@kubevirt-bot
Copy link
Contributor

Hi @Sreeja1725. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. 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 Sep 2, 2024
@Sreeja1725
Copy link
Author

cc @alaypatel07

@Sreeja1725 Sreeja1725 marked this pull request as draft September 2, 2024 17:42
@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 2, 2024
@xpivarc
Copy link
Member

xpivarc commented Sep 3, 2024

/cc @machadovilaca

@machadovilaca
Copy link
Member

thanks for the PR @Sreeja1725, we would need to validate this change (removing the usage of the latency adapter for requestLatency) does not have unexpected consequences. I wonder if you couldn't adapt

func (l *latencyAdapter) Observe(_ context.Context, verb string, u url.URL, latency time.Duration) {
instead, since you have access to the URL there too

@kubevirt-bot kubevirt-bot added dco-signoff: no Indicates the PR's author has not DCO signed all their commits. size/M and removed dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/XS labels Sep 3, 2024
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Sep 3, 2024
@Sreeja1725
Copy link
Author

thanks for the PR @Sreeja1725, we would need to validate this change (removing the usage of the latency adapter for requestLatency) does not have unexpected consequences. I wonder if you couldn't adapt

func (l *latencyAdapter) Observe(_ context.Context, verb string, u url.URL, latency time.Duration) {

instead, since you have access to the URL there too

Thanks for your response @machadovilaca , I have updated as per your comment. PTAL

Comment on lines 36 to 39
resource := findResource(u)
if resource == "" {
resource = "none"
}
Copy link
Member

Choose a reason for hiding this comment

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

I see that you improved a bit, was going to comment on this, but what would you think about:

func getVerbLabelValue(u url.URL, verb string) string {
	if verb != "GET" {
		return verb
	}

	if strings.Contains(u.Path, "/watch/") || u.Query().Get("watch") == "true" {
		return "WATCH"
	}

	resource := findResource(u)
	if resource == "" {
		resource = "none"
	}

	if strings.HasSuffix(u.Path, resource) {
		// If the resource is the last element in the url, then
		// we're asking to list all resources of that type instead
		// of getting an individual resource
		return "LIST"
	}

	return verb
}

yet a bit better, no?

Copy link
Member

Choose a reason for hiding this comment

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

and then just
l.m.WithLabelValues(getVerbLabelValue(u, verb), u.String()).Observe(latency.Seconds())

Copy link
Author

Choose a reason for hiding this comment

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

Yes, it's better! The refactoring made the code cleaner and modular. Thanks @machadovilaca for simplifying the logic and separating concerns.

@dosubot dosubot bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Sep 9, 2024
@alaypatel07
Copy link
Contributor

/ok-to-test

@alaypatel07
Copy link
Contributor

/retest

@alaypatel07
Copy link
Contributor

@machadovilaca can you please do a second round of reviews on this PR?

@machadovilaca
Copy link
Member

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: machadovilaca

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 19, 2024
@Sreeja1725
Copy link
Author

@xpivarc Can you PTAL

@xpivarc
Copy link
Member

xpivarc commented Sep 26, 2024

/cc @0xFelix

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

Added some comments can you please put something in the commit message?

Comment on lines 96 to 99
resource := findResource(u)
if resource == "" {
return "none"
}
Copy link
Member

Choose a reason for hiding this comment

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

Could be inlined

Comment on lines 113 to 114
match := r.FindStringSubmatch(u.Path)
if len(match) > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Could be inlined

}
match := r.FindStringSubmatch(u.Path)
if len(match) > 1 {
resource = match[1]
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
resource = match[1]
return match[1]

Comment on lines 110 to 112
if resource != "" {
break
}
Copy link
Member

Choose a reason for hiding this comment

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

Drop this

resource = match[1]
}
}
return resource
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
return resource
return ""

return resource, verb
}

func determineVerb(u url.URL, methodOrVerb string) (verb string) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make the funcs name more descriptive? Something like getVerbFromHTTPVerb?

return resource
}

func getHost(request *http.Request) string {
Copy link
Member

Choose a reason for hiding this comment

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

Is it used only in a single place? If so it's okay to keep it inline.

Comment on lines 37 to 39
resource string
verb string
host string
Copy link
Member

Choose a reason for hiding this comment

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

Define these vars on the go with :=

@kubevirt-bot kubevirt-bot added dco-signoff: no Indicates the PR's author has not DCO signed all their commits. and removed dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Sep 26, 2024
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Sep 26, 2024
@Sreeja1725
Copy link
Author

@0xFelix Addressed all your comments, PTAL

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

/lgtm

Two nits, feel free to address

}

switch method {
verb = getVerbFromHTTPVerb(*request.URL, method)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Could be inlined

var resource string
var verb string
var host string
var status, host string
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
var status, host string
var status string
var host string

nit: Not sure we got a rule for that though

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 30, 2024
@kubevirt-commenter-bot
Copy link

Required labels detected, running phase 2 presubmits:
/test pull-kubevirt-e2e-windows2016
/test pull-kubevirt-e2e-kind-1.30-vgpu
/test pull-kubevirt-e2e-kind-sriov
/test pull-kubevirt-e2e-k8s-1.30-ipv6-sig-network
/test pull-kubevirt-e2e-k8s-1.29-sig-network
/test pull-kubevirt-e2e-k8s-1.29-sig-storage
/test pull-kubevirt-e2e-k8s-1.29-sig-compute
/test pull-kubevirt-e2e-k8s-1.29-sig-operator
/test pull-kubevirt-e2e-k8s-1.30-sig-network
/test pull-kubevirt-e2e-k8s-1.30-sig-storage
/test pull-kubevirt-e2e-k8s-1.30-sig-compute
/test pull-kubevirt-e2e-k8s-1.30-sig-operator

@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 30, 2024
@Sreeja1725
Copy link
Author

@0xFelix Updated as per your comments, PTAL

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

/lgtm

Thanks!

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 1, 2024
@kubevirt-commenter-bot
Copy link

Required labels detected, running phase 2 presubmits:
/test pull-kubevirt-e2e-windows2016
/test pull-kubevirt-e2e-kind-1.30-vgpu
/test pull-kubevirt-e2e-kind-sriov
/test pull-kubevirt-e2e-k8s-1.30-ipv6-sig-network
/test pull-kubevirt-e2e-k8s-1.29-sig-network
/test pull-kubevirt-e2e-k8s-1.29-sig-storage
/test pull-kubevirt-e2e-k8s-1.29-sig-compute
/test pull-kubevirt-e2e-k8s-1.29-sig-operator
/test pull-kubevirt-e2e-k8s-1.30-sig-network
/test pull-kubevirt-e2e-k8s-1.30-sig-storage
/test pull-kubevirt-e2e-k8s-1.30-sig-compute
/test pull-kubevirt-e2e-k8s-1.30-sig-operator

@kubevirt-bot kubevirt-bot merged commit ecc7c8f into kubevirt:main Oct 1, 2024
41 checks passed
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. area/monitoring dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/observability Denotes an issue or PR that relates to observability. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants