Skip to content

Commit 52dcb11

Browse files
committed
Fixes #10
1 parent 272abec commit 52dcb11

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

set.go

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"math"
78
"strconv"
89
"strings"
910

@@ -74,6 +75,8 @@ func (r *QueryResult) createMetric(facets map[string]interface{}, suffix string)
7475

7576
func setValueForResult(r prometheus.Gauge, v interface{}) error {
7677
switch t := v.(type) {
78+
case nil:
79+
r.Set(math.NaN())
7780
case string:
7881
f, err := strconv.ParseFloat(t, 64)
7982
if err != nil {

set_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,22 @@ func (opts *testQuerySetOptions) testQuerySet(t *testing.T) {
144144
}
145145

146146
}
147+
148+
func TestNilValue(t *testing.T) {
149+
(&testQuerySetOptions{
150+
q: NewQueryResult(&Query{
151+
Name: "nil_metric",
152+
}),
153+
rec: records{
154+
record{
155+
"value": nil,
156+
},
157+
},
158+
results: map[string]string{
159+
"nil_metric{}": `gauge: <
160+
value: nan
161+
>
162+
`,
163+
},
164+
}).testQuerySet(t)
165+
}

0 commit comments

Comments
 (0)