Skip to content

Commit f1d5653

Browse files
authored
Merge pull request #1809 from chrischdi/pr-info-nometric-nil
Do not expose info metric for nil objects
2 parents 3532203 + 25f3b8f commit f1d5653

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error)
269269
}
270270

271271
func (c *compiledInfo) values(v interface{}) (result []eachValue, err []error) {
272+
if v == nil {
273+
return
274+
}
272275
value := eachValue{Value: 1, Labels: map[string]string{}}
273276
addPathLabels(v, c.labelFromPath, value.Labels)
274277
result = append(result, value)

pkg/customresourcestate/registry_factory_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ func Test_values(t *testing.T) {
209209
}, wantResult: []eachValue{
210210
newEachValue(t, 1, "version", "v0.0.0"),
211211
}},
212+
{name: "info nil path", each: &compiledInfo{
213+
compiledCommon{
214+
path: mustCompilePath(t, "does", "not", "exist"),
215+
},
216+
}, wantResult: nil},
212217
{name: "stateset", each: &compiledStateSet{
213218
compiledCommon: compiledCommon{
214219
path: mustCompilePath(t, "status", "phase"),

0 commit comments

Comments
 (0)