Skip to content

Commit f09e551

Browse files
authored
outputs/warp10: url encode comma in tags value (#8657)
1 parent fe16d56 commit f09e551

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

plugins/outputs/warp10/warp10.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"math"
99
"net/http"
10+
"net/url"
1011
"sort"
1112
"strconv"
1213
"strings"
@@ -174,7 +175,9 @@ func buildTags(tags []*telegraf.Tag) []string {
174175
tagsString := make([]string, len(tags)+1)
175176
indexSource := 0
176177
for index, tag := range tags {
177-
tagsString[index] = fmt.Sprintf("%s=%s", tag.Key, tag.Value)
178+
key := url.QueryEscape(tag.Key)
179+
value := url.QueryEscape(tag.Value)
180+
tagsString[index] = fmt.Sprintf("%s=%s", key, value)
178181
indexSource = index
179182
}
180183
indexSource++

plugins/outputs/warp10/warp10_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ func TestWriteWarp10(t *testing.T) {
2424
require.Exactly(t, "1257894000000000// unit.testtest1.value{source=telegraf,tag1=value1} 1.000000\n", payload)
2525
}
2626

27+
func TestWriteWarp10EncodedTags(t *testing.T) {
28+
w := Warp10{
29+
Prefix: "unit.test",
30+
WarpURL: "http://localhost:8090",
31+
Token: "WRITE",
32+
}
33+
34+
metrics := testutil.MockMetrics()
35+
for _, metric := range metrics {
36+
metric.AddTag("encoded{tag", "value1,value2")
37+
}
38+
39+
payload := w.GenWarp10Payload(metrics)
40+
require.Exactly(t, "1257894000000000// unit.testtest1.value{encoded%7Btag=value1%2Cvalue2,source=telegraf,tag1=value1} 1.000000\n", payload)
41+
}
42+
2743
func TestHandleWarp10Error(t *testing.T) {
2844
w := Warp10{
2945
Prefix: "unit.test",

0 commit comments

Comments
 (0)