Fix dropwizard parsing error for metrics that need escaped (#4142)
If the dropwizard parser cannot convert the metric name into a valid
line protocol series then we will accept the name as is.
(cherry picked from commit 0af40a8a5d)
This commit is contained in:
committed by
Daniel Nelson
parent
03141eaad2
commit
8301861b1b
@@ -1390,3 +1390,80 @@ func BenchmarkMachineProcstat(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeriesMachine(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
input []byte
|
||||
results []Result
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "empty string",
|
||||
input: []byte(""),
|
||||
results: nil,
|
||||
},
|
||||
{
|
||||
name: "no tags",
|
||||
input: []byte("cpu"),
|
||||
results: []Result{
|
||||
Result{
|
||||
Name: Measurement,
|
||||
Value: []byte("cpu"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "tags",
|
||||
input: []byte("cpu,a=x,b=y"),
|
||||
results: []Result{
|
||||
Result{
|
||||
Name: Measurement,
|
||||
Value: []byte("cpu"),
|
||||
},
|
||||
Result{
|
||||
Name: TagKey,
|
||||
Value: []byte("a"),
|
||||
},
|
||||
Result{
|
||||
Name: TagValue,
|
||||
Value: []byte("x"),
|
||||
},
|
||||
Result{
|
||||
Name: TagKey,
|
||||
Value: []byte("b"),
|
||||
},
|
||||
Result{
|
||||
Name: TagValue,
|
||||
Value: []byte("y"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
handler := &TestingHandler{}
|
||||
fsm := NewSeriesMachine(handler)
|
||||
fsm.SetData(tt.input)
|
||||
|
||||
count := 0
|
||||
for fsm.ParseLine() {
|
||||
if fsm.Err() != nil {
|
||||
handler.AddError(fsm.Err())
|
||||
}
|
||||
count++
|
||||
if count > 20 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if fsm.Err() != nil {
|
||||
handler.AddError(fsm.Err())
|
||||
}
|
||||
|
||||
results := handler.Results()
|
||||
require.Equal(t, tt.results, results)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user