Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
139731: pkg/cli: validate input file in tsdump command r=arjunmahishi a=arjunmahishi

In the `tsdump` command, when the `--format` is `datadog` or `datadoginit`, the input file is a mandatory argument. This commit adds validation logic for it before it's used to prevent panic.

Fixes: cockroachdb#138170
Epic: none

Co-authored-by: Arjun Mahishi <[email protected]>
  • Loading branch information
craig[bot] and arjunmahishi committed Jan 27, 2025
2 parents e8189e1 + e4f91b7 commit e508cf6
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions pkg/cli/tsdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ will then convert it to the --format requested in the current invocation.
}

var w tsWriter
switch debugTimeSeriesDumpOpts.format {
switch cmd := debugTimeSeriesDumpOpts.format; cmd {
case tsDumpRaw:
if convertFile != "" {
return errors.Errorf("input file is already in raw format")
Expand All @@ -104,30 +104,19 @@ will then convert it to the --format requested in the current invocation.
10_000_000, /* threshold */
doRequest,
)
case tsDumpDatadog:
targetURL, err := getDatadogTargetURL(debugTimeSeriesDumpOpts.ddSite)
if err != nil {
return err
case tsDumpDatadogInit, tsDumpDatadog:
if len(args) < 1 {
return errors.New("no input file provided")
}

var datadogWriter = makeDatadogWriter(
targetURL,
false,
debugTimeSeriesDumpOpts.ddApiKey,
100,
doDDRequest,
)
return datadogWriter.upload(args[0])

case tsDumpDatadogInit:
targetURL, err := getDatadogTargetURL(debugTimeSeriesDumpOpts.ddSite)
if err != nil {
return err
}

var datadogWriter = makeDatadogWriter(
targetURL,
true,
cmd == tsDumpDatadogInit,
debugTimeSeriesDumpOpts.ddApiKey,
100,
doDDRequest,
Expand Down

0 comments on commit e508cf6

Please sign in to comment.