app/vminsert/influx: skip comments starting with # in influx line protocol

This commit is contained in:
Aliaksandr Valialkin 2019-08-23 14:41:52 +03:00
parent 697de90893
commit f1f8fce4f7
2 changed files with 23 additions and 0 deletions

View file

@ -182,6 +182,15 @@ func unmarshalRows(dst []Row, s string, tagsPool []Tag, fieldsPool []Field) ([]R
s = s[1:]
continue
}
if s[0] == '#' {
// Skip comment
if n > 0 {
s = s[n+1:]
} else {
s = s[len(s):]
}
continue
}
if cap(dst) > len(dst) {
dst = dst[:len(dst)+1]
} else {

View file

@ -147,6 +147,11 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
f("", &Rows{})
f("\n\n", &Rows{})
// Comment
f("\n# foobar\n", &Rows{})
f("#foobar baz", &Rows{})
f("#foobar baz\n#sss", &Rows{})
// Minimal line without tags and timestamp
f("foo bar=123", &Rows{
Rows: []Row{{
@ -157,6 +162,15 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
}},
}},
})
f("# comment\nfoo bar=123\n#comment2 sdsf dsf", &Rows{
Rows: []Row{{
Measurement: "foo",
Fields: []Field{{
Key: "bar",
Value: 123,
}},
}},
})
f("foo bar=123\n", &Rows{
Rows: []Row{{
Measurement: "foo",