outputs/warp10: url encode comma in tags value (#8657)
This commit is contained in:
parent
fe16d56a3e
commit
f09e551cbd
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -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++
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue