diff --git a/api/models/series.go b/api/models/series.go index 40c6a6795..562ab1599 100644 --- a/api/models/series.go +++ b/api/models/series.go @@ -291,7 +291,7 @@ func (series SeriesByTarget) MarshalJSONFast(b []byte) ([]byte, error) { b = append(b, `,"datapoints":[`...) for _, p := range s.Datapoints { b = append(b, '[') - if math.IsNaN(p.Val) { + if math.IsNaN(p.Val) || math.IsInf(p.Val, 0) { b = append(b, `null,`...) } else { b = strconv.AppendFloat(b, p.Val, 'f', -1, 64) @@ -330,7 +330,7 @@ func (series SeriesByTarget) MarshalJSONFastWithMeta(b []byte) ([]byte, error) { b = append(b, `,"datapoints":[`...) for _, p := range s.Datapoints { b = append(b, '[') - if math.IsNaN(p.Val) { + if math.IsNaN(p.Val) || math.IsInf(p.Val, 0) { b = append(b, `null,`...) } else { b = strconv.AppendFloat(b, p.Val, 'f', -1, 64) diff --git a/api/models/series_test.go b/api/models/series_test.go index b84ab6c34..81a49445b 100644 --- a/api/models/series_test.go +++ b/api/models/series_test.go @@ -38,6 +38,18 @@ func TestJsonMarshal(t *testing.T) { }, out: `[{"target":"a\\b","datapoints":[]}]`, }, + { + in: []Series{ + { + Target: `a`, + Datapoints: []schema.Point{ + {Val: math.Inf(1), Ts: 60}, + }, + Interval: 60, + }, + }, + out: `[{"target":"a","datapoints":[[null,60]]}]`, + }, { in: []Series{ {