diff --git a/set.go b/set.go index ed744fa..f0d6e4a 100644 --- a/set.go +++ b/set.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "math" "strconv" "strings" @@ -74,6 +75,8 @@ func (r *QueryResult) createMetric(facets map[string]interface{}, suffix string) func setValueForResult(r prometheus.Gauge, v interface{}) error { switch t := v.(type) { + case nil: + r.Set(math.NaN()) case string: f, err := strconv.ParseFloat(t, 64) if err != nil { diff --git a/set_test.go b/set_test.go index 9d07517..2d874de 100644 --- a/set_test.go +++ b/set_test.go @@ -144,3 +144,22 @@ func (opts *testQuerySetOptions) testQuerySet(t *testing.T) { } } + +func TestNilValue(t *testing.T) { + (&testQuerySetOptions{ + q: NewQueryResult(&Query{ + Name: "nil_metric", + }), + rec: records{ + record{ + "value": nil, + }, + }, + results: map[string]string{ + "nil_metric{}": `gauge: < + value: nan +> +`, + }, + }).testQuerySet(t) +}