mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/protoparser/opentsdb: accept multiple spaces between fields in a row as a deliminator. (#1575)
This commit is contained in:
parent
ca61d7c82b
commit
00dddfe02f
2 changed files with 91 additions and 3 deletions
|
@ -57,10 +57,11 @@ func (r *Row) reset() {
|
||||||
|
|
||||||
func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
||||||
r.reset()
|
r.reset()
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
if !strings.HasPrefix(s, "put ") {
|
if !strings.HasPrefix(s, "put ") {
|
||||||
return tagsPool, fmt.Errorf("missing `put ` prefix in %q", s)
|
return tagsPool, fmt.Errorf("missing `put ` prefix in %q", s)
|
||||||
}
|
}
|
||||||
s = s[len("put "):]
|
s = strings.TrimSpace(s[len("put "):])
|
||||||
n := strings.IndexByte(s, ' ')
|
n := strings.IndexByte(s, ' ')
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
return tagsPool, fmt.Errorf("cannot find whitespace between metric and timestamp in %q", s)
|
return tagsPool, fmt.Errorf("cannot find whitespace between metric and timestamp in %q", s)
|
||||||
|
@ -69,7 +70,7 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
||||||
if len(r.Metric) == 0 {
|
if len(r.Metric) == 0 {
|
||||||
return tagsPool, fmt.Errorf("metric cannot be empty")
|
return tagsPool, fmt.Errorf("metric cannot be empty")
|
||||||
}
|
}
|
||||||
tail := s[n+1:]
|
tail := strings.TrimSpace(s[n+1:])
|
||||||
n = strings.IndexByte(tail, ' ')
|
n = strings.IndexByte(tail, ' ')
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
return tagsPool, fmt.Errorf("cannot find whitespace between timestamp and value in %q", s)
|
return tagsPool, fmt.Errorf("cannot find whitespace between timestamp and value in %q", s)
|
||||||
|
@ -79,7 +80,7 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
||||||
return tagsPool, fmt.Errorf("cannot parse timestamp from %q: %w", tail[:n], err)
|
return tagsPool, fmt.Errorf("cannot parse timestamp from %q: %w", tail[:n], err)
|
||||||
}
|
}
|
||||||
r.Timestamp = int64(timestamp)
|
r.Timestamp = int64(timestamp)
|
||||||
tail = tail[n+1:]
|
tail = strings.TrimSpace(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)
|
return tagsPool, fmt.Errorf("cannot find whitespace between value and the first tag in %q", s)
|
||||||
|
@ -148,6 +149,7 @@ func unmarshalTags(dst []Tag, s string) ([]Tag, error) {
|
||||||
}
|
}
|
||||||
tag := &dst[len(dst)-1]
|
tag := &dst[len(dst)-1]
|
||||||
|
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
n := strings.IndexByte(s, ' ')
|
n := strings.IndexByte(s, ' ')
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
// The last tag found
|
// The last tag found
|
||||||
|
|
|
@ -221,4 +221,90 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Multi spaces
|
||||||
|
f("put foobar 789 -123.456 a=b", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foobar",
|
||||||
|
Value: -123.456,
|
||||||
|
Timestamp: 789,
|
||||||
|
Tags: []Tag{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Value: "b",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
f("put foobar 789 -123.456 a=b", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foobar",
|
||||||
|
Value: -123.456,
|
||||||
|
Timestamp: 789,
|
||||||
|
Tags: []Tag{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Value: "b",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
f("put foobar 789 -123.456 a=b", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foobar",
|
||||||
|
Value: -123.456,
|
||||||
|
Timestamp: 789,
|
||||||
|
Tags: []Tag{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Value: "b",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
f("put foobar 789 -123.456 a=b", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foobar",
|
||||||
|
Value: -123.456,
|
||||||
|
Timestamp: 789,
|
||||||
|
Tags: []Tag{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Value: "b",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
f("put foobar 789 -123.456 a=b c=d", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foobar",
|
||||||
|
Value: -123.456,
|
||||||
|
Timestamp: 789,
|
||||||
|
Tags: []Tag{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Value: "b",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "c",
|
||||||
|
Value: "d",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
// Soace after tags
|
||||||
|
f("put foobar 789 -123.456 a=b ", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foobar",
|
||||||
|
Value: -123.456,
|
||||||
|
Timestamp: 789,
|
||||||
|
Tags: []Tag{
|
||||||
|
{
|
||||||
|
Key: "a",
|
||||||
|
Value: "b",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue