[arvados] updated: 2.6.0-93-g680a7bbd7
git repository hosting
git at public.arvados.org
Fri Apr 28 15:29:50 UTC 2023
Summary of changes:
cmd/arvados-client/container_gateway.go | 13 +++++++------
cmd/arvados-client/container_gateway_test.go | 16 ++++++++++++++--
lib/cmd/parseflags.go | 12 +++++++++++-
3 files changed, 32 insertions(+), 9 deletions(-)
via 680a7bbd73fa20861ab4213b36947b835304532d (commit)
via 2f117c412dc990a81ff5fa40ecb38be6a506bd38 (commit)
from e7cb79569f8047de64ccec7ec4382bf0f4b7423d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 680a7bbd73fa20861ab4213b36947b835304532d
Author: Tom Clegg <tom at curii.com>
Date: Fri Apr 28 11:29:01 2023 -0400
18790: Enable follow mode with -f flag.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/cmd/arvados-client/container_gateway.go b/cmd/arvados-client/container_gateway.go
index 94375075c..7b52cc3a6 100644
--- a/cmd/arvados-client/container_gateway.go
+++ b/cmd/arvados-client/container_gateway.go
@@ -33,6 +33,7 @@ type logsCommand struct {
func (lc logsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
f := flag.NewFlagSet(prog, flag.ContinueOnError)
+ follow := f.Bool("f", false, "follow: poll for new data until the container finishes")
pollInterval := f.Duration("poll", time.Second*2, "minimum duration to wait before polling for new data")
if ok, code := cmd.ParseFlags(f, prog, args, "container-request-uuid", stderr); !ok {
return code
@@ -53,7 +54,7 @@ func (lc logsCommand) RunCommand(prog string, args []string, stdin io.Reader, st
InsecureSkipVerify: true}}
}
- err := lc.tailf(target, stdout, stderr, *pollInterval)
+ err := lc.tail(target, stdout, stderr, *follow, *pollInterval)
if err != nil {
fmt.Fprintln(stderr, err)
return 1
@@ -61,7 +62,7 @@ func (lc logsCommand) RunCommand(prog string, args []string, stdin io.Reader, st
return 0
}
-func (lc *logsCommand) tailf(crUUID string, stdout, stderr io.Writer, pollInterval time.Duration) error {
+func (lc *logsCommand) tail(crUUID string, stdout, stderr io.Writer, follow bool, pollInterval time.Duration) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -157,7 +158,7 @@ poll:
displayingUUID = cr.ContainerUUID
delay = 0
continue
- } else if cr.State == arvados.ContainerRequestStateFinal {
+ } else if cr.State == arvados.ContainerRequestStateFinal || !follow {
break
} else if len(newData) > 0 {
delay = pollInterval
diff --git a/cmd/arvados-client/container_gateway_test.go b/cmd/arvados-client/container_gateway_test.go
index 25c794e83..761a7c3ef 100644
--- a/cmd/arvados-client/container_gateway_test.go
+++ b/cmd/arvados-client/container_gateway_test.go
@@ -230,7 +230,7 @@ func (s *ClientSuite) TestContainerRequestLog(c *check.C) {
c.Log("running logs command on queued container")
var stdout, stderr bytes.Buffer
- cmd := exec.CommandContext(ctx, "go", "run", ".", "logs", "-poll=250ms", cr.UUID)
+ cmd := exec.CommandContext(ctx, "go", "run", ".", "logs", "-f", "-poll=250ms", cr.UUID)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "ARVADOS_API_TOKEN="+arvadostest.SystemRootToken)
cmd.Stdout = io.MultiWriter(&stdout, os.Stderr)
@@ -270,6 +270,18 @@ func (s *ClientSuite) TestContainerRequestLog(c *check.C) {
c.Assert(err, check.IsNil)
_, err = fmt.Fprintf(fStderr, "%s line 1 of stderr\n", time.Now().UTC().Format(rfc3339NanoFixed))
c.Assert(err, check.IsNil)
+
+ {
+ // Without "-f", just show the existing logs and
+ // exit. Timeout needs to be long enough for "go run".
+ ctxNoFollow, cancel := context.WithDeadline(ctx, time.Now().Add(time.Second*5))
+ defer cancel()
+ cmdNoFollow := exec.CommandContext(ctxNoFollow, "go", "run", ".", "logs", "-poll=250ms", cr.UUID)
+ buf, err := cmdNoFollow.CombinedOutput()
+ c.Check(err, check.IsNil)
+ c.Check(string(buf), check.Matches, `(?ms).*line 1 of stderr\n`)
+ }
+
time.Sleep(time.Second * 2)
_, err = fmt.Fprintf(fCrunchrun, "%s line 2 of crunch-run.txt", time.Now().UTC().Format(rfc3339NanoFixed))
c.Assert(err, check.IsNil)
@@ -304,7 +316,7 @@ func (s *ClientSuite) TestContainerRequestLog(c *check.C) {
{
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(time.Second*5))
defer cancel()
- cmd := exec.CommandContext(ctx, "go", "run", ".", "logs", cr.UUID)
+ cmd := exec.CommandContext(ctx, "go", "run", ".", "logs", "-f", cr.UUID)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "ARVADOS_API_TOKEN="+arvadostest.SystemRootToken)
buf, err := cmd.CombinedOutput()
commit 2f117c412dc990a81ff5fa40ecb38be6a506bd38
Author: Tom Clegg <tom at curii.com>
Date: Fri Apr 28 11:12:15 2023 -0400
18790: Fix usage messages.
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>
diff --git a/cmd/arvados-client/container_gateway.go b/cmd/arvados-client/container_gateway.go
index 08f37d564..94375075c 100644
--- a/cmd/arvados-client/container_gateway.go
+++ b/cmd/arvados-client/container_gateway.go
@@ -34,13 +34,13 @@ type logsCommand struct {
func (lc logsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
f := flag.NewFlagSet(prog, flag.ContinueOnError)
pollInterval := f.Duration("poll", time.Second*2, "minimum duration to wait before polling for new data")
- if ok, code := cmd.ParseFlags(f, prog, args, "container-uuid", stderr); !ok {
+ if ok, code := cmd.ParseFlags(f, prog, args, "container-request-uuid", stderr); !ok {
return code
} else if f.NArg() < 1 {
- fmt.Fprintf(stderr, "missing required argument: container-uuid (try -help)\n")
+ fmt.Fprintf(stderr, "missing required argument: container-request-uuid (try -help)\n")
return 2
} else if f.NArg() > 1 {
- fmt.Fprintf(stderr, "encountered extra arguments after container-uuid (try -help)\n")
+ fmt.Fprintf(stderr, "encountered extra arguments after container-request-uuid (try -help)\n")
return 2
}
target := f.Args()[0]
diff --git a/lib/cmd/parseflags.go b/lib/cmd/parseflags.go
index 3e872fcd1..707cacbf5 100644
--- a/lib/cmd/parseflags.go
+++ b/lib/cmd/parseflags.go
@@ -8,8 +8,13 @@ import (
"flag"
"fmt"
"io"
+ "reflect"
)
+// Hack to enable checking whether a given FlagSet's Usage method is
+// the (private) default one.
+var defaultFlagSet = flag.NewFlagSet("none", flag.ContinueOnError)
+
// ParseFlags calls f.Parse(args) and prints appropriate error/help
// messages to stderr.
//
@@ -34,7 +39,12 @@ func ParseFlags(f FlagSet, prog string, args []string, positional string, stderr
}
return true, 0
case flag.ErrHelp:
- if f, ok := f.(*flag.FlagSet); ok && f.Usage != nil {
+ // Use our own default usage func, not the one
+ // provided by the flag pkg, if the caller hasn't set
+ // one. (We use reflect to determine whether f.Usage
+ // is the private defaultUsage func that
+ // flag.NewFlagSet uses.)
+ if f, ok := f.(*flag.FlagSet); ok && f.Usage != nil && reflect.ValueOf(f.Usage).String() != reflect.ValueOf(defaultFlagSet.Usage).String() {
f.SetOutput(stderr)
f.Usage()
} else {
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list