Skip to content

Commit

Permalink
Merge pull request kubernetes#2048 from murphd40/2047
Browse files Browse the repository at this point in the history
2047: Add LabelsFromPath functionality to Info metrics
  • Loading branch information
k8s-ci-robot authored Apr 26, 2023
2 parents b3157f7 + d16935b commit 32f8c5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,25 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error)
continue
}
}
// labelFromKey logic
for key := range iter {

// labelFromKey / labelFromPath logic
for key, it := range iter {
labels := make(map[string]string)

if key != "" && c.labelFromKey != "" {
labels[c.labelFromKey] = key
}

addPathLabels(it, c.LabelFromPath(), labels)

if len(labels) > 0 {
result = append(result, eachValue{
Labels: map[string]string{
c.labelFromKey: key,
},
Value: 1,
Labels: labels,
Value: 1,
})
}
}

result = append(result, value...)
default:
result, errs = c.values(v)
Expand Down
11 changes: 11 additions & 0 deletions pkg/customresourcestate/registry_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ func Test_values(t *testing.T) {
newEachValue(t, 1, "type", "type-a"),
newEachValue(t, 1, "type", "type-b"),
}},
{name: "info label from path", each: &compiledInfo{
compiledCommon: compiledCommon{
path: mustCompilePath(t, "status", "sub"),
labelFromPath: map[string]valuePath{
"active": mustCompilePath(t, "active"),
},
},
}, wantResult: []eachValue{
newEachValue(t, 1, "active", "1"),
newEachValue(t, 1, "active", "3"),
}},
{name: "stateset", each: &compiledStateSet{
compiledCommon: compiledCommon{
path: mustCompilePath(t, "status", "phase"),
Expand Down

0 comments on commit 32f8c5e

Please sign in to comment.