From d43de72f3baaf0f10454f8cf2396897f36825db6 Mon Sep 17 00:00:00 2001 From: sh0rez Date: Mon, 15 Jul 2019 14:26:50 +0200 Subject: [PATCH] feat(logcli): query from absolute timestamp (#736) * feat(logcli): query from absolute timestamp Adds a new flag (`--from`) as to complement `--since`. While since subtracts a relative duration from the current time, from allows to specify the absolute start of the lookback window. Note: `--from` takes precedence over `--since`, but only if set. * fix(logcli): use RFC3339Nano for -from To comply with Prometheus, this flag now honors Nanoseconds as well (was using RFC3339 so far) --- cmd/logcli/main.go | 1 + cmd/logcli/query.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/cmd/logcli/main.go b/cmd/logcli/main.go index 6350964a2efb7..0022caa2499fe 100644 --- a/cmd/logcli/main.go +++ b/cmd/logcli/main.go @@ -24,6 +24,7 @@ var ( regexpStr = queryCmd.Arg("regex", "").String() limit = queryCmd.Flag("limit", "Limit on number of entries to print.").Default("30").Int() since = queryCmd.Flag("since", "Lookback window.").Default("1h").Duration() + from = queryCmd.Flag("from", "Start looking for logs at this absolute time").String() forward = queryCmd.Flag("forward", "Scan forwards through logs.").Default("false").Bool() tail = queryCmd.Flag("tail", "Tail the logs").Short('t').Default("false").Bool() delayFor = queryCmd.Flag("delay-for", "Delay in tailing by number of seconds to accumulate logs").Default("0").Int() diff --git a/cmd/logcli/query.go b/cmd/logcli/query.go index f5b5716279477..da1f57de626d4 100644 --- a/cmd/logcli/query.go +++ b/cmd/logcli/query.go @@ -25,6 +25,14 @@ func doQuery() { end := time.Now() start := end.Add(-*since) + if *from != "" { + var err error + start, err = time.Parse(time.RFC3339Nano, *from) + if err != nil { + log.Fatalf("error parsing date '%s': %s", *from, err) + } + } + d := logproto.BACKWARD if *forward { d = logproto.FORWARD