Skip to content

Commit

Permalink
Benchtool: add -bench.write.proxy-url argument. (#223)
Browse files Browse the repository at this point in the history
This allows configuring the Prometheus remote-write client with a HTTP proxy URL.

Getting the client to support the HTTP[S]_PROXY environment variables is not
straightforward, as the creation of the HTTP transport is deep in the upstream
code. Additionally, the client appears to have it's own mechanism for
configuring a HTTP proxy, so it would be safer to use that without meddling.
  • Loading branch information
stevesg authored Nov 16, 2021
1 parent 4d60651 commit c9664fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Order should be `CHANGE`, `FEATURE`, `ENHANCEMENT`, and `BUGFIX`

## unreleased

* [ENHANCEMENT] Benchtool: add `-bench.write.proxy-url` argument for configuring the Prometheus remote-write client with a HTTP proxy URL. #223

## v0.10.6

* [FEATURE] Rules check for Loki now supports `pattern`.
Expand Down
14 changes: 14 additions & 0 deletions pkg/bench/write_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ type WriteBenchConfig struct {
Endpoint string `yaml:"endpoint"`
BasicAuthUsername string `yaml:"basic_auth_username"`
BasicAuthPasword string `yaml:"basic_auth_password"`
ProxyURL string `yaml:"proxy_url"`
}

func (cfg *WriteBenchConfig) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.Enabled, "bench.write.enabled", false, "enable write benchmarking")
f.StringVar(&cfg.Endpoint, "bench.write.endpoint", "", "Remote write endpoint.")
f.StringVar(&cfg.BasicAuthUsername, "bench.write.basic-auth-username", "", "Set the basic auth username on remote write requests.")
f.StringVar(&cfg.BasicAuthPasword, "bench.write.basic-auth-password", "", "Set the basic auth password on remote write requests.")
f.StringVar(&cfg.ProxyURL, "bench.write.proxy-url", "", "Set the HTTP proxy URL to use on remote write requests.")
}

type WriteBenchmarkRunner struct {
Expand Down Expand Up @@ -110,6 +112,15 @@ func (w *WriteBenchmarkRunner) getRandomWriteClient() (*writeClient, error) {
if err != nil {
return nil, err
}

var proxyURL *url.URL
if w.cfg.ProxyURL != "" {
proxyURL, err = url.Parse(w.cfg.ProxyURL)
if err != nil {
return nil, errors.Wrap(err, "invalid proxy url")
}
}

cli, err = newWriteClient("bench-"+pick, w.tenantName, &remote.ClientConfig{
URL: &config.URL{URL: u},
Timeout: model.Duration(w.workload.options.Timeout),
Expand All @@ -119,6 +130,9 @@ func (w *WriteBenchmarkRunner) getRandomWriteClient() (*writeClient, error) {
Username: w.cfg.BasicAuthUsername,
Password: config.Secret(w.cfg.BasicAuthPasword),
},
ProxyURL: config.URL{
URL: proxyURL,
},
},
}, w.logger, w.requestDuration)
if err != nil {
Expand Down

0 comments on commit c9664fe

Please sign in to comment.