mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 07:19:17 +01:00
lib/protoparser/graphite: fix parsing of a Graphite line with empty tags such as foo; 1 2
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1100
This commit is contained in:
parent
d9e8af0e8f
commit
f4969a624d
@ -30,6 +30,7 @@
|
|||||||
* BUGFIX: fix `http: superfluous response.WriteHeader call` issue. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1078
|
* BUGFIX: fix `http: superfluous response.WriteHeader call` issue. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1078
|
||||||
* BUGFIX: fix arm64 builds due to the issue in `github.com/golang/snappy`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1074
|
* BUGFIX: fix arm64 builds due to the issue in `github.com/golang/snappy`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1074
|
||||||
* BUGFIX: fix `index out of range [1024819115206086200] with length 27` panic, which could occur when `1e-9` value is passed to VictoriaMetrics histogram. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1096
|
* BUGFIX: fix `index out of range [1024819115206086200] with length 27` panic, which could occur when `1e-9` value is passed to VictoriaMetrics histogram. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1096
|
||||||
|
* BUGFIX: fix parsing for Graphite line with empty tags such as `foo; 123 456`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1100
|
||||||
|
|
||||||
|
|
||||||
# [v1.54.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.54.1)
|
# [v1.54.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.54.1)
|
||||||
|
@ -71,7 +71,7 @@ func (r *Row) UnmarshalMetricAndTags(s string, tagsPool []Tag) ([]Tag, error) {
|
|||||||
var err error
|
var err error
|
||||||
tagsPool, err = unmarshalTags(tagsPool, s[n+1:])
|
tagsPool, err = unmarshalTags(tagsPool, s[n+1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tagsPool, fmt.Errorf("cannot umarshal tags: %w", err)
|
return tagsPool, fmt.Errorf("cannot unmarshal tags: %w", err)
|
||||||
}
|
}
|
||||||
tags := tagsPool[tagsStart:]
|
tags := tagsPool[tagsStart:]
|
||||||
r.Tags = tags[:len(tags):len(tags)]
|
r.Tags = tags[:len(tags):len(tags)]
|
||||||
@ -171,18 +171,14 @@ func unmarshalTags(dst []Tag, s string) ([]Tag, error) {
|
|||||||
n := strings.IndexByte(s, ';')
|
n := strings.IndexByte(s, ';')
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
// The last tag found
|
// The last tag found
|
||||||
if err := tag.unmarshal(s); err != nil {
|
tag.unmarshal(s)
|
||||||
return dst[:len(dst)-1], err
|
|
||||||
}
|
|
||||||
if len(tag.Key) == 0 || len(tag.Value) == 0 {
|
if len(tag.Key) == 0 || len(tag.Value) == 0 {
|
||||||
// Skip empty tag
|
// Skip empty tag
|
||||||
dst = dst[:len(dst)-1]
|
dst = dst[:len(dst)-1]
|
||||||
}
|
}
|
||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
if err := tag.unmarshal(s[:n]); err != nil {
|
tag.unmarshal(s[:n])
|
||||||
return dst[:len(dst)-1], err
|
|
||||||
}
|
|
||||||
s = s[n+1:]
|
s = s[n+1:]
|
||||||
if len(tag.Key) == 0 || len(tag.Value) == 0 {
|
if len(tag.Key) == 0 || len(tag.Value) == 0 {
|
||||||
// Skip empty tag
|
// Skip empty tag
|
||||||
@ -202,13 +198,16 @@ func (t *Tag) reset() {
|
|||||||
t.Value = ""
|
t.Value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tag) unmarshal(s string) error {
|
func (t *Tag) unmarshal(s string) {
|
||||||
t.reset()
|
t.reset()
|
||||||
n := strings.IndexByte(s, '=')
|
n := strings.IndexByte(s, '=')
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
return fmt.Errorf("missing tag value for %q", s)
|
// Empty tag value.
|
||||||
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1100
|
||||||
|
t.Key = s
|
||||||
|
t.Value = s[len(s):]
|
||||||
|
} else {
|
||||||
|
t.Key = s[:n]
|
||||||
|
t.Value = s[n+1:]
|
||||||
}
|
}
|
||||||
t.Key = s[:n]
|
|
||||||
t.Value = s[n+1:]
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ func TestUnmarshalMetricAndTagsFailure(t *testing.T) {
|
|||||||
f("")
|
f("")
|
||||||
f(";foo=bar")
|
f(";foo=bar")
|
||||||
f(" ")
|
f(" ")
|
||||||
f("foo;bar")
|
|
||||||
f("foo ;bar=baz")
|
f("foo ;bar=baz")
|
||||||
f("f oo;bar=baz")
|
f("f oo;bar=baz")
|
||||||
f("foo;bar=baz ")
|
f("foo;bar=baz ")
|
||||||
@ -80,12 +79,6 @@ func TestRowsUnmarshalFailure(t *testing.T) {
|
|||||||
// Missing value
|
// Missing value
|
||||||
f("aaa")
|
f("aaa")
|
||||||
|
|
||||||
// missing tag
|
|
||||||
f("aa; 12 34")
|
|
||||||
|
|
||||||
// missing tag value
|
|
||||||
f("aa;bb 23 34")
|
|
||||||
|
|
||||||
// unexpected space in tag value
|
// unexpected space in tag value
|
||||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/99
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/99
|
||||||
f("s;tag1=aaa1;tag2=bb b2;tag3=ccc3 1")
|
f("s;tag1=aaa1;tag2=bb b2;tag3=ccc3 1")
|
||||||
@ -187,6 +180,31 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
// Empty tags
|
// Empty tags
|
||||||
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1100
|
||||||
|
f("foo; 1", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foo",
|
||||||
|
Tags: []Tag{},
|
||||||
|
Value: 1,
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
f("foo; 1 2", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foo",
|
||||||
|
Tags: []Tag{},
|
||||||
|
Value: 1,
|
||||||
|
Timestamp: 2,
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
// Empty tag name or value
|
||||||
|
f("foo;bar 1 2", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "foo",
|
||||||
|
Tags: []Tag{},
|
||||||
|
Value: 1,
|
||||||
|
Timestamp: 2,
|
||||||
|
}},
|
||||||
|
})
|
||||||
f("foo;bar=baz;aa=;x=y;=z 1 2", &Rows{
|
f("foo;bar=baz;aa=;x=y;=z 1 2", &Rows{
|
||||||
Rows: []Row{{
|
Rows: []Row{{
|
||||||
Metric: "foo",
|
Metric: "foo",
|
||||||
|
Loading…
Reference in New Issue
Block a user