mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/protoparser/graphite: support parsing floating-point timestamp like Graphite does
Such timestamps are rounded to seconds like Carbon does.
See b0ba62a62d/lib/carbon/protocols.py (L197)
This commit is contained in:
parent
1da41177a8
commit
54ff78c6c9
2 changed files with 12 additions and 2 deletions
|
@ -98,12 +98,12 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tagsPool, fmt.Errorf("cannot unmarshal value from %q: %w", tail[:n], err)
|
return tagsPool, fmt.Errorf("cannot unmarshal value from %q: %w", tail[:n], err)
|
||||||
}
|
}
|
||||||
ts, err := fastfloat.ParseInt64(tail[n+1:])
|
ts, err := fastfloat.Parse(tail[n+1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tagsPool, fmt.Errorf("cannot unmarshal timestamp from %q: %w", tail[n+1:], err)
|
return tagsPool, fmt.Errorf("cannot unmarshal timestamp from %q: %w", tail[n+1:], err)
|
||||||
}
|
}
|
||||||
r.Value = v
|
r.Value = v
|
||||||
r.Timestamp = ts
|
r.Timestamp = int64(ts)
|
||||||
return tagsPool, nil
|
return tagsPool, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,16 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Floating-point timestamp
|
||||||
|
// See https://github.com/graphite-project/carbon/blob/b0ba62a62d40a37950fed47a8f6ae6d0f02e6af5/lib/carbon/protocols.py#L197
|
||||||
|
f("aaa 1123 4294.943", &Rows{
|
||||||
|
Rows: []Row{{
|
||||||
|
Metric: "aaa",
|
||||||
|
Value: 1123,
|
||||||
|
Timestamp: 4294,
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
f("foo;bar=baz 1 2", &Rows{
|
f("foo;bar=baz 1 2", &Rows{
|
||||||
Rows: []Row{{
|
Rows: []Row{{
|
||||||
|
|
Loading…
Reference in a new issue