Fix label resolution for maps

The `map[string]interface{}` resolution searched for values within various nested fields, but not the relative path itself.

Ref.: ca1da6b22e/pkg/customresourcestate/registry_factory.go (L603)

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
This commit is contained in:
Pranshu Srivastava 2023-02-23 00:10:01 +05:30
parent 91c09d0a96
commit 3f0532bc50
No known key found for this signature in database
GPG Key ID: 3CDBD4D4CEF89B86
2 changed files with 3 additions and 1 deletions

View File

@ -264,6 +264,8 @@ func (c *compiledGauge) Values(v interface{}) (result []eachValue, errs []error)
ev.Labels[c.labelFromKey] = key
}
addPathLabels(it, c.LabelFromPath(), ev.Labels)
// Evaluate path from parent's context as well (search w.r.t. the root element, not just specific fields).
addPathLabels(v, c.LabelFromPath(), ev.Labels)
result = append(result, *ev)
}
case []interface{}:

View File

@ -193,7 +193,7 @@ func Test_values(t *testing.T) {
},
ValueFrom: mustCompilePath(t, "creationTimestamp"),
}, wantResult: []eachValue{
newEachValue(t, 1.6563744e+09),
newEachValue(t, 1.6563744e+09, "name", "foo"),
}},
{name: "non-existent path", each: &compiledGauge{
compiledCommon: compiledCommon{