diff options
| author | Paul Buetow <paul@buetow.org> | 2021-10-14 20:10:55 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-10-14 20:11:23 +0300 |
| commit | 06ece112c0dd20c0c211c538216fe64ebe4045c9 (patch) | |
| tree | 98f290d8642b59087a03938b04052e056912b44d /internal | |
| parent | 6075b52103c7d42a7c4dc91bde9e64b2f92281de (diff) | |
add dgrep context integration tests
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/io/fs/readfile.go | 23 | ||||
| -rw-r--r-- | internal/server/handlers/basehandler.go | 2 |
2 files changed, 17 insertions, 8 deletions
diff --git a/internal/io/fs/readfile.go b/internal/io/fs/readfile.go index 88d467e..28cbe58 100644 --- a/internal/io/fs/readfile.go +++ b/internal/io/fs/readfile.go @@ -99,15 +99,24 @@ func (f readFile) Start(ctx context.Context, ltx lcontext.LContext, rawLines := make(chan *bytes.Buffer, 100) truncate := make(chan struct{}) - var wg sync.WaitGroup - wg.Add(1) + readCtx, readCancel := context.WithCancel(ctx) + var filterWg sync.WaitGroup + filterWg.Add(1) go f.periodicTruncateCheck(ctx, truncate) - go f.filter(ctx, ltx, &wg, rawLines, lines, re) + go func() { + f.filter(ctx, ltx, rawLines, lines, re) + filterWg.Done() + // If the filter stopped, make the reader stop too, no need to read + // more data if there is nothing more the filter wants to filter for! + // E.g. it could be that we only want to filter N matches but not more. + readCancel() + }() - err = f.read(ctx, fd, rawLines, truncate) + err = f.read(readCtx, fd, rawLines, truncate) close(rawLines) - wg.Wait() + // Filter may sends some data still. So wait until it is done here. + filterWg.Wait() return err } @@ -215,10 +224,8 @@ func (f readFile) read(ctx context.Context, fd *os.File, rawLines chan *bytes.Bu // Filter log lines matching a given regular expression. func (f readFile) filter(ctx context.Context, ltx lcontext.LContext, - wg *sync.WaitGroup, rawLines <-chan *bytes.Buffer, lines chan<- line.Line, - re regex.Regex) { + rawLines <-chan *bytes.Buffer, lines chan<- line.Line, re regex.Regex) { - defer wg.Done() // Do we have any kind of local context settings? If so then run the more complex // filterWithLContext method. if ltx.Has() { diff --git a/internal/server/handlers/basehandler.go b/internal/server/handlers/basehandler.go index c25f85a..934f2bc 100644 --- a/internal/server/handlers/basehandler.go +++ b/internal/server/handlers/basehandler.go @@ -159,6 +159,8 @@ func (h *baseHandler) handleCommand(commandStr string) { cancel() }() + dlog.Server.Trace(args) + dlog.Server.Trace(args[0]) splitted := strings.Split(args[0], ":") commandName := splitted[0] options, ltx, err := config.DeserializeOptions(splitted[1:]) |
