Skip to content

Commit 3072502

Browse files
committed
fixup! fixup! fixup! fixup! Allow labelFromKey field
1 parent b9f0d8d commit 3072502

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func (c *compiledGauge) Values(v interface{}) (result []eachValue, errs []error)
214214
onError(fmt.Errorf("[%s]: %w", key, err))
215215
continue
216216
}
217+
if _, ok := ev.Labels[c.labelFromKey]; ok {
218+
onError(fmt.Errorf("labelFromKey (%s) generated labels conflict with labelsFromPath, consider renaming it", c.labelFromKey))
219+
continue
220+
}
217221
if key != "" && c.labelFromKey != "" {
218222
ev.Labels[c.labelFromKey] = key
219223
}
@@ -285,9 +289,7 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error)
285289
})
286290
}
287291
}
288-
if len(result) == 0 {
289-
result = value
290-
}
292+
result = append(result, value...)
291293
default:
292294
result, errs = c.values(v)
293295
}
@@ -301,7 +303,9 @@ func (c *compiledInfo) values(v interface{}) (result []eachValue, err []error) {
301303
}
302304
value := eachValue{Value: 1, Labels: map[string]string{}}
303305
addPathLabels(v, c.labelFromPath, value.Labels)
304-
result = append(result, value)
306+
if len(value.Labels) != 0 {
307+
result = append(result, value)
308+
}
305309
return
306310
}
307311

pkg/customresourcestate/registry_factory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func Test_values(t *testing.T) {
221221
labelFromKey: "type",
222222
}, wantResult: []eachValue{
223223
newEachValue(t, 1, "type", "type-a"),
224-
newEachValue(t, 3, "type", "type-b"),
224+
newEachValue(t, 1, "type", "type-b"),
225225
}},
226226
{name: "stateset", each: &compiledStateSet{
227227
compiledCommon: compiledCommon{

0 commit comments

Comments
 (0)