From e3581e3607fcbd05f223e7f07682226608753ad2 Mon Sep 17 00:00:00 2001 From: Yevgeniy Miretskiy Date: Thu, 7 Sep 2023 09:33:33 -0400 Subject: [PATCH] metric: Support slice type Extend metric registry to allow metric slices to be used. Prior to this change metric registry only alowed arrays. Slices are treated identical to the arrays -- the values are expanded, and each metric added to the registry. The array itself was not added. From some historical archeological perspective, #46747 added support for embedded metric Arrays. My best read on this PR is that it narrowly addressed the existing "TODOs", and avoided doing anything extra (which is good!). But it does not appear that there is a fundamental reason why slices should not be supported the same way. Expic: None Release note: None # Conflicts: # pkg/util/metric/registry.go # pkg/util/metric/registry_test.go --- pkg/util/metric/registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/metric/registry.go b/pkg/util/metric/registry.go index 8a9e071328c9..ce9f0aa722fd 100644 --- a/pkg/util/metric/registry.go +++ b/pkg/util/metric/registry.go @@ -107,7 +107,7 @@ func (r *Registry) AddMetricStruct(metricStruct interface{}) { continue } switch vfield.Kind() { - case reflect.Array: + case reflect.Array, reflect.Slice: for i := 0; i < vfield.Len(); i++ { velem := vfield.Index(i) telemName := fmt.Sprintf("%s[%d]", tname, i)