Skip to content

Commit 32f8c5e

Browse files
authored
Merge pull request kubernetes#2048 from murphd40/2047
2047: Add LabelsFromPath functionality to Info metrics
2 parents b3157f7 + d16935b commit 32f8c5e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,25 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error)
325325
continue
326326
}
327327
}
328-
// labelFromKey logic
329-
for key := range iter {
328+
329+
// labelFromKey / labelFromPath logic
330+
for key, it := range iter {
331+
labels := make(map[string]string)
332+
330333
if key != "" && c.labelFromKey != "" {
334+
labels[c.labelFromKey] = key
335+
}
336+
337+
addPathLabels(it, c.LabelFromPath(), labels)
338+
339+
if len(labels) > 0 {
331340
result = append(result, eachValue{
332-
Labels: map[string]string{
333-
c.labelFromKey: key,
334-
},
335-
Value: 1,
341+
Labels: labels,
342+
Value: 1,
336343
})
337344
}
338345
}
346+
339347
result = append(result, value...)
340348
default:
341349
result, errs = c.values(v)

pkg/customresourcestate/registry_factory_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,17 @@ func Test_values(t *testing.T) {
292292
newEachValue(t, 1, "type", "type-a"),
293293
newEachValue(t, 1, "type", "type-b"),
294294
}},
295+
{name: "info label from path", each: &compiledInfo{
296+
compiledCommon: compiledCommon{
297+
path: mustCompilePath(t, "status", "sub"),
298+
labelFromPath: map[string]valuePath{
299+
"active": mustCompilePath(t, "active"),
300+
},
301+
},
302+
}, wantResult: []eachValue{
303+
newEachValue(t, 1, "active", "1"),
304+
newEachValue(t, 1, "active", "3"),
305+
}},
295306
{name: "stateset", each: &compiledStateSet{
296307
compiledCommon: compiledCommon{
297308
path: mustCompilePath(t, "status", "phase"),

0 commit comments

Comments
 (0)