Better rounding for incoming query timestamps (#4941)
Fixes https://github.com/prometheus/prometheus/issues/4939 Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
d28246e337
commit
11a52be1d8
|
@ -1150,6 +1150,7 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter
|
||||||
func parseTime(s string) (time.Time, error) {
|
func parseTime(s string) (time.Time, error) {
|
||||||
if t, err := strconv.ParseFloat(s, 64); err == nil {
|
if t, err := strconv.ParseFloat(s, 64); err == nil {
|
||||||
s, ns := math.Modf(t)
|
s, ns := math.Modf(t)
|
||||||
|
ns = math.Round(ns*1000) / 1000
|
||||||
return time.Unix(int64(s), int64(ns*float64(time.Second))), nil
|
return time.Unix(int64(s), int64(ns*float64(time.Second))), nil
|
||||||
}
|
}
|
||||||
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
|
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
|
||||||
|
|
|
@ -1318,6 +1318,10 @@ func TestParseTime(t *testing.T) {
|
||||||
}, {
|
}, {
|
||||||
input: "2015-06-03T14:21:58.555+01:00",
|
input: "2015-06-03T14:21:58.555+01:00",
|
||||||
result: ts,
|
result: ts,
|
||||||
|
}, {
|
||||||
|
// Test float rounding.
|
||||||
|
input: "1543578564.705",
|
||||||
|
result: time.Unix(1543578564, 705*1e6),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue