diff --git a/test/instrumentation/decode_metric.go b/test/instrumentation/decode_metric.go index 3946b9f3b3d..80b620b79db 100644 --- a/test/instrumentation/decode_metric.go +++ b/test/instrumentation/decode_metric.go @@ -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") } diff --git a/test/instrumentation/find_stable_metric.go b/test/instrumentation/find_stable_metric.go index 1e2590186ce..a5975ecbb6a 100644 --- a/test/instrumentation/find_stable_metric.go +++ b/test/instrumentation/find_stable_metric.go @@ -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 { diff --git a/test/instrumentation/main_test.go b/test/instrumentation/main_test.go index 29f38475b4e..747bce15792 100644 --- a/test/instrumentation/main_test.go +++ b/test/instrumentation/main_test.go @@ -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) } }) }