Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datatype to match prom output #871

Merged
merged 4 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/query/api/v1/handler/prometheus/native/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
8 changes: 8 additions & 0 deletions src/query/api/v1/handler/prometheus/native/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package native

import (
"math"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -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")
}