Skip to content

Commit 7bdc283

Browse files
committed
refactor: move prombench to promrw
1 parent 4f7ab6e commit 7bdc283

File tree

9 files changed

+157
-153
lines changed

9 files changed

+157
-153
lines changed

cmd/promrw/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go run ./cmd/promrw record -o /tmp/requests.rwq --d 10m --addr="127.0.0.1:8080"
99

1010
Start load generator:
1111
```bash
12-
go run ./cmd/prombench --targetsCount=100 --scrapeInterval=1s http://127.0.0.1:8080
12+
go run ./cmd/promrw bench --targetsCount=100 --scrapeInterval=1s http://127.0.0.1:8080
1313
```
1414

1515
Prometheus remote write requests will be recorded to `/tmp/requests.rwq` file.

cmd/promrw/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import (
1313
func main() {
1414
rootCmd := &cobra.Command{
1515
Use: "promrw",
16-
Short: "promrw is a tool for recording and sending prometheus remote write requests",
16+
Short: "promrw is a benchmarking suite for prometheus remote write",
17+
18+
SilenceUsage: true,
1719
}
1820
rootCmd.AddCommand(
19-
newRecorderCommand(),
20-
newSenderCommand(),
21+
newRecordCommand(),
22+
newReplayCommand(),
23+
newBenchCommand(),
2124
)
2225
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
2326
defer stop()

cmd/promrw/recorder.go renamed to cmd/promrw/record.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"golang.org/x/sync/errgroup"
2121
)
2222

23-
type Recorder struct {
23+
type Record struct {
2424
Addr string
2525
Duration time.Duration
2626
Output string
@@ -30,7 +30,7 @@ type Recorder struct {
3030
bytes atomic.Uint64
3131
}
3232

33-
func (r *Recorder) read(req *http.Request) ([]byte, error) {
33+
func (r *Record) read(req *http.Request) ([]byte, error) {
3434
if t := req.Header.Get("Content-Type"); t != "application/x-protobuf" {
3535
return nil, errors.Errorf("unsupported content type %q", t)
3636
}
@@ -71,7 +71,7 @@ func fmtInt(v int) string {
7171
return s
7272
}
7373

74-
func (r *Recorder) Run(ctx context.Context) (rerr error) {
74+
func (r *Record) Run(ctx context.Context) (rerr error) {
7575
fmt.Println("listening on", "http://"+r.Addr)
7676
fmt.Println("writing to", r.Output, "for", r.Duration)
7777
f, err := os.Create(r.Output)
@@ -158,8 +158,8 @@ func (r *Recorder) Run(ctx context.Context) (rerr error) {
158158
return g.Wait()
159159
}
160160

161-
func newRecorderCommand() *cobra.Command {
162-
var recorder Recorder
161+
func newRecordCommand() *cobra.Command {
162+
var recorder Record
163163
cmd := &cobra.Command{
164164
Use: "record",
165165
Args: cobra.NoArgs,

cmd/promrw/sender.go renamed to cmd/promrw/replay.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import (
1717
"golang.org/x/sync/errgroup"
1818
)
1919

20-
type Sender struct {
20+
type Replay struct {
2121
Target string
2222
Source string
2323
Workers int
2424
}
2525

26-
func (s *Sender) Run(ctx context.Context) error {
27-
f, err := os.Open(s.Source)
26+
func (r *Replay) Run(ctx context.Context) error {
27+
f, err := os.Open(r.Source)
2828
if err != nil {
2929
return errors.Wrap(err, "open file")
3030
}
@@ -50,7 +50,7 @@ func (s *Sender) Run(ctx context.Context) error {
5050
fn := func(data []byte) error {
5151
ctx, cancel := context.WithTimeout(ctx, time.Minute)
5252
defer cancel()
53-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.Target, bytes.NewReader(data))
53+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, r.Target, bytes.NewReader(data))
5454
if err != nil {
5555
return errors.Wrap(err, "create request")
5656
}
@@ -75,7 +75,7 @@ func (s *Sender) Run(ctx context.Context) error {
7575

7676
g, ctx := errgroup.WithContext(ctx)
7777
inputs := make(chan []byte)
78-
for i := 0; i < s.Workers; i++ {
78+
for i := 0; i < r.Workers; i++ {
7979
g.Go(func() error {
8080
for {
8181
select {
@@ -121,18 +121,18 @@ func (s *Sender) Run(ctx context.Context) error {
121121
return nil
122122
}
123123

124-
func newSenderCommand() *cobra.Command {
125-
var sender Sender
124+
func newReplayCommand() *cobra.Command {
125+
var replay Replay
126126
cmd := &cobra.Command{
127-
Use: "send",
127+
Use: "replay",
128128
Short: "Send recorded requests to remote write server",
129129
Args: cobra.NoArgs,
130130
RunE: func(cmd *cobra.Command, args []string) error {
131-
return sender.Run(cmd.Context())
131+
return replay.Run(cmd.Context())
132132
},
133133
}
134-
cmd.Flags().StringVar(&sender.Target, "target", "http://127.0.0.1:19291", "Target server")
135-
cmd.Flags().StringVarP(&sender.Source, "input", "i", "requests.rwq", "Source file")
136-
cmd.Flags().IntVarP(&sender.Workers, "workers", "j", 8, "Number of workers")
134+
cmd.Flags().StringVar(&replay.Target, "target", "http://127.0.0.1:19291", "Target server")
135+
cmd.Flags().StringVarP(&replay.Source, "input", "i", "requests.rwq", "Source file")
136+
cmd.Flags().IntVarP(&replay.Workers, "workers", "j", 8, "Number of workers")
137137
return cmd
138138
}

0 commit comments

Comments
 (0)