From 96223322ba0dd4803c7f500029b0817d26f62d49 Mon Sep 17 00:00:00 2001 From: Tom Wilkie <tom.wilkie@gmail.com> Date: Tue, 3 Jul 2018 12:01:58 +0100 Subject: [PATCH] Make queries take nanoseconds since epoch. Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com> --- README.md | 4 ++-- pkg/querier/http.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f9b4de05..4ccfc67d 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,8 @@ There are 4 API endpoints: For doing queries, accepts the following paramters in the query-string: - `query`: a logQL query - `limit`: max number of entries to return - - `start`: the start time for the query, as a Unix epoch (seconds since 1970) - - `end`: the end time for the query, as a Unix epoch (seconds since 1970) + - `start`: the start time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) + - `end`: the end time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) - `direction`: `forward` or `backward`, useful when specifying a limit - `regexp`: a regex to filter the returned results, will eventually be rolled into the query language diff --git a/pkg/querier/http.go b/pkg/querier/http.go index d7d8d84e..9981a106 100644 --- a/pkg/querier/http.go +++ b/pkg/querier/http.go @@ -28,18 +28,18 @@ func intParam(values url.Values, name string, def int) (int, error) { return strconv.Atoi(value) } -func unixTimeParam(values url.Values, name string, def time.Time) (time.Time, error) { +func unixNanoTimeParam(values url.Values, name string, def time.Time) (time.Time, error) { value := values.Get(name) if value == "" { return def, nil } - secs, err := strconv.ParseInt(value, 10, 64) + nanos, err := strconv.ParseInt(value, 10, 64) if err != nil { return time.Time{}, err } - return time.Unix(secs, 0), nil + return time.Unix(0, nanos), nil } func directionParam(values url.Values, name string, def logproto.Direction) (logproto.Direction, error) { @@ -65,13 +65,13 @@ func (q *Querier) QueryHandler(w http.ResponseWriter, r *http.Request) { } now := time.Now() - start, err := unixTimeParam(params, "start", now.Add(-defaulSince)) + start, err := unixNanoTimeParam(params, "start", now.Add(-defaulSince)) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } - end, err := unixTimeParam(params, "end", now) + end, err := unixNanoTimeParam(params, "end", now) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return -- GitLab