add support for parsing gauge func

Change-Id: Id0b9cd51dead5ee9f4adac804d62f5d9742320a7
This commit is contained in:
Han Kang 2022-10-12 08:30:06 -07:00
parent 4f2faa2f1c
commit 49c08947f7
3 changed files with 24 additions and 3 deletions

View File

@ -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])

View File

@ -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
},
))
})
}

View File

@ -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