protoparser/opentsdb: allow lines without tags (#3303)

According to http://opentsdb.net/docs/build/html/api_telnet/put.html
"At least one tag pair must be present".
However, in VictoriaMetrics datamodel tags aren't required.
This could be confusing for users. Allowing accept lines without
tags seems to do no harm.

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290
Signed-off-by: hagen1778 <roman@victoriametrics.com>

Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2022-11-09 14:32:47 +01:00 committed by GitHub
parent e17a1acf4a
commit 04b0e4e7bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View file

@ -84,13 +84,15 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
tail = trimLeadingSpaces(tail[n+1:])
n = strings.IndexByte(tail, ' ')
if n < 0 {
return tagsPool, fmt.Errorf("cannot find whitespace between value and the first tag in %q", s)
// see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3290
n = len(tail)
}
v, err := fastfloat.Parse(tail[:n])
if err != nil {
return tagsPool, fmt.Errorf("cannot parse value from %q: %w", tail[:n], err)
}
r.Value = v
if len(tail) > n {
tagsStart := len(tagsPool)
tagsPool, err = unmarshalTags(tagsPool, tail[n+1:])
if err != nil {
@ -98,6 +100,8 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
}
tags := tagsPool[tagsStart:]
r.Tags = tags[:len(tags):len(tags)]
}
return tagsPool, nil
}

View file

@ -37,9 +37,6 @@ func TestRowsUnmarshalFailure(t *testing.T) {
f("put aaa timestamp")
f("put foobar 3df4 -123456 a=b")
// Missing first tag
f("put aaa 123 43")
// Invalid value
f("put aaa 123 invalid-value")
f("put foobar 789 -123foo456 a=b")
@ -104,6 +101,14 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
},
}},
})
// No tags
f("put foobar 789 -123.456", &Rows{
Rows: []Row{{
Metric: "foobar",
Value: -123.456,
Timestamp: 789,
}},
})
// Fractional timestamp that is supported by Akumuli.
f("put foobar 789.4 -123.456 a=b", &Rows{
Rows: []Row{{