-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Conversation
/assign @logicalhan @dgrisonnet @wojtek-t @tkashem |
There was a problem hiding this 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"}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, changed
There was a problem hiding this comment.
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
347cd8c
to
ec2a48a
Compare
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
staging/src/k8s.io/component-base/metrics/prometheus/restclient/metrics.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/component-base/metrics/prometheus/restclient/metrics.go
Outdated
Show resolved
Hide resolved
@@ -40,6 +40,16 @@ var ( | |||
[]string{"verb", "host"}, | |||
) | |||
|
|||
requestSize = k8smetrics.NewHistogramVec( | |||
&k8smetrics.HistogramOpts{ | |||
Name: "rest_client_request_size_bytes", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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,
ec2a48a
to
5c2403d
Compare
5c2403d
to
58c44aa
Compare
/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}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
/test pull-kubernetes-integration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/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)) |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the condition is weird, but is based on
https://cs.opensource.google/go/go/+/refs/tags/go1.17.7:src/net/http/request.go;l=919-927;drc=e6dda19888180c5159460486d30c0412e4980748
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
3770f73
to
6e80080
Compare
6e80080
to
ace9bdd
Compare
/triage accepted |
/triage accepted |
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.
ace9bdd
to
64d9d05
Compare
/approve |
[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 |
/retest |
E2eNode Suite: [sig-node] Summary API [NodeConformance] when querying /stats/summary should report resource usage through the stats api |
/lgtm |
Kubernetes e2e suite: [sig-network] Proxy version v1 A set of valid responses are returned for both pod and service ProxyWithPath [Conformance] expand_less |
/kind feature
What this PR does / why we need it: