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

Revert "client-go: remove no longer used finalURLTemplate" #111752

Merged
merged 2 commits into from Aug 24, 2022

Conversation

aanm
Copy link
Contributor

@aanm aanm commented Aug 8, 2022

The functionality provided by the finalURLTemplate is still used by
certain external projects to track the request latency for requests
performed to kube-apiserver.

Using a template of the URL, instead of the URL itself, prevents the
explosion of label cardinality in exposed metrics since it aggregates
the URLs in a way that common URLs requests are reported as being the
same.

This reverts commit bebf5a6.

Signed-off-by: André Martins aanm90@gmail.com

What type of PR is this?

/kind bug
/kind cleanup

/kind api-change
/kind regression

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #111750

Special notes for your reviewer:

Please take a look at #111750 for more information

Does this PR introduce a user-facing change?

Revert 1.24 regression that prevented client-go latency metrics to be reported with a template URL to avoid label cardinality.

The functionality provided by the finalURLTemplate is still used by
certain external projects to track the request latency for requests
performed to kube-apiserver.

Using a template of the URL, instead of the URL itself, prevents the
explosion of label cardinality in exposed metrics since it aggregates
the URLs in a way that common URLs requests are reported as being the
same.

This reverts commit bebf5a6.

Signed-off-by: André Martins <aanm90@gmail.com>
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/regression Categorizes issue or PR as related to a regression from a prior release. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. 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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 8, 2022
@aanm
Copy link
Contributor Author

aanm commented Aug 8, 2022

/test pull-kubernetes-unit

@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@aojea
Copy link
Member

aojea commented Aug 9, 2022

Using a template of the URL, instead of the URL itself, prevents the
explosion of label cardinality in exposed metrics since it aggregates
the URLs in a way that common URLs requests are reported as being the
same.

the url path is unbounded, each CRD per example will create its own path, the templating doesn't prevent the label cardinality explosion

@aojea
Copy link
Member

aojea commented Aug 9, 2022

ah, I see the disconnection, I wasn't understanding the issue sorry.

The Interface uses the url as parameter to keep backwards compatibility, but the method that gathers the metrics only uses the host to avoid the cardinality problem

#106539

@aojea
Copy link
Member

aojea commented Aug 9, 2022

/lgtm

#111750 (comment)

The interface accepts an URL, we pass the URL without templating because we rely on the implementation to drop the path and use the host only.

func (l *latencyAdapter) Observe(ctx context.Context, verb string, u url.URL, latency time.Duration) {
l.m.WithContext(ctx).WithLabelValues(verb, u.Host).Observe(latency.Seconds())
}

However, this breaks users that decide to implement their own adapter for the latency metrics, they were relying on the URL to be templated (I don't know how safe that is though)

/assign @liggitt @wojtek-t @dgrisonnet

The CI failure is legit

running golangci-lint
staging/src/k8s.io/client-go/rest/request.go:524:32: SA5011: possible nil pointer dereference (staticcheck)
segments := strings.Split(url.Path, "/")
^
staging/src/k8s.io/client-go/rest/request.go:528:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
if url != nil && r.c.base != nil && strings.Contains(url.Path, r.c.base.Path) {

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Aug 9, 2022
Signed-off-by: André Martins <aanm90@gmail.com>
@aanm aanm force-pushed the revert-final-url-template branch from 3186c73 to 94e7b2b Compare August 9, 2022 14:54
@@ -519,14 +519,17 @@ func (r Request) finalURLTemplate() url.URL {
newParams[k] = v
}
r.params = newParams
url := r.URL()
u := r.URL()
if u == nil {
Copy link
Member

Choose a reason for hiding this comment

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

this can not happen, right? it always return an empty URL , it never returns nil

// URL returns the current working URL.
func (r *Request) URL() *url.URL {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct it can't, but otherwise there is no way to ignore the linter AFAIK. Do you have a suggestion for this? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

ah, lol, didn't got that detail

Copy link
Member

Choose a reason for hiding this comment

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

I pasted the error without looking into it 🙃
/lgtm

Copy link
Member

@dgrisonnet dgrisonnet Aug 9, 2022

Choose a reason for hiding this comment

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

I wonder if the linter guesses that the pointer might be nil based on this check:

if url != nil && r.c.base != nil && strings.Contains(url.Path, r.c.base.Path) {

Since url can't be nil, what would happen if you were to remove the check, would the linter still complain?

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 wonder if the linter guesses that the pointer might be nil based on this check:

if url != nil && r.c.base != nil && strings.Contains(url.Path, r.c.base.Path) {

Since url can't be nil, what would happen if you were to remove the check, would the linter still complain?

No, I think it simply knows that url is a pointer and we are accessing the pointer without checking if it's not nil.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 9, 2022
@fedebongio
Copy link
Contributor

/assign @yliaog
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 9, 2022
@aanm
Copy link
Contributor Author

aanm commented Aug 10, 2022

/test pull-kubernetes-integration

@liggitt
Copy link
Member

liggitt commented Aug 15, 2022

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aanm, liggitt

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 Aug 15, 2022
@aanm
Copy link
Contributor Author

aanm commented Aug 17, 2022

/milestone v1.25

@k8s-ci-robot
Copy link
Contributor

@aanm: You must be a member of the kubernetes/milestone-maintainers GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your Milestone Maintainers Team and have them propose you as an additional delegate for this responsibility.

In response to this:

/milestone v1.25

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.

@dims
Copy link
Member

dims commented Aug 18, 2022

We are talking about this PR here: https://kubernetes.slack.com/archives/C2C40FMNF/p1660773038626139

Looks like the consensus is that we wait until master opens up and then cherry-pick to 1.25.1

@k8s-ci-robot k8s-ci-robot merged commit dfd10d3 into kubernetes:master Aug 24, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Aug 24, 2022
@aanm aanm deleted the revert-final-url-template branch August 25, 2022 22:34
k8s-ci-robot added a commit that referenced this pull request Sep 7, 2022
…-origin-gh-aanm-release-1.25

Automated cherry pick of #111752: Revert "client-go: remove no longer used
k8s-ci-robot added a commit that referenced this pull request Sep 7, 2022
…-origin-gh-aanm-release-1.24

Automated cherry pick of #111752: Revert "client-go: remove no longer used
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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. 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.

Regression in client-go >= v1.24.0 metrics lead to explosion in label cardinality
10 participants