From: Tom Clegg Date: Tue, 4 Apr 2023 14:59:41 +0000 (-0400) Subject: 18790: Prefix each line with source filename. X-Git-Tag: 2.7.0~121^2~15 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/fc6b3cd79ba9e07810330d0d47a0ab89ad8857f7 18790: Prefix each line with source filename. Re-check container state right away if crunch-run.txt logs a final state like "Completed". Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/cmd/arvados-client/container_gateway.go b/cmd/arvados-client/container_gateway.go index 7a35190427..f23252169f 100644 --- a/cmd/arvados-client/container_gateway.go +++ b/cmd/arvados-client/container_gateway.go @@ -111,17 +111,18 @@ poll: continue poll } } - anyNewData := false + newData := map[string]*bytes.Buffer{} for _, fnm := range watching { if size[fnm] > mark[fnm] { - anyNewData = true - _, n, err := lc.copyRange(ctx, ctrUUID, fnm, fmt.Sprintf("%d-", mark[fnm]), stdout) + newData[fnm] = &bytes.Buffer{} + _, n, err := lc.copyRange(ctx, ctrUUID, fnm, fmt.Sprintf("%d-", mark[fnm]), newData[fnm]) if err != nil { fmt.Fprintln(stderr, err) } mark[fnm] += n } } + checkState := lc.display(stdout, stderr, watching, newData) if containerFinished { // If the caller specified a container request // UUID and the container we were watching has @@ -143,9 +144,12 @@ poll: ctrUUID = newUUID containerFinished = false delay = 0 - } else if anyNewData { + continue + } + if len(newData) > 0 { delay = pollInterval - } else { + } + if len(newData) == 0 || checkState { delay = delay * 2 if delay > pollInterval*5 { delay = pollInterval * 5 @@ -210,6 +214,33 @@ func (lc *logsCommand) copyRange(ctx context.Context, uuid, fnm, byterange strin return rsize, n, err } +// display some log data, formatted as desired (prefixing each line +// with a tag indicating which file it came from, etc.). +// +// Return value is true if the log data contained a hint that it's a +// good time to check whether the container is finished so we can +// exit. +func (lc *logsCommand) display(out, stderr io.Writer, watching []string, received map[string]*bytes.Buffer) bool { + checkState := false + for _, fnm := range watching { + buf := received[fnm] + if buf == nil || buf.Len() == 0 { + continue + } + for _, line := range bytes.Split(bytes.TrimSuffix(buf.Bytes(), []byte{'\n'}), []byte{'\n'}) { + _, err := fmt.Fprintf(out, "%-14s %s\n", fnm, line) + if err != nil { + fmt.Fprintln(stderr, err) + } + checkState = checkState || + bytes.HasSuffix(line, []byte("Complete")) || + bytes.HasSuffix(line, []byte("Cancelled")) || + bytes.HasSuffix(line, []byte("Queued")) + } + } + return checkState +} + // shellCommand connects the terminal to an interactive shell on a // running container. type shellCommand struct{} diff --git a/cmd/arvados-client/container_gateway_test.go b/cmd/arvados-client/container_gateway_test.go index 0e5aad709e..fbab499002 100644 --- a/cmd/arvados-client/container_gateway_test.go +++ b/cmd/arvados-client/container_gateway_test.go @@ -277,7 +277,7 @@ func (s *ClientSuite) TestContainerLog(c *check.C) { for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline) && !strings.Contains(stdout.String(), "--end--"); time.Sleep(time.Second / 10) { } - c.Check(stdout.String(), check.Matches, `(?ms).*--end--\n.*`) + c.Check(stdout.String(), check.Matches, `(?ms).*stderr\.txt +--end--\n.*`) mtxt, err := cfs.MarshalManifest(".") c.Assert(err, check.IsNil)