Skip to content

Commit

Permalink
feat(logcli): query from absolute timestamp (#736)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
sh0rez authored and cyriltovena committed Jul 15, 2019
1 parent a2ceb8d commit d43de72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/logcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions cmd/logcli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d43de72

Please sign in to comment.