Skip to content

Commit

Permalink
fix(promrw): fix target parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jan 7, 2024
1 parent bdcbe9f commit 2e062a6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/promrw/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"context"
"crypto/sha256"
"flag"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -495,19 +494,18 @@ func (s *Bench) prometheusConfig() *config {
return cfg
}

func (s *Bench) parseTargets() {
for _, arg := range flag.Args() {
func (s *Bench) parseTargets(args []string) error {
for _, arg := range args {
u, err := url.Parse(arg)
if err != nil {
fmt.Fprintln(os.Stderr, "invalid target:", err)
os.Exit(1)
return errors.Wrap(err, "parse url")
}
s.targets = append(s.targets, u.String())
}
if len(s.targets) == 0 {
fmt.Fprintln(os.Stderr, "no targets specified")
os.Exit(1)
return errors.New("no targets")
}
return nil
}

func (s *Bench) waitForTarget(ctx context.Context, target string) error {
Expand Down Expand Up @@ -697,8 +695,11 @@ func newBenchCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "bench",
Short: "Start remote write benchmark",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
b.parseTargets()
if err := b.parseTargets(args); err != nil {
return err
}
return b.run(cmd.Context())
},
}
Expand Down

0 comments on commit 2e062a6

Please sign in to comment.