mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +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")
|
||||
}
|
||||
m.ConstLabels = cLabels
|
||||
sl, err := decodeStabilityLevel(ce.Args[4], "metrics")
|
||||
sl, err := decodeStabilityLevel(ce.Args[4], c.kubeMetricsImportName)
|
||||
if err != nil {
|
||||
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:
|
||||
if se, ok := opts.Fun.(*ast.SelectorExpr); ok {
|
||||
if se.Sel.Name == "NewDesc" {
|
||||
sl, _ := decodeStabilityLevel(opts.Args[4], "metrics")
|
||||
sl, _ := decodeStabilityLevel(opts.Args[4], f.metricsImportName)
|
||||
if sl != nil {
|
||||
classes := []metrics.StabilityLevel{metrics.STABLE, metrics.BETA}
|
||||
if ALL_STABILITY_CLASSES {
|
||||
|
@ -23,6 +23,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"k8s.io/component-base/metrics"
|
||||
)
|
||||
|
||||
@ -306,6 +308,21 @@ var _ = custom.NewCounter(
|
||||
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",
|
||||
@ -526,8 +543,8 @@ var _ = compbasemetrics.NewCounter(
|
||||
if test.metric.Labels == nil {
|
||||
test.metric.Labels = []string{}
|
||||
}
|
||||
if !reflect.DeepEqual(metrics[0], test.metric) {
|
||||
t.Errorf("metric:\ngot %v\nwant %v", metrics[0], test.metric)
|
||||
if diff := cmp.Diff(metrics[0], test.metric); diff != "" {
|
||||
t.Errorf("metric diff: %s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user