19377: Say "health check OK" on success. 19377-diagnostics-health-check
authorTom Clegg <tom@curii.com>
Thu, 6 Oct 2022 18:14:31 +0000 (14:14 -0400)
committerTom Clegg <tom@curii.com>
Thu, 6 Oct 2022 18:14:31 +0000 (14:14 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

sdk/go/health/aggregator.go
sdk/go/health/aggregator_test.go

index caf99108a632ac44163a4e669fce9bb00366c078..63e0b0d9018f26d25cb1aa5b581bb1b35d1fbc8f 100644 (file)
@@ -438,7 +438,7 @@ func (ccmd checkCommand) RunCommand(prog string, args []string, stdin io.Reader,
        err := ccmd.run(ctx, prog, args, stdin, stdout, stderr)
        if err != nil {
                if err != errSilent {
-                       fmt.Fprintln(stdout, err.Error())
+                       fmt.Fprintln(stderr, err.Error())
                }
                return 1
        }
@@ -452,6 +452,7 @@ func (ccmd checkCommand) run(ctx context.Context, prog string, args []string, st
        loader.SetupFlags(flags)
        versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0")
        timeout := flags.Duration("timeout", defaultTimeout.Duration(), "Maximum time to wait for health responses")
+       quiet := flags.Bool("quiet", false, "Silent on success (suppress 'health check OK' message on stderr)")
        outputYAML := flags.Bool("yaml", false, "Output full health report in YAML format (default mode shows errors as plain text, is silent on success)")
        if ok, _ := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
                // cmd.ParseFlags already reported the error
@@ -487,11 +488,14 @@ func (ccmd checkCommand) run(ctx context.Context, prog string, args []string, st
        }
        if resp.Health != "OK" {
                for _, msg := range resp.Errors {
-                       fmt.Fprintln(stdout, msg)
+                       fmt.Fprintln(stderr, msg)
                }
                fmt.Fprintln(stderr, "health check failed")
                return errSilent
        }
+       if !*quiet {
+               fmt.Fprintln(stderr, "health check OK")
+       }
        return nil
 }
 
index b1166c27d457317b8a4f6d5b5bcdea69cc6bf273..f76f7b8ea80a45ba9d908e485d2dcae8b9eca300 100644 (file)
@@ -321,6 +321,13 @@ func (s *AggregatorSuite) TestCheckCommand(c *check.C) {
 
        exitcode := CheckCommand.RunCommand("check", []string{"-config=" + tmpdir + "/config.yml"}, &bytes.Buffer{}, &stdout, &stderr)
        c.Check(exitcode, check.Equals, 0)
+       c.Check(stderr.String(), check.Equals, "health check OK\n")
+       c.Check(stdout.String(), check.Equals, "")
+
+       stdout.Reset()
+       stderr.Reset()
+       exitcode = CheckCommand.RunCommand("check", []string{"-quiet", "-config=" + tmpdir + "/config.yml"}, &bytes.Buffer{}, &stdout, &stderr)
+       c.Check(exitcode, check.Equals, 0)
        c.Check(stderr.String(), check.Equals, "")
        c.Check(stdout.String(), check.Equals, "")