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

Add histogram exemplar support #124013

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

richabanker
Copy link
Contributor

@richabanker richabanker commented Mar 20, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds exemplar support for histograms

Which issue(s) this PR fixes:

Fixes #119697

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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 Mar 20, 2024
@k8s-ci-robot k8s-ci-robot added area/apiserver 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 Mar 20, 2024
func (noopMetric) Set(float64) {}
func (noopMetric) Sub(float64) {}
func (noopMetric) Observe(float64) {}
func (noopMetric) ObserveWithExemplar(float64, prometheus.Labels) {}
Copy link
Member

Choose a reason for hiding this comment

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

I'm revisiting this after a good while but IIRC from a discussion with @logicalhan around exemplar support for counters, we want to modify the existing methods implicitly (without modifying their signatures) to support exemplars OOTB.

Additionally, my understanding is that we don't want to make any component directly dependent on prometheus/client_golang, but incorporate that behavior into component-base and have them import that instead, in an effort to be able to offset any breaking changes and not having to send patches upstream (and catering to any extra use-cases specific to k/k).

All components themselves will be responsible for "attaching" exemplars within their contexts, if they want to utilize this feature-set, but we won't have to make any explicit changes in any component for this feature-set to work. However, the SIG can help components benefit from this by patching their contexts for them, but I believe that is out of the scope of this effort (adding exemplar support to component-base).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the pointers @rexagod. The initial version of this PR was mostly a POC to verify that we are able to see exemplars after-all in metrics, hence admittedly had quite a lot of hacky stuff going on at first.

I modified this PR now, following what you are doing for counters in #119949, though it still needs to use the component-base.metrics.exemplarMetric that you have introduced, so I'll wait for that PR to merge first and make those changes then.

Additionally I am wondering, if we need to introduce Add()/Observe() methods for CounterVec/HistogramVec too?

@richabanker richabanker marked this pull request as ready for review April 18, 2024 16:04
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 18, 2024
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed 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 Apr 18, 2024
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.

/assign
/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 Apr 18, 2024
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

lgtm with one nit

Comment on lines 42 to 49
h.withExemplar(v)
}

func (h *Histogram) withExemplar(v float64) {
(&exemplarHistogram{h}).withExemplar(v)
}

func (h *exemplarHistogram) withExemplar(v float64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need the extra exemplarHistogram type and the withExemplar functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I don't. Can't remember why I did that, removed it now.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: richabanker
Once this PR has been reviewed and has the lgtm label, please ask for approval from logicalhan. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

same comments for exemplarHistogramVec

"span_id": maybeSpanCtx.SpanID().String(),
}
}
if m, ok := h.ObserverMetric.(prometheus.ExemplarObserver); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this always going to be true? Should we fall back to the regular observe if it isn't an examplar observer?

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 am not sure... but still, added a fallback to use the regular Observe() flow.

}

func (h *Histogram) withExemplar(v float64) {
var exemplarLabels prometheus.Labels
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this inside the if statement below to avoid unnecessary computation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, moved.

@richabanker
Copy link
Contributor Author

same comments for exemplarHistogramVec

I need to wrap the return value of func (vc *HistogramVecWithContext) WithLabelValues(lvs ...string) which is currently ObserverMetric into a struct on which I could apply func withExemplar(). So the extra exemplarHistogramVec is needed for exemplarHistogramVec.

@k8s-ci-robot
Copy link
Contributor

@richabanker: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-integration a73152a link true /test pull-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. 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/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.

Trace exemplars for kube-apiserver metrics
5 participants