mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #78867 from logicalhan/annotate-counter-vec
fix stability level annotation for counter vec
This commit is contained in:
commit
a767890968
@ -86,6 +86,10 @@ type CounterVec struct {
|
|||||||
// However, the object returned will not measure anything unless the collector is first
|
// However, the object returned will not measure anything unless the collector is first
|
||||||
// registered, since the metric is lazily instantiated.
|
// registered, since the metric is lazily instantiated.
|
||||||
func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
|
func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
|
||||||
|
// todo: handle defaulting better
|
||||||
|
if opts.StabilityLevel == "" {
|
||||||
|
opts.StabilityLevel = ALPHA
|
||||||
|
}
|
||||||
cv := &CounterVec{
|
cv := &CounterVec{
|
||||||
CounterVec: noopCounterVec,
|
CounterVec: noopCounterVec,
|
||||||
CounterOpts: opts,
|
CounterOpts: opts,
|
||||||
@ -104,6 +108,7 @@ func (v *CounterVec) DeprecatedVersion() *semver.Version {
|
|||||||
// initializeMetric invocation creates the actual underlying CounterVec. Until this method is called
|
// initializeMetric invocation creates the actual underlying CounterVec. Until this method is called
|
||||||
// the underlying counterVec is a no-op.
|
// the underlying counterVec is a no-op.
|
||||||
func (v *CounterVec) initializeMetric() {
|
func (v *CounterVec) initializeMetric() {
|
||||||
|
v.CounterOpts.annotateStabilityLevel()
|
||||||
v.CounterVec = prometheus.NewCounterVec(v.CounterOpts.toPromCounterOpts(), v.originalLabels)
|
v.CounterVec = prometheus.NewCounterVec(v.CounterOpts.toPromCounterOpts(), v.originalLabels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func TestCounterVec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
labels: []string{"label_a", "label_b"},
|
labels: []string{"label_a", "label_b"},
|
||||||
expectedMetricFamilyCount: 1,
|
expectedMetricFamilyCount: 1,
|
||||||
expectedHelp: "counter help",
|
expectedHelp: "[ALPHA] counter help",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Test deprecated",
|
desc: "Test deprecated",
|
||||||
@ -156,7 +156,7 @@ func TestCounterVec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
labels: []string{"label_a", "label_b"},
|
labels: []string{"label_a", "label_b"},
|
||||||
expectedMetricFamilyCount: 1,
|
expectedMetricFamilyCount: 1,
|
||||||
expectedHelp: "(Deprecated since 1.15.0) counter help",
|
expectedHelp: "[ALPHA] (Deprecated since 1.15.0) counter help",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Test hidden",
|
desc: "Test hidden",
|
||||||
@ -171,6 +171,19 @@ func TestCounterVec(t *testing.T) {
|
|||||||
expectedMetricFamilyCount: 0,
|
expectedMetricFamilyCount: 0,
|
||||||
expectedHelp: "counter help",
|
expectedHelp: "counter help",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Test alpha",
|
||||||
|
CounterOpts: &CounterOpts{
|
||||||
|
StabilityLevel: ALPHA,
|
||||||
|
Namespace: "namespace",
|
||||||
|
Name: "metric_test_name",
|
||||||
|
Subsystem: "subsystem",
|
||||||
|
Help: "counter help",
|
||||||
|
},
|
||||||
|
labels: []string{"label_a", "label_b"},
|
||||||
|
expectedMetricFamilyCount: 1,
|
||||||
|
expectedHelp: "[ALPHA] counter help",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user