Skip to content

Commit 460b847

Browse files
committed
fixup! metrics: add exemplar support for counters
1 parent 47c21fa commit 460b847

File tree

10 files changed

+20
-3
lines changed

10 files changed

+20
-3
lines changed

staging/src/k8s.io/component-base/metrics/counter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,9 @@ func TestCounterWithExemplar(t *testing.T) {
302302
traceID := trace.TraceID(fn(1))
303303
spanID := trace.SpanID(fn(2))
304304
ctxForSpanCtx := trace.ContextWithSpanContext(context.Background(), trace.NewSpanContext(trace.SpanContextConfig{
305-
TraceID: traceID,
306-
SpanID: spanID,
305+
SpanID: spanID,
306+
TraceID: traceID,
307+
TraceFlags: trace.FlagsSampled,
307308
}))
308309
toAdd := float64(40)
309310

staging/src/k8s.io/component-base/metrics/metric.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ type exemplarMetric struct {
226226
func (e *exemplarMetric) withExemplar(v float64) {
227227
if m, ok := e.CounterMetric.(prometheus.ExemplarAdder); ok {
228228
maybeSpanCtx := trace.SpanContextFromContext(e.ctx)
229-
if maybeSpanCtx.IsValid() {
229+
if maybeSpanCtx.IsValid() && maybeSpanCtx.IsSampled() {
230230
exemplarLabels := prometheus.Labels{
231231
"trace_id": maybeSpanCtx.TraceID().String(),
232232
"span_id": maybeSpanCtx.SpanID().String(),

staging/src/k8s.io/dynamic-resource-allocation/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ require (
5858
github.com/spf13/pflag v1.0.5 // indirect
5959
github.com/stoewer/go-strcase v1.2.0 // indirect
6060
github.com/x448/float16 v0.8.4 // indirect
61+
go.opentelemetry.io/otel v1.28.0 // indirect
62+
go.opentelemetry.io/otel/trace v1.28.0 // indirect
6163
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
6264
golang.org/x/net v0.30.0 // indirect
6365
golang.org/x/oauth2 v0.23.0 // indirect

staging/src/k8s.io/dynamic-resource-allocation/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/endpointslice/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ require (
4848
github.com/prometheus/procfs v0.15.1 // indirect
4949
github.com/spf13/pflag v1.0.5 // indirect
5050
github.com/x448/float16 v0.8.4 // indirect
51+
go.opentelemetry.io/otel v1.28.0 // indirect
52+
go.opentelemetry.io/otel/trace v1.28.0 // indirect
5153
golang.org/x/net v0.30.0 // indirect
5254
golang.org/x/oauth2 v0.23.0 // indirect
5355
golang.org/x/sys v0.26.0 // indirect

staging/src/k8s.io/endpointslice/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/kube-proxy/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ require (
3434
github.com/spf13/cobra v1.8.1 // indirect
3535
github.com/spf13/pflag v1.0.5 // indirect
3636
github.com/x448/float16 v0.8.4 // indirect
37+
go.opentelemetry.io/otel v1.28.0 // indirect
38+
go.opentelemetry.io/otel/trace v1.28.0 // indirect
3739
golang.org/x/net v0.30.0 // indirect
3840
golang.org/x/sys v0.26.0 // indirect
3941
golang.org/x/text v0.19.0 // indirect

staging/src/k8s.io/kube-proxy/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/kubelet/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ require (
4747
github.com/spf13/cobra v1.8.1 // indirect
4848
github.com/spf13/pflag v1.0.5 // indirect
4949
github.com/x448/float16 v0.8.4 // indirect
50+
go.opentelemetry.io/otel v1.28.0 // indirect
51+
go.opentelemetry.io/otel/trace v1.28.0 // indirect
5052
golang.org/x/net v0.30.0 // indirect
5153
golang.org/x/oauth2 v0.23.0 // indirect
5254
golang.org/x/sys v0.26.0 // indirect

staging/src/k8s.io/kubelet/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)