mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
e17a1acf4a
commit
04b0e4e7bf
2 changed files with 19 additions and 10 deletions
|
@ -84,20 +84,24 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
||||||
tail = trimLeadingSpaces(tail[n+1:])
|
tail = trimLeadingSpaces(tail[n+1:])
|
||||||
n = strings.IndexByte(tail, ' ')
|
n = strings.IndexByte(tail, ' ')
|
||||||
if n < 0 {
|
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])
|
v, err := fastfloat.Parse(tail[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tagsPool, fmt.Errorf("cannot parse value from %q: %w", tail[:n], err)
|
return tagsPool, fmt.Errorf("cannot parse value from %q: %w", tail[:n], err)
|
||||||
}
|
}
|
||||||
r.Value = v
|
r.Value = v
|
||||||
tagsStart := len(tagsPool)
|
if len(tail) > n {
|
||||||
tagsPool, err = unmarshalTags(tagsPool, tail[n+1:])
|
tagsStart := len(tagsPool)
|
||||||
if err != nil {
|
tagsPool, err = unmarshalTags(tagsPool, tail[n+1:])
|
||||||
return tagsPool, fmt.Errorf("cannot unmarshal tags in %q: %w", s, err)
|
if err != nil {
|
||||||
|
return tagsPool, fmt.Errorf("cannot unmarshal tags in %q: %w", s, err)
|
||||||
|
}
|
||||||
|
tags := tagsPool[tagsStart:]
|
||||||
|
r.Tags = tags[:len(tags):len(tags)]
|
||||||
}
|
}
|
||||||
tags := tagsPool[tagsStart:]
|
|
||||||
r.Tags = tags[:len(tags):len(tags)]
|
|
||||||
return tagsPool, nil
|
return tagsPool, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,6 @@ func TestRowsUnmarshalFailure(t *testing.T) {
|
||||||
f("put aaa timestamp")
|
f("put aaa timestamp")
|
||||||
f("put foobar 3df4 -123456 a=b")
|
f("put foobar 3df4 -123456 a=b")
|
||||||
|
|
||||||
// Missing first tag
|
|
||||||
f("put aaa 123 43")
|
|
||||||
|
|
||||||
// Invalid value
|
// Invalid value
|
||||||
f("put aaa 123 invalid-value")
|
f("put aaa 123 invalid-value")
|
||||||
f("put foobar 789 -123foo456 a=b")
|
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.
|
// Fractional timestamp that is supported by Akumuli.
|
||||||
f("put foobar 789.4 -123.456 a=b", &Rows{
|
f("put foobar 789.4 -123.456 a=b", &Rows{
|
||||||
Rows: []Row{{
|
Rows: []Row{{
|
||||||
|
|
Loading…
Reference in a new issue