Skip to content

Commit

Permalink
outputs/warp10: url encode comma in tags value
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYoup committed Feb 8, 2021
1 parent 4608620 commit 822c846
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugins/outputs/warp10/warp10.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"math"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -174,7 +175,9 @@ func buildTags(tags []*telegraf.Tag) []string {
tagsString := make([]string, len(tags)+1)
indexSource := 0
for index, tag := range tags {
tagsString[index] = fmt.Sprintf("%s=%s", tag.Key, tag.Value)
key := url.QueryEscape(tag.Key)
value := url.QueryEscape(tag.Value)
tagsString[index] = fmt.Sprintf("%s=%s", key, value)
indexSource = index
}
indexSource++
Expand Down
16 changes: 16 additions & 0 deletions plugins/outputs/warp10/warp10_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ func TestWriteWarp10(t *testing.T) {
require.Exactly(t, "1257894000000000// unit.testtest1.value{source=telegraf,tag1=value1} 1.000000\n", payload)
}

func TestWriteWarp10EncodedTags(t *testing.T) {
w := Warp10{
Prefix: "unit.test",
WarpURL: "http://localhost:8090",
Token: "WRITE",
}

metrics := testutil.MockMetrics()
for _, metric := range metrics {
metric.AddTag("encoded{tag", "value1,value2")
}

payload := w.GenWarp10Payload(metrics)
require.Exactly(t, "1257894000000000// unit.testtest1.value{encoded%7Btag=value1%2Cvalue2,source=telegraf,tag1=value1} 1.000000\n", payload)
}

func TestHandleWarp10Error(t *testing.T) {
w := Warp10{
Prefix: "unit.test",
Expand Down

0 comments on commit 822c846

Please sign in to comment.