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

client-go: add request and response size metrics #108296

Merged
merged 1 commit into from
Feb 28, 2022

Conversation

aojea
Copy link
Member

@aojea aojea commented Feb 23, 2022

/kind feature

What this PR does / why we need it:

client-go: add new histogram metric to record the size of the requests and responses.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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. labels Feb 23, 2022
@k8s-ci-robot k8s-ci-robot added 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. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 23, 2022
@aojea
Copy link
Member Author

aojea commented Feb 23, 2022

/assign @logicalhan @dgrisonnet @wojtek-t @tkashem

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.

Just one concern but this otherwise lgtm

// Use buckets ranging from 1000 bytes (1KB) to 10^9 bytes (1GB).
Buckets: k8smetrics.ExponentialBuckets(1000, 10.0, 7),
},
[]string{"verb", "url"},
Copy link
Member

Choose a reason for hiding this comment

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

this should definitely not use url and should most definitely use host due to cardinality concerns.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, changed

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, wait, this is a new interface, we can pass the host directly

@@ -42,6 +42,11 @@ type LatencyMetric interface {
Observe(ctx context.Context, verb string, u url.URL, latency time.Duration)
}

// SizeMetric observes client response size partitioned by verb and url.
type SizeMetric interface {
Observe(ctx context.Context, verb string, u url.URL, size float64)
Copy link
Member Author

Choose a reason for hiding this comment

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

@logicalhan better if I set the host here instead of the url, right?

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 fine to pass the URL and use the host property.

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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 23, 2022
@@ -40,6 +40,16 @@ var (
[]string{"verb", "host"},
)

requestSize = k8smetrics.NewHistogramVec(
&k8smetrics.HistogramOpts{
Name: "rest_client_request_size_bytes",
Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, I think response is a better name

Copy link
Member

Choose a reason for hiding this comment

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

that's totally different, are you measuring what we get or what we are returning?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, we should measure both , there are cases that the problems can be related to POST or GET with huge payloads,

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 23, 2022
@aojea
Copy link
Member Author

aojea commented Feb 23, 2022

/hold

I want to verify the metrics before merging now that we have a presubmit job that gives us a prometheus dump ... but please keep adding comments

Help: "Response size in bytes. Broken down by verb and host.",
StabilityLevel: k8smetrics.ALPHA,
// 64 bytes to 16MB
Buckets: []float64{64, 256, 512, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216},
Copy link
Member

Choose a reason for hiding this comment

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

Should we perhaps sync the buckets of apiserver_response_sizes based on these new ones as a follow-up? https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go#L125-L134

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that this ones are more "realistic" , I'm +1 on that

@aojea
Copy link
Member Author

aojea commented Feb 24, 2022

/test pull-kubernetes-integration

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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 24, 2022
@logicalhan
Copy link
Member

/approve

@aojea
Copy link
Member Author

aojea commented Feb 24, 2022

/approve

I see @liggitt active, let's see if we can put this in his queue , wojtek told me he is a bit busy these days

@@ -901,6 +901,7 @@ func (r *Request) request(ctx context.Context, fn func(*http.Request, *http.Resp
}
resp, err := client.Do(req)
updateURLMetrics(ctx, r, resp, err)
metrics.RequestSize.Observe(ctx, r.verb, r.URL().Host, float64(req.ContentLength))
Copy link
Member

Choose a reason for hiding this comment

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

is ContentLength always populated? is there ever a case we should ignore (-1 or 0 with non-nil body?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I honestly can't say, I was trying to skim the golang code but found it confusing, I will add an if to avoid the -1 and 0 corner cases to be safe

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

is ContentLength always populated? is there ever a case we should ignore (-1 or 0 with non-nil body?)

ignored on that case

@@ -963,6 +964,7 @@ func (r *Request) Do(ctx context.Context) Result {
if err != nil {
return Result{err: err}
}
metrics.ResponseSize.Observe(ctx, r.verb, r.URL().Host, float64(len(result.body)))
Copy link
Member

Choose a reason for hiding this comment

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

does this do the right thing if result is an error result? (result.err != nil)

Copy link
Member Author

@aojea aojea Feb 24, 2022

Choose a reason for hiding this comment

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

I had the same doubt for latency, and asking people with more experience they told me that latency should take into account errors too, because measure the time the client is waiting.
However, for size, I can't see why do we want to store a zero on a failed request, we didn't have a result so I don't think we should measure a length of nothing

Copy link
Member Author

@aojea aojea Feb 24, 2022

Choose a reason for hiding this comment

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

result.body is nil on failure, hence I don't think we should measure it, there is no response

Copy link
Member Author

Choose a reason for hiding this comment

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

I confirmed there is no null value in prometheus , so this is correct, only measure if it exists

Copy link
Member

Choose a reason for hiding this comment

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

it still seems like this should be guarded on something like if result.err == nil of if result.body != nil

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

@@ -979,6 +981,7 @@ func (r *Request) DoRaw(ctx context.Context) ([]byte, error) {
if err != nil {
return nil, err
}
metrics.ResponseSize.Observe(ctx, r.verb, r.URL().Host, float64(len(result.body)))
Copy link
Member

Choose a reason for hiding this comment

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

same question about this doing the right thing if result.err != nil

Copy link
Member Author

Choose a reason for hiding this comment

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

the metrics is associated to the response, and there is no response if err != nil, that is different from result.err != nil

Copy link
Member

Choose a reason for hiding this comment

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

should this be guarded on if result.body != nil?

Copy link
Member Author

@aojea aojea Feb 28, 2022

Choose a reason for hiding this comment

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

can it be nil?

// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body.

beside that, is a great question, do we record it as 0 or do we ignore?

Copy link
Member

Choose a reason for hiding this comment

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

I think if result.err != nil and len(result.body) == 0, we should not record

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

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

/triage accepted
Thank you to all the reviewers!

@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 Feb 24, 2022
@logicalhan
Copy link
Member

/triage accepted

@aojea
Copy link
Member Author

aojea commented Feb 26, 2022

ping @liggitt

Get metrics for the request and response  size, so we can correlate latency
and size on a request, otherwise we could get confused because we don't know if the
network is slow or just the request size huge.
@liggitt
Copy link
Member

liggitt commented Feb 28, 2022

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, liggitt, 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 Feb 28, 2022
@aojea
Copy link
Member Author

aojea commented Feb 28, 2022

/retest
E2eNode Suite: [sig-node] Summary API [NodeConformance] when querying /stats/summary should report resource usage through the stats api expand_less
k8s.io/kubernetes/vendor/k8s.io/apiextensions-apiserver/test/integration: TestCRValidationOnCRDUpdate expand_less

@aojea
Copy link
Member Author

aojea commented Feb 28, 2022

E2eNode Suite: [sig-node] Summary API [NodeConformance] when querying /stats/summary should report resource usage through the stats api
/test pull-kubernetes-node-e2e-containerd

@tkashem
Copy link
Contributor

tkashem commented Feb 28, 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 28, 2022
@aojea
Copy link
Member Author

aojea commented Feb 28, 2022

Kubernetes e2e suite: [sig-network] Proxy version v1 A set of valid responses are returned for both pod and service ProxyWithPath [Conformance] expand_less
/test pull-kubernetes-conformance-kind-ga-only-parallel

@k8s-ci-robot k8s-ci-robot merged commit 5ee80de into kubernetes:master Feb 28, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 28, 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. kind/feature Categorizes issue or PR as related to a new feature. 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. 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/M Denotes a PR that changes 30-99 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

8 participants