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

Commit 0751e79

Browse files
authored
Merge pull request #17 from chr15murray/main
Add support for keepUrlTag
2 parents d8c2b37 + 4127047 commit 0751e79

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

pkg/remotewrite/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Config struct {
3838

3939
KeepTags null.Bool `json:"keepTags" envconfig:"K6_KEEP_TAGS"`
4040
KeepNameTag null.Bool `json:"keepNameTag" envconfig:"K6_KEEP_NAME_TAG"`
41+
KeepUrlTag null.Bool `json:"keepUrlTag" envconfig:"K6_KEEP_URL_TAG"`
4142
}
4243

4344
func NewConfig() Config {
@@ -51,6 +52,7 @@ func NewConfig() Config {
5152
FlushPeriod: types.NullDurationFrom(defaultFlushPeriod),
5253
KeepTags: null.BoolFrom(true),
5354
KeepNameTag: null.BoolFrom(false),
55+
KeepUrlTag: null.BoolFrom(true),
5456
Headers: make(map[string]string),
5557
}
5658
}
@@ -131,6 +133,10 @@ func (base Config) Apply(applied Config) Config {
131133
base.KeepNameTag = applied.KeepNameTag
132134
}
133135

136+
if applied.KeepUrlTag.Valid {
137+
base.KeepUrlTag = applied.KeepUrlTag
138+
}
139+
134140
if len(applied.Headers) > 0 {
135141
for k, v := range applied.Headers {
136142
base.Headers[k] = v
@@ -186,6 +192,10 @@ func ParseArg(arg string) (Config, error) {
186192
c.KeepNameTag = null.BoolFrom(v)
187193
}
188194

195+
if v, ok := params["keepUrlTag"].(bool); ok {
196+
c.KeepUrlTag = null.BoolFrom(v)
197+
}
198+
189199
c.Headers = make(map[string]string)
190200
if v, ok := params["headers"].(map[string]interface{}); ok {
191201
for k, v := range v {
@@ -284,6 +294,14 @@ func GetConsolidatedConfig(jsonRawConf json.RawMessage, env map[string]string, a
284294
}
285295
}
286296

297+
if b, err := getEnvBool(env, "K6_KEEP_URL_TAG"); err != nil {
298+
return result, err
299+
} else {
300+
if b.Valid {
301+
result.KeepUrlTag = b
302+
}
303+
}
304+
287305
envHeaders := getEnvMap(env, "K6_PROMETHEUS_HEADERS_")
288306
for k, v := range envHeaders {
289307
result.Headers[k] = v

pkg/remotewrite/config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestConstructRemoteConfig(t *testing.T) {
117117
FlushPeriod: types.NullDurationFrom(defaultFlushPeriod),
118118
KeepTags: null.BoolFrom(true),
119119
KeepNameTag: null.BoolFrom(false),
120+
KeepUrlTag: null.BoolFrom(true),
120121
Headers: make(map[string]string),
121122
},
122123
errString: "",
@@ -146,6 +147,7 @@ func TestConstructRemoteConfig(t *testing.T) {
146147
FlushPeriod: types.NullDurationFrom(defaultFlushPeriod),
147148
KeepTags: null.BoolFrom(true),
148149
KeepNameTag: null.BoolFrom(false),
150+
KeepUrlTag: null.BoolFrom(true),
149151
Headers: make(map[string]string),
150152
},
151153
errString: "",
@@ -194,6 +196,7 @@ func TestConstructRemoteConfig(t *testing.T) {
194196
FlushPeriod: types.NullDurationFrom(defaultFlushPeriod),
195197
KeepTags: null.BoolFrom(true),
196198
KeepNameTag: null.BoolFrom(false),
199+
KeepUrlTag: null.BoolFrom(true),
197200
Headers: map[string]string{
198201
"X-Header": "value",
199202
},
@@ -230,6 +233,7 @@ func TestConstructRemoteConfig(t *testing.T) {
230233
FlushPeriod: types.NullDurationFrom(defaultFlushPeriod),
231234
KeepTags: null.BoolFrom(true),
232235
KeepNameTag: null.BoolFrom(false),
236+
KeepUrlTag: null.BoolFrom(true),
233237
Headers: map[string]string{
234238
"X-Header": "value_from_env",
235239
},
@@ -266,6 +270,7 @@ func TestConstructRemoteConfig(t *testing.T) {
266270
FlushPeriod: types.NullDurationFrom(defaultFlushPeriod),
267271
KeepTags: null.BoolFrom(true),
268272
KeepNameTag: null.BoolFrom(false),
273+
KeepUrlTag: null.BoolFrom(true),
269274
Headers: map[string]string{
270275
"X-Header": "value_from_arg",
271276
},
@@ -315,6 +320,7 @@ func assertConfig(t *testing.T, actual, expected Config) {
315320
assert.Equal(t, expected.FlushPeriod, actual.FlushPeriod)
316321
assert.Equal(t, expected.KeepTags, actual.KeepTags)
317322
assert.Equal(t, expected.KeepNameTag, expected.KeepNameTag)
323+
assert.Equal(t, expected.KeepUrlTag, expected.KeepUrlTag)
318324
assert.Equal(t, expected.Headers, actual.Headers)
319325
}
320326

pkg/remotewrite/labels.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func tagsToLabels(tags *stats.SampleTags, config Config) ([]prompb.Label, error)
2222
continue
2323
}
2424

25+
if !config.KeepUrlTag.Bool && name == "url" {
26+
continue
27+
}
28+
2529
labelPairs = append(labelPairs, prompb.Label{
2630
Name: name,
2731
Value: value,

pkg/remotewrite/labels_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ func TestTagsToLabels(t *testing.T) {
4848
{Name: "name", Value: "nnn"},
4949
},
5050
},
51+
"url-tag-discard": {
52+
tags: stats.NewSampleTags(map[string]string{"foo": "bar", "url": "uuu"}),
53+
config: Config{
54+
KeepTags: null.BoolFrom(true),
55+
KeepUrlTag: null.BoolFrom(false),
56+
},
57+
labels: []prompb.Label{
58+
{Name: "foo", Value: "bar"},
59+
},
60+
},
61+
"url-tag-keep": {
62+
tags: stats.NewSampleTags(map[string]string{"foo": "bar", "url": "uuu"}),
63+
config: Config{
64+
KeepTags: null.BoolFrom(true),
65+
KeepUrlTag: null.BoolFrom(true),
66+
},
67+
labels: []prompb.Label{
68+
{Name: "foo", Value: "bar"},
69+
{Name: "url", Value: "uuu"},
70+
},
71+
},
5172
"discard-tags": {
5273
tags: stats.NewSampleTags(map[string]string{"foo": "bar", "name": "nnn"}),
5374
config: Config{

0 commit comments

Comments
 (0)