From 0e3eb25760af63b3dd47654f7a479e00c5a130c8 Mon Sep 17 00:00:00 2001 From: Nikunj Aggarwal Date: Tue, 28 Aug 2018 11:23:13 -0400 Subject: [PATCH 1/4] Return value as string to match prom output --- src/query/api/v1/handler/prometheus/native/common.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/query/api/v1/handler/prometheus/native/common.go b/src/query/api/v1/handler/prometheus/native/common.go index 9585ce738f..4b1e388023 100644 --- a/src/query/api/v1/handler/prometheus/native/common.go +++ b/src/query/api/v1/handler/prometheus/native/common.go @@ -173,7 +173,7 @@ func renderResultsJSON(w io.Writer, series []*ts.Series, params models.RequestPa } jw.BeginArray() - jw.WriteFloat64(dp.Value) + jw.WriteString(valueToProm(dp.Value)) jw.WriteInt(int(dp.Timestamp.Unix())) 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) +} From 6a5d94225f9e4c1b52f4f7d7d7e64cc74320caf9 Mon Sep 17 00:00:00 2001 From: Nikunj Aggarwal Date: Tue, 28 Aug 2018 11:25:05 -0400 Subject: [PATCH 2/4] Fix point order --- src/query/api/v1/handler/prometheus/native/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/api/v1/handler/prometheus/native/common.go b/src/query/api/v1/handler/prometheus/native/common.go index 4b1e388023..121b640677 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.WriteString(valueToProm(dp.Value)) jw.WriteInt(int(dp.Timestamp.Unix())) + jw.WriteString(valueToProm(dp.Value)) jw.EndArray() } jw.EndArray() From 72da21f8f4400349a81a53c45ec5b8dfd42c2f74 Mon Sep 17 00:00:00 2001 From: Nikunj Aggarwal Date: Wed, 29 Aug 2018 14:09:31 -0400 Subject: [PATCH 3/4] Rebase , comments --- src/query/api/v1/handler/prometheus/native/common_test.go | 7 +++++++ 1 file changed, 7 insertions(+) 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..7f7595bc0d 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,9 @@ 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") +} From fb5d2d5400f53392b8e415fe6501e2766a84d044 Mon Sep 17 00:00:00 2001 From: Nikunj Aggarwal Date: Thu, 30 Aug 2018 12:23:39 -0400 Subject: [PATCH 4/4] More asserts --- src/query/api/v1/handler/prometheus/native/common_test.go | 1 + 1 file changed, 1 insertion(+) 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 7f7595bc0d..2b6fd28176 100644 --- a/src/query/api/v1/handler/prometheus/native/common_test.go +++ b/src/query/api/v1/handler/prometheus/native/common_test.go @@ -80,4 +80,5 @@ 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") }