Merge pull request #78867 from logicalhan/annotate-counter-vec

fix stability level annotation for counter vec
This commit is contained in:
Kubernetes Prow Robot 2019-06-14 23:06:09 -07:00 committed by GitHub
commit a767890968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -86,6 +86,10 @@ type CounterVec struct {
// However, the object returned will not measure anything unless the collector is first
// registered, since the metric is lazily instantiated.
func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
// todo: handle defaulting better
if opts.StabilityLevel == "" {
opts.StabilityLevel = ALPHA
}
cv := &CounterVec{
CounterVec: noopCounterVec,
CounterOpts: opts,
@ -104,6 +108,7 @@ func (v *CounterVec) DeprecatedVersion() *semver.Version {
// initializeMetric invocation creates the actual underlying CounterVec. Until this method is called
// the underlying counterVec is a no-op.
func (v *CounterVec) initializeMetric() {
v.CounterOpts.annotateStabilityLevel()
v.CounterVec = prometheus.NewCounterVec(v.CounterOpts.toPromCounterOpts(), v.originalLabels)
}

View File

@ -143,7 +143,7 @@ func TestCounterVec(t *testing.T) {
},
labels: []string{"label_a", "label_b"},
expectedMetricFamilyCount: 1,
expectedHelp: "counter help",
expectedHelp: "[ALPHA] counter help",
},
{
desc: "Test deprecated",
@ -156,7 +156,7 @@ func TestCounterVec(t *testing.T) {
},
labels: []string{"label_a", "label_b"},
expectedMetricFamilyCount: 1,
expectedHelp: "(Deprecated since 1.15.0) counter help",
expectedHelp: "[ALPHA] (Deprecated since 1.15.0) counter help",
},
{
desc: "Test hidden",
@ -171,6 +171,19 @@ func TestCounterVec(t *testing.T) {
expectedMetricFamilyCount: 0,
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 {