Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Allow labelFromKey field
Browse files Browse the repository at this point in the history
  • Loading branch information
rexagod committed Nov 9, 2022
1 parent b9f0d8d commit 3072502
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (c *compiledGauge) Values(v interface{}) (result []eachValue, errs []error)
onError(fmt.Errorf("[%s]: %w", key, err))
continue
}
if _, ok := ev.Labels[c.labelFromKey]; ok {
onError(fmt.Errorf("labelFromKey (%s) generated labels conflict with labelsFromPath, consider renaming it", c.labelFromKey))
continue
}
if key != "" && c.labelFromKey != "" {
ev.Labels[c.labelFromKey] = key
}
Expand Down Expand Up @@ -285,9 +289,7 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error)
})
}
}
if len(result) == 0 {
result = value
}
result = append(result, value...)
default:
result, errs = c.values(v)
}
Expand All @@ -301,7 +303,9 @@ func (c *compiledInfo) values(v interface{}) (result []eachValue, err []error) {
}
value := eachValue{Value: 1, Labels: map[string]string{}}
addPathLabels(v, c.labelFromPath, value.Labels)
result = append(result, value)
if len(value.Labels) != 0 {
result = append(result, value)
}
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/customresourcestate/registry_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func Test_values(t *testing.T) {
labelFromKey: "type",
}, wantResult: []eachValue{
newEachValue(t, 1, "type", "type-a"),
newEachValue(t, 3, "type", "type-b"),
newEachValue(t, 1, "type", "type-b"),
}},
{name: "stateset", each: &compiledStateSet{
compiledCommon: compiledCommon{
Expand Down

0 comments on commit 3072502

Please sign in to comment.