Skip to content

Commit

Permalink
Better rounding for incoming query timestamps.
Browse files Browse the repository at this point in the history
Signed-off-by: johncming <[email protected]>
  • Loading branch information
johncming committed Aug 4, 2020
1 parent 040b69b commit 405cbb8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ func (qapi *QueryAPI) series(r *http.Request) (interface{}, []error, *api.ApiErr
func parseTime(s string) (time.Time, error) {
if t, err := strconv.ParseFloat(s, 64); err == nil {
s, ns := math.Modf(t)
ns = math.Round(ns*1000) / 1000
return time.Unix(int64(s), int64(ns*float64(time.Second))), nil
}
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ func TestParseTime(t *testing.T) {
}, {
input: "2015-06-03T14:21:58.555+01:00",
result: ts,
},{
// Test float rounding.
input: "1543578564.705",
result: time.Unix(1543578564, 705*1e6),
},
}

Expand Down

0 comments on commit 405cbb8

Please sign in to comment.