mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
k8s.io/component-base: support GetCounterMetricValue for Counter
GetCounterMetricValue has an unchecked conversion to metrics.Metric, something that didn't work for a *Counter because it didn't implement that interface.
This commit is contained in:
parent
6cb28fd1b4
commit
ef6f65bead
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"github.com/blang/semver"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
)
|
||||
|
||||
// Counter is our internal representation for our wrapping struct around prometheus
|
||||
@ -31,6 +32,9 @@ type Counter struct {
|
||||
selfCollector
|
||||
}
|
||||
|
||||
// The implementation of the Metric interface is expected by testutil.GetCounterMetricValue.
|
||||
var _ Metric = &Counter{}
|
||||
|
||||
// NewCounter returns an object which satisfies the kubeCollector and CounterMetric interfaces.
|
||||
// However, the object returned will not measure anything unless the collector is first
|
||||
// registered, since the metric is lazily instantiated.
|
||||
@ -46,6 +50,14 @@ func NewCounter(opts *CounterOpts) *Counter {
|
||||
return kc
|
||||
}
|
||||
|
||||
func (c *Counter) Desc() *prometheus.Desc {
|
||||
return c.metric.Desc()
|
||||
}
|
||||
|
||||
func (c *Counter) Write(to *dto.Metric) error {
|
||||
return c.metric.Write(to)
|
||||
}
|
||||
|
||||
// Reset resets the underlying prometheus Counter to start counting from 0 again
|
||||
func (c *Counter) Reset() {
|
||||
if !c.IsCreated() {
|
||||
|
Loading…
Reference in New Issue
Block a user