Browse Source

filer.meta.tail: support untilTimeAgo for a range

pull/3122/head
chrislu 3 years ago
parent
commit
968ca95b49
  1. 8
      weed/command/filer_meta_tail.go
  2. 4
      weed/util/log_buffer/log_read.go

8
weed/command/filer_meta_tail.go

@ -36,6 +36,7 @@ var (
tailFiler = cmdFilerMetaTail.Flag.String("filer", "localhost:8888", "filer hostname:port")
tailTarget = cmdFilerMetaTail.Flag.String("pathPrefix", "/", "path to a folder or common prefix for the folders or files on filer")
tailStart = cmdFilerMetaTail.Flag.Duration("timeAgo", 0, "start time before now. \"300ms\", \"1.5h\" or \"2h45m\". Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"")
tailStop = cmdFilerMetaTail.Flag.Duration("untilTimeAgo", 0, "read until this time ago. \"300ms\", \"1.5h\" or \"2h45m\". Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"")
tailPattern = cmdFilerMetaTail.Flag.String("pattern", "", "full path or just filename pattern, ex: \"/home/?opher\", \"*.pdf\", see https://golang.org/pkg/path/filepath/#Match ")
esServers = cmdFilerMetaTail.Flag.String("es", "", "comma-separated elastic servers http://<host:port>")
esIndex = cmdFilerMetaTail.Flag.String("es.index", "seaweedfs", "ES index name")
@ -103,8 +104,13 @@ func runFilerMetaTail(cmd *Command, args []string) bool {
}
}
var untilTsNs int64
if *tailStop != 0 {
untilTsNs = time.Now().Add(-*tailStop).UnixNano()
}
tailErr := pb.FollowMetadata(pb.ServerAddress(*tailFiler), grpcDialOption, "tail", clientId, *tailTarget, nil,
time.Now().Add(-*tailStart).UnixNano(), 0, 0, func(resp *filer_pb.SubscribeMetadataResponse) error {
time.Now().Add(-*tailStart).UnixNano(), untilTsNs, 0, func(resp *filer_pb.SubscribeMetadataResponse) error {
if !shouldPrint(resp) {
return nil
}

4
weed/util/log_buffer/log_read.go

@ -40,6 +40,10 @@ func (logBuffer *LogBuffer) LoopProcessLogData(readerName string, startReadTime
}
// glog.V(4).Infof("%s ReadFromBuffer by %v", readerName, lastReadTime)
if bytesBuf == nil {
if stopTsNs != 0 {
isDone = true
return
}
if waitForDataFn() {
continue
} else {

Loading…
Cancel
Save