-
Notifications
You must be signed in to change notification settings - Fork 554
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
Instrument metrics #645
base: master
Are you sure you want to change the base?
Instrument metrics #645
Conversation
cerberus20
commented
Feb 29, 2024
Hi @cerberus20. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/assign @dgrisonnet |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: cerberus20 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@dgrisonnet /ping |
@dgrisonnet Can you please help review? thank you. |
pkg/client/metrics/metrics.go
Outdated
apiErrorCount = metrics.NewCounterVec( | ||
&metrics.CounterOpts{ | ||
Namespace: "prometheus_adapter", | ||
Subsystem: "prometheus_client", | ||
Name: "api_errors_total", | ||
Help: "Total number of API errors", | ||
}, | ||
[]string{"error_code", "path", "server"}, |
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.
In order to compute an error rate and produce an alert out of this metric, it is usually better to record all the request including the one that succeed.
A common practice is to have a http_requests_total
metric with a code
label. In you case I would suggest to have a api_requests_total
metric that record all the requests and rename the label to code
and set it to the http status code of the request.
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, makes sense, updated with api_requests_total. thanks for the suggestion.
pkg/client/metrics/metrics.go
Outdated
errRegisterQueryLatency := registry.Register(queryLatency) | ||
if errRegisterQueryLatency != nil { | ||
return nil, errRegisterQueryLatency | ||
} | ||
|
||
errRegisterAPIErrorCount := registry.Register(apiErrorCount) | ||
if errRegisterAPIErrorCount != nil { | ||
return nil, errRegisterAPIErrorCount | ||
} |
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.
Since we don't necessarily need to differentiate between the errors here, it is usually a common practice in Go to just have one err
variable and reuse it for reach Register
call.
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.
updated, thanks
pkg/client/metrics/metrics.go
Outdated
if apiErr, wasAPIErr := err.(*client.Error); wasAPIErr { | ||
apiRequestsTotal.With(prometheus.Labels{"code": string(apiErr.Type), "path": endpoint, "server": c.serverName}).Inc() | ||
} else { | ||
apiRequestsTotal.With(prometheus.Labels{"code": "generic", "path": endpoint, "server": c.serverName}).Inc() | ||
} |
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.
When I first looked at your PR I had forgotten that the client errors were wrapped https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/pkg/client/types.go#L27-L31 which is not ideal as it is less explicit to users than a normal http code would be. I feel like we should change some things in order to surface the http code and expose it in the metrics.
I'll be out till the 27th of May, but I'll try to have a look at that again when I am back.
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.
@dgrisonnet I updated code to add HTTPStatusCode to APIResponse to expose the http code in the metric. Can you please review? Thank you.
…ent-metrics # Conflicts: # pkg/client/metrics/metrics.go
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |