Skip to content

Commit c9664fe

Browse files
authored
Benchtool: add -bench.write.proxy-url argument. (#223)
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.
1 parent 4d60651 commit c9664fe

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## unreleased
6+
7+
* [ENHANCEMENT] Benchtool: add `-bench.write.proxy-url` argument for configuring the Prometheus remote-write client with a HTTP proxy URL. #223
8+
59
## v0.10.6
610

711
* [FEATURE] Rules check for Loki now supports `pattern`.

pkg/bench/write_runner.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ type WriteBenchConfig struct {
2929
Endpoint string `yaml:"endpoint"`
3030
BasicAuthUsername string `yaml:"basic_auth_username"`
3131
BasicAuthPasword string `yaml:"basic_auth_password"`
32+
ProxyURL string `yaml:"proxy_url"`
3233
}
3334

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

4143
type WriteBenchmarkRunner struct {
@@ -110,6 +112,15 @@ func (w *WriteBenchmarkRunner) getRandomWriteClient() (*writeClient, error) {
110112
if err != nil {
111113
return nil, err
112114
}
115+
116+
var proxyURL *url.URL
117+
if w.cfg.ProxyURL != "" {
118+
proxyURL, err = url.Parse(w.cfg.ProxyURL)
119+
if err != nil {
120+
return nil, errors.Wrap(err, "invalid proxy url")
121+
}
122+
}
123+
113124
cli, err = newWriteClient("bench-"+pick, w.tenantName, &remote.ClientConfig{
114125
URL: &config.URL{URL: u},
115126
Timeout: model.Duration(w.workload.options.Timeout),
@@ -119,6 +130,9 @@ func (w *WriteBenchmarkRunner) getRandomWriteClient() (*writeClient, error) {
119130
Username: w.cfg.BasicAuthUsername,
120131
Password: config.Secret(w.cfg.BasicAuthPasword),
121132
},
133+
ProxyURL: config.URL{
134+
URL: proxyURL,
135+
},
122136
},
123137
}, w.logger, w.requestDuration)
124138
if err != nil {

0 commit comments

Comments
 (0)