diff --git a/test/instrumentation/decode_metric.go b/test/instrumentation/decode_metric.go index 81bb878c4b3..4ceeda7b516 100644 --- a/test/instrumentation/decode_metric.go +++ b/test/instrumentation/decode_metric.go @@ -70,7 +70,7 @@ func (c *metricDecoder) decodeNewMetricCall(fc *ast.CallExpr) (*metric, error) { return nil, nil } switch functionName { - case "NewCounter", "NewGauge", "NewHistogram", "NewSummary", "NewTimingHistogram": + case "NewCounter", "NewGauge", "NewHistogram", "NewSummary", "NewTimingHistogram", "NewGaugeFunc": m, err = c.decodeMetric(fc) case "NewCounterVec", "NewGaugeVec", "NewHistogramVec", "NewSummaryVec", "NewTimingHistogramVec": m, err = c.decodeMetricVec(fc) @@ -90,7 +90,7 @@ func getMetricType(functionName string) string { switch functionName { case "NewCounter", "NewCounterVec": return counterMetricType - case "NewGauge", "NewGaugeVec": + case "NewGauge", "NewGaugeVec", "NewGaugeFunc": return gaugeMetricType case "NewHistogram", "NewHistogramVec": return histogramMetricType @@ -104,7 +104,7 @@ func getMetricType(functionName string) string { } func (c *metricDecoder) decodeMetric(call *ast.CallExpr) (metric, error) { - if len(call.Args) != 1 { + if len(call.Args) > 2 { return metric{}, newDecodeErrorf(call, errInvalidNewMetricCall) } return c.decodeOpts(call.Args[0]) diff --git a/test/instrumentation/testdata/pkg/kubelet/metrics/metrics.go b/test/instrumentation/testdata/pkg/kubelet/metrics/metrics.go index 45bbe077938..da29941fb30 100644 --- a/test/instrumentation/testdata/pkg/kubelet/metrics/metrics.go +++ b/test/instrumentation/testdata/pkg/kubelet/metrics/metrics.go @@ -481,6 +481,20 @@ func Register(collectors ...metrics.StableCollector) { for _, collector := range collectors { legacyregistry.CustomMustRegister(collector) } + legacyregistry.RawMustRegister(metrics.NewGaugeFunc( + &metrics.GaugeOpts{ + Subsystem: "kubelet", + Name: "certificate_manager_client_ttl_seconds", + Help: "Gauge of the TTL (time-to-live) of the Kubelet's client certificate. " + + "The value is in seconds until certificate expiry (negative if already expired). " + + "If client certificate is invalid or unused, the value will be +INF.", + StabilityLevel: metrics.BETA, + }, + func() float64 { + return 0 + }, + )) + }) } diff --git a/test/instrumentation/testdata/test-stable-metrics-list.yaml b/test/instrumentation/testdata/test-stable-metrics-list.yaml index 4fbe7ee07c1..668daa62d7b 100644 --- a/test/instrumentation/testdata/test-stable-metrics-list.yaml +++ b/test/instrumentation/testdata/test-stable-metrics-list.yaml @@ -1,3 +1,10 @@ +- name: certificate_manager_client_ttl_seconds + subsystem: kubelet + help: Gauge of the TTL (time-to-live) of the Kubelet's client certificate. The value + is in seconds until certificate expiry (negative if already expired). If client + certificate is invalid or unused, the value will be +INF. + type: Gauge + stabilityLevel: BETA - name: device_plugin_alloc_duration_seconds subsystem: kubelet help: Duration in seconds to serve a device plugin Allocation request. Broken down