Do not expose info metric for nil objects

This commit is contained in:
Christian Schlotter 2022-08-19 13:25:30 +02:00
parent 3532203e8f
commit 25f3b8f45a
No known key found for this signature in database
GPG Key ID: 0E487122453EB0AC
2 changed files with 8 additions and 0 deletions

View File

@ -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)

View File

@ -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"),