Skip to content

Commit

Permalink
Do not expose info metric for nil objects
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 19, 2022
1 parent 3532203 commit 25f3b8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error)
}

func (c *compiledInfo) values(v interface{}) (result []eachValue, err []error) {
if v == nil {
return
}
value := eachValue{Value: 1, Labels: map[string]string{}}
addPathLabels(v, c.labelFromPath, value.Labels)
result = append(result, value)
Expand Down
5 changes: 5 additions & 0 deletions pkg/customresourcestate/registry_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func Test_values(t *testing.T) {
}, wantResult: []eachValue{
newEachValue(t, 1, "version", "v0.0.0"),
}},
{name: "info nil path", each: &compiledInfo{
compiledCommon{
path: mustCompilePath(t, "does", "not", "exist"),
},
}, wantResult: nil},
{name: "stateset", each: &compiledStateSet{
compiledCommon: compiledCommon{
path: mustCompilePath(t, "status", "phase"),
Expand Down

0 comments on commit 25f3b8f

Please sign in to comment.