diff --git a/src/query/api/v1/handler/prometheus/native/common.go b/src/query/api/v1/handler/prometheus/native/common.go index e2ab134f10..29d0b1e5ff 100644 --- a/src/query/api/v1/handler/prometheus/native/common.go +++ b/src/query/api/v1/handler/prometheus/native/common.go @@ -173,8 +173,8 @@ func renderResultsJSON(w io.Writer, series []*ts.Series, params models.RequestPa } jw.BeginArray() - jw.WriteFloat64(dp.Value) jw.WriteInt(int(dp.Timestamp.Unix())) + jw.WriteString(valueToProm(dp.Value)) jw.EndArray() } jw.EndArray() @@ -190,3 +190,7 @@ func renderResultsJSON(w io.Writer, series []*ts.Series, params models.RequestPa jw.EndArray() jw.Close() } + +func valueToProm(value float64) string { + return strconv.FormatFloat(value, 'f', -1, 64) +} diff --git a/src/query/api/v1/handler/prometheus/native/common_test.go b/src/query/api/v1/handler/prometheus/native/common_test.go index 6465a7938d..2b6fd28176 100644 --- a/src/query/api/v1/handler/prometheus/native/common_test.go +++ b/src/query/api/v1/handler/prometheus/native/common_test.go @@ -21,6 +21,7 @@ package native import ( + "math" "net/http" "net/url" "testing" @@ -74,3 +75,10 @@ func TestInvalidTarget(t *testing.T) { assert.NotNil(t, p.Start) require.Equal(t, err.Code(), http.StatusBadRequest) } + +func TestValueToProm(t *testing.T) { + assert.Equal(t, valueToProm(1.0), "1") + assert.Equal(t, valueToProm(1.2), "1.2") + assert.Equal(t, valueToProm(math.NaN()), "NaN") + assert.Equal(t, valueToProm(0.0119311), "0.0119311") +}