Skip to content

Commit

Permalink
pkg/cli: validate input file in tsdump command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arjunmahishi committed Jan 24, 2025
1 parent 98dbe75 commit e4f91b7
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 e4f91b7

Please sign in to comment.