From f6e49ace3177d7c052b1ba2250ba1bc23b63e389 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Fri, 7 Jun 2019 15:33:26 -0400 Subject: [PATCH] add support for RFC3339Nano in query timestamps --- docs/api.md | 4 ++-- pkg/querier/http.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index db618291b9318..14b9b40ffcc1c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -28,8 +28,8 @@ The Loki server has the following API endpoints (_Note:_ Authentication is out o - `query`: a logQL query - `limit`: max number of entries to return - - `start`: the start time for the query, as a nanosecond Unix epoch (nanoseconds since 1970). Default is always one hour ago. - - `end`: the end time for the query, as a nanosecond Unix epoch (nanoseconds since 1970). Default is current time. + - `start`: the start time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) or as RFC3339Nano (eg: "2006-01-02T15:04:05.999999999Z07:00"). Default is always one hour ago. + - `end`: the end time for the query, as a nanosecond Unix epoch (nanoseconds since 1970) or as RFC3339Nano (eg: "2006-01-02T15:04:05.999999999Z07:00"). Default is current time. - `direction`: `forward` or `backward`, useful when specifying a limit. Default is backward. - `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 3161ff6f619d2..b98a9e918776a 100644 --- a/pkg/querier/http.go +++ b/pkg/querier/http.go @@ -48,6 +48,9 @@ func unixNanoTimeParam(values url.Values, name string, def time.Time) (time.Time nanos, err := strconv.ParseInt(value, 10, 64) if err != nil { + if ts, err := time.Parse(time.RFC3339Nano, value); err == nil { + return ts, nil + } return time.Time{}, err }