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:
Aliaksandr Valialkin 2020-10-06 11:37:50 +03:00
parent 90aa2a8ffd
commit e19d400230
2 changed files with 12 additions and 2 deletions

View File

@ -98,12 +98,12 @@ func (r *Row) unmarshal(s string, tagsPool []Tag) ([]Tag, error) {
if err != nil {
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 {
return tagsPool, fmt.Errorf("cannot unmarshal timestamp from %q: %w", tail[n+1:], err)
}
r.Value = v
r.Timestamp = ts
r.Timestamp = int64(ts)
return tagsPool, nil
}

View File

@ -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
f("foo;bar=baz 1 2", &Rows{
Rows: []Row{{