mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Fix stable metric finder for NewDesc with custom import name
This commit is contained in:
parent
baefd08919
commit
22258a263f
@ -144,7 +144,7 @@ func (c *metricDecoder) decodeDesc(ce *ast.CallExpr) (metric, error) {
|
|||||||
return *m, newDecodeErrorf(ce, "can't decode const labels")
|
return *m, newDecodeErrorf(ce, "can't decode const labels")
|
||||||
}
|
}
|
||||||
m.ConstLabels = cLabels
|
m.ConstLabels = cLabels
|
||||||
sl, err := decodeStabilityLevel(ce.Args[4], "metrics")
|
sl, err := decodeStabilityLevel(ce.Args[4], c.kubeMetricsImportName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *m, newDecodeErrorf(ce, "can't decode stability level")
|
return *m, newDecodeErrorf(ce, "can't decode stability level")
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func (f *stableMetricFinder) Visit(node ast.Node) (w ast.Visitor) {
|
|||||||
case *ast.CallExpr:
|
case *ast.CallExpr:
|
||||||
if se, ok := opts.Fun.(*ast.SelectorExpr); ok {
|
if se, ok := opts.Fun.(*ast.SelectorExpr); ok {
|
||||||
if se.Sel.Name == "NewDesc" {
|
if se.Sel.Name == "NewDesc" {
|
||||||
sl, _ := decodeStabilityLevel(opts.Args[4], "metrics")
|
sl, _ := decodeStabilityLevel(opts.Args[4], f.metricsImportName)
|
||||||
if sl != nil {
|
if sl != nil {
|
||||||
classes := []metrics.StabilityLevel{metrics.STABLE, metrics.BETA}
|
classes := []metrics.StabilityLevel{metrics.STABLE, metrics.BETA}
|
||||||
if ALL_STABILITY_CLASSES {
|
if ALL_STABILITY_CLASSES {
|
||||||
|
@ -23,6 +23,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"k8s.io/component-base/metrics"
|
"k8s.io/component-base/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -306,6 +308,21 @@ var _ = custom.NewCounter(
|
|||||||
StabilityLevel: custom.STABLE,
|
StabilityLevel: custom.STABLE,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
`},
|
||||||
|
{
|
||||||
|
testName: "Custom import NewDesc",
|
||||||
|
metric: metric{
|
||||||
|
Name: "apiserver_storage_size_bytes",
|
||||||
|
Help: "Size of the storage database file physically allocated in bytes.",
|
||||||
|
Labels: []string{"server"},
|
||||||
|
StabilityLevel: "STABLE",
|
||||||
|
Type: customType,
|
||||||
|
ConstLabels: map[string]string{},
|
||||||
|
},
|
||||||
|
src: `
|
||||||
|
package test
|
||||||
|
import custom "k8s.io/component-base/metrics"
|
||||||
|
var _ = custom.NewDesc("apiserver_storage_size_bytes", "Size of the storage database file physically allocated in bytes.", []string{"server"}, nil, custom.STABLE, "")
|
||||||
`},
|
`},
|
||||||
{
|
{
|
||||||
testName: "Const",
|
testName: "Const",
|
||||||
@ -526,8 +543,8 @@ var _ = compbasemetrics.NewCounter(
|
|||||||
if test.metric.Labels == nil {
|
if test.metric.Labels == nil {
|
||||||
test.metric.Labels = []string{}
|
test.metric.Labels = []string{}
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(metrics[0], test.metric) {
|
if diff := cmp.Diff(metrics[0], test.metric); diff != "" {
|
||||||
t.Errorf("metric:\ngot %v\nwant %v", metrics[0], test.metric)
|
t.Errorf("metric diff: %s", diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user