diff --git a/cmd/backup.go b/cmd/backup.go index 8166d7bd2..277f6c282 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -32,5 +32,6 @@ Backs up a FeatureBase server to a local, tar-formatted snapshot file. flags.StringVar(&cmd.Pprof, "pprof", cmd.Pprof, "host:port to listen for profiling requests at /debug/pprof and /debug/fgprof.") ctl.SetTLSConfig(flags, "", &cmd.TLS.CertificatePath, &cmd.TLS.CertificateKeyPath, &cmd.TLS.CACertPath, &cmd.TLS.SkipVerify, &cmd.TLS.EnableClientVerification) flags.StringVar(&cmd.AuthToken, "auth-token", "", "Authentication token") + flags.StringVar(&cmd.HeaderTimeoutStr, "header-timeout", cmd.HeaderTimeoutStr, "Length of time to wait for initial HTTP response before giving up.") return ccmd } diff --git a/ctl/backup.go b/ctl/backup.go index aed077a37..6327ea012 100644 --- a/ctl/backup.go +++ b/ctl/backup.go @@ -43,7 +43,8 @@ type BackupCommand struct { // nolint: maligned RetryPeriod time.Duration `json:"retry-period"` // Response Header Timeout for HTTP Requests - HeaderTimeout time.Duration `json:"header-timeout"` + HeaderTimeoutStr string + HeaderTimeout time.Duration `json:"header-timeout"` // Host:port on which to listen for pprof. Pprof string `json:"pprof"` @@ -85,6 +86,13 @@ func (cmd *BackupCommand) Run(ctx context.Context) (err error) { } else if cmd.Concurrency <= 0 { return fmt.Errorf("concurrency must be at least one") } + if cmd.HeaderTimeoutStr != "" { + if dur, err := time.ParseDuration(cmd.HeaderTimeoutStr); err != nil { + return fmt.Errorf("could not parse '%s' as a duration: %v", cmd.HeaderTimeoutStr, err) + } else { + cmd.HeaderTimeout = dur + } + } // Parse TLS configuration for node-specific clients. tls := cmd.TLSConfiguration() diff --git a/internal/clustertests/cluster_test.go b/internal/clustertests/cluster_test.go index 6f47f799c..5c69299ff 100644 --- a/internal/clustertests/cluster_test.go +++ b/internal/clustertests/cluster_test.go @@ -173,10 +173,13 @@ func TestClusterStuff(t *testing.T) { var backupCmd *exec.Cmd tmpdir := t.TempDir() - // collect code coverage while doing backup using an instrumented binary by calling - // a wrapper test (TestRunMain) for the main entrypoint of featurebase + // Collect code coverage while doing backup using an + // instrumented binary by calling a wrapper test (TestRunMain) + // for the main entrypoint of featurebase. Note, we pass the + // "--header-timeout" option simply to ensure that it is + // accepted and properly parsed by the command. args := []string{"-test.run=TestRunMain", "-test.coverprofile=/results/coverage-backup.out", "backup", - "--host=pilosa1:10101", fmt.Sprintf("--output=%s", tmpdir+"/backuptest")} + "--host=pilosa1:10101", fmt.Sprintf("--output=%s", tmpdir+"/backuptest"), "--header-timeout=3s"} if auth { args = append(args, fmt.Sprintf("--auth-token=%s", token)) }