Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 06d4b3f

Browse files
committed
Renamed config.URL to config.ServerURL
Renamed the field name for consistency with the env var.
1 parent 56960bd commit 06d4b3f

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

pkg/remotewrite/config.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
const (
18-
defaultURL = "http://localhost:9090/api/v1/write"
18+
defaultServerURL = "http://localhost:9090/api/v1/write"
1919
defaultTimeout = 5 * time.Second
2020
defaultPushInterval = 5 * time.Second
2121
defaultMetricPrefix = "k6_"
@@ -24,8 +24,8 @@ const (
2424
var defaultTrendStats = []string{"p(99)"}
2525

2626
type Config struct {
27-
// URL contains the absolute URL for the Write endpoint where to flush the time series.
28-
URL null.String `json:"url" envconfig:"K6_PROMETHEUS_RW_SERVER_URL"`
27+
// ServerURL contains the absolute ServerURL for the Write endpoint where to flush the time series.
28+
ServerURL null.String `json:"url" envconfig:"K6_PROMETHEUS_RW_SERVER_URL"`
2929

3030
// Headers contains additional headers that should be included in the HTTP requests.
3131
Headers map[string]string `json:"headers" envconfig:"K6_PROMETHEUS_RW_HEADERS"`
@@ -56,7 +56,7 @@ type Config struct {
5656
// NewConfig creates an Output's configuration.
5757
func NewConfig() Config {
5858
return Config{
59-
URL: null.StringFrom(defaultURL),
59+
ServerURL: null.StringFrom(defaultServerURL),
6060
InsecureSkipTLSVerify: null.BoolFrom(true),
6161
Username: null.NewString("", false),
6262
Password: null.NewString("", false),
@@ -95,8 +95,8 @@ func (conf Config) RemoteConfig() (*remote.HTTPConfig, error) {
9595

9696
// Apply merges applied Config into base.
9797
func (base Config) Apply(applied Config) Config {
98-
if applied.URL.Valid {
99-
base.URL = applied.URL
98+
if applied.ServerURL.Valid {
99+
base.ServerURL = applied.ServerURL
100100
}
101101

102102
if applied.InsecureSkipTLSVerify.Valid {
@@ -201,7 +201,7 @@ func parseEnvs(env map[string]string) (Config, error) {
201201
}
202202

203203
if url, urlDefined := env["K6_PROMETHEUS_RW_SERVER_URL"]; urlDefined {
204-
c.URL = null.StringFrom(url)
204+
c.ServerURL = null.StringFrom(url)
205205
}
206206

207207
if b, err := getEnvBool(env, "K6_PROMETHEUS_RW_INSECURE_SKIP_TLS_VERIFY"); err != nil {
@@ -250,7 +250,7 @@ func parseJSON(data json.RawMessage) (Config, error) {
250250
return c, err
251251
}
252252

253-
// parseURL parses the supplied string of arguments into a Config.
253+
// parseArg parses the supplied string of arguments into a Config.
254254
func parseArg(text string) (Config, error) {
255255
var c Config
256256
opts := strings.Split(text, ",")
@@ -263,7 +263,7 @@ func parseArg(text string) (Config, error) {
263263
key, v := r[0], r[1]
264264
switch key {
265265
case "url":
266-
c.URL = null.StringFrom(v)
266+
c.ServerURL = null.StringFrom(v)
267267
case "insecureSkipTLSVerify":
268268
if err := c.InsecureSkipTLSVerify.UnmarshalText([]byte(v)); err != nil {
269269
return c, fmt.Errorf("insecureSkipTLSVerify value must be true or false, not %q", v)

pkg/remotewrite/config_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestConfigApply(t *testing.T) {
2020
t.Parallel()
2121

2222
fullConfig := Config{
23-
URL: null.StringFrom("some-url"),
23+
ServerURL: null.StringFrom("some-url"),
2424
InsecureSkipTLSVerify: null.BoolFrom(false),
2525
Username: null.StringFrom("user"),
2626
Password: null.StringFrom("pass"),
@@ -53,7 +53,7 @@ func TestConfigRemoteConfig(t *testing.T) {
5353
require.NoError(t, err)
5454

5555
config := Config{
56-
URL: null.StringFrom(u.String()),
56+
ServerURL: null.StringFrom(u.String()),
5757
InsecureSkipTLSVerify: null.BoolFrom(true),
5858
Username: null.StringFrom("myuser"),
5959
Password: null.StringFrom("mypass"),
@@ -98,7 +98,7 @@ func TestGetConsolidatedConfig(t *testing.T) {
9898
env: nil,
9999
arg: "",
100100
config: Config{
101-
URL: null.StringFrom("http://localhost:9090/api/v1/write"),
101+
ServerURL: null.StringFrom("http://localhost:9090/api/v1/write"),
102102
InsecureSkipTLSVerify: null.BoolFrom(true),
103103
Username: null.NewString("", false),
104104
Password: null.NewString("", false),
@@ -110,7 +110,7 @@ func TestGetConsolidatedConfig(t *testing.T) {
110110
"JSONSuccess": {
111111
jsonRaw: json.RawMessage(fmt.Sprintf(`{"url":"%s"}`, u.String())),
112112
config: Config{
113-
URL: null.StringFrom(u.String()),
113+
ServerURL: null.StringFrom(u.String()),
114114
InsecureSkipTLSVerify: null.BoolFrom(true),
115115
Username: null.NewString("", false),
116116
Password: null.NewString("", false),
@@ -127,7 +127,7 @@ func TestGetConsolidatedConfig(t *testing.T) {
127127
},
128128
// arg: "username=user",
129129
config: Config{
130-
URL: null.StringFrom(u.String()),
130+
ServerURL: null.StringFrom(u.String()),
131131
InsecureSkipTLSVerify: null.BoolFrom(false),
132132
Username: null.NewString("u", true),
133133
Password: null.NewString("", false),
@@ -144,7 +144,7 @@ func TestGetConsolidatedConfig(t *testing.T) {
144144
},
145145
// arg: "password=arg",
146146
config: Config{
147-
URL: null.StringFrom("http://json:9090"),
147+
ServerURL: null.StringFrom("http://json:9090"),
148148
InsecureSkipTLSVerify: null.BoolFrom(true),
149149
Username: null.StringFrom("env"),
150150
Password: null.StringFrom("env"),
@@ -181,16 +181,16 @@ func TestGetConsolidatedConfig(t *testing.T) {
181181
}
182182
}
183183

184-
func TestParseURL(t *testing.T) {
184+
func TestParseServerURL(t *testing.T) {
185185
t.Parallel()
186186

187187
c, err := parseArg("url=http://prometheus.remote:3412/write")
188188
assert.Nil(t, err)
189-
assert.Equal(t, null.StringFrom("http://prometheus.remote:3412/write"), c.URL)
189+
assert.Equal(t, null.StringFrom("http://prometheus.remote:3412/write"), c.ServerURL)
190190

191191
c, err = parseArg("url=http://prometheus.remote:3412/write,insecureSkipTLSVerify=false,pushInterval=2s")
192192
assert.Nil(t, err)
193-
assert.Equal(t, null.StringFrom("http://prometheus.remote:3412/write"), c.URL)
193+
assert.Equal(t, null.StringFrom("http://prometheus.remote:3412/write"), c.ServerURL)
194194
assert.Equal(t, null.BoolFrom(false), c.InsecureSkipTLSVerify)
195195
assert.Equal(t, types.NullDurationFrom(time.Second*2), c.PushInterval)
196196

@@ -199,7 +199,7 @@ func TestParseURL(t *testing.T) {
199199
assert.Equal(t, map[string]string{"X-Header": "value"}, c.Headers)
200200
}
201201

202-
func TestOptionURL(t *testing.T) {
202+
func TestOptionServerURL(t *testing.T) {
203203
t.Parallel()
204204

205205
cases := map[string]struct {
@@ -213,7 +213,7 @@ func TestOptionURL(t *testing.T) {
213213
}
214214

215215
expconfig := Config{
216-
URL: null.StringFrom("http://prometheus:9090/api/v1/write"),
216+
ServerURL: null.StringFrom("http://prometheus:9090/api/v1/write"),
217217
InsecureSkipTLSVerify: null.BoolFrom(true),
218218
Username: null.NewString("", false),
219219
Password: null.NewString("", false),
@@ -246,7 +246,7 @@ func TestOptionHeaders(t *testing.T) {
246246
}
247247

248248
expconfig := Config{
249-
URL: null.StringFrom("http://localhost:9090/api/v1/write"),
249+
ServerURL: null.StringFrom("http://localhost:9090/api/v1/write"),
250250
InsecureSkipTLSVerify: null.BoolFrom(true),
251251
PushInterval: types.NullDurationFrom(5 * time.Second),
252252
Headers: map[string]string{
@@ -280,7 +280,7 @@ func TestOptionInsecureSkipTLSVerify(t *testing.T) {
280280
}
281281

282282
expconfig := Config{
283-
URL: null.StringFrom(defaultURL),
283+
ServerURL: null.StringFrom(defaultServerURL),
284284
InsecureSkipTLSVerify: null.BoolFrom(false),
285285
PushInterval: types.NullDurationFrom(defaultPushInterval),
286286
Headers: make(map[string]string),
@@ -311,7 +311,7 @@ func TestOptionBasicAuth(t *testing.T) {
311311
}
312312

313313
expconfig := Config{
314-
URL: null.StringFrom("http://localhost:9090/api/v1/write"),
314+
ServerURL: null.StringFrom("http://localhost:9090/api/v1/write"),
315315
InsecureSkipTLSVerify: null.BoolFrom(true),
316316
Username: null.StringFrom("user1"),
317317
Password: null.StringFrom("pass1"),
@@ -345,7 +345,7 @@ func TestOptionTrendAsNativeHistogram(t *testing.T) {
345345
}
346346

347347
expconfig := Config{
348-
URL: null.StringFrom("http://localhost:9090/api/v1/write"),
348+
ServerURL: null.StringFrom("http://localhost:9090/api/v1/write"),
349349
InsecureSkipTLSVerify: null.BoolFrom(true),
350350
Username: null.NewString("", false),
351351
Password: null.NewString("", false),
@@ -380,7 +380,7 @@ func TestOptionPushInterval(t *testing.T) {
380380
}
381381

382382
expconfig := Config{
383-
URL: null.StringFrom("http://localhost:9090/api/v1/write"),
383+
ServerURL: null.StringFrom("http://localhost:9090/api/v1/write"),
384384
InsecureSkipTLSVerify: null.BoolFrom(true),
385385
Username: null.NewString("", false),
386386
Password: null.NewString("", false),
@@ -415,7 +415,7 @@ func TestConfigTrendStats(t *testing.T) {
415415
}
416416

417417
expconfig := Config{
418-
URL: null.StringFrom("http://localhost:9090/api/v1/write"),
418+
ServerURL: null.StringFrom("http://localhost:9090/api/v1/write"),
419419
InsecureSkipTLSVerify: null.BoolFrom(true),
420420
PushInterval: types.NullDurationFrom(5 * time.Second),
421421
Headers: make(map[string]string),

pkg/remotewrite/remotewrite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func New(params output.Params) (*Output, error) {
5252
return nil, err
5353
}
5454

55-
wc, err := remote.NewWriteClient(config.URL.String, clientConfig)
55+
wc, err := remote.NewWriteClient(config.ServerURL.String, clientConfig)
5656
if err != nil {
5757
return nil, fmt.Errorf("failed to initialize the Prometheus remote write client: %w", err)
5858
}
@@ -73,7 +73,7 @@ func New(params output.Params) (*Output, error) {
7373
}
7474

7575
func (o *Output) Description() string {
76-
return fmt.Sprintf("Prometheus remote write (%s)", o.config.URL.String)
76+
return fmt.Sprintf("Prometheus remote write (%s)", o.config.ServerURL.String)
7777
}
7878

7979
func (o *Output) Start() error {

pkg/remotewrite/remotewrite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestOutputDescription(t *testing.T) {
1717
t.Parallel()
1818
o := Output{
1919
config: Config{
20-
URL: null.StringFrom("http://remote-url.fake"),
20+
ServerURL: null.StringFrom("http://remote-url.fake"),
2121
},
2222
}
2323
exp := "Prometheus remote write (http://remote-url.fake)"

0 commit comments

Comments
 (0)