Skip to content

Commit

Permalink
metric: Support slice type
Browse files Browse the repository at this point in the history
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, cockroachdb#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
  • Loading branch information
Yevgeniy Miretskiy authored and wenyihu6 committed Jul 23, 2024
1 parent 2073003 commit e3581e3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/util/metric/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e3581e3

Please sign in to comment.