Skip to content

Commit

Permalink
Fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Jun 13, 2021
1 parent 272abec commit ab30c69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ab30c69

Please sign in to comment.