Fix graphite minus one timestamp (#609)

* fix graphite -1 timestamp

* format the graphite fix -1 timestamp
This commit is contained in:
Seva Poliakov 2020-07-08 13:59:19 +03:00 committed by GitHub
parent 32b9fb58b8
commit eb45185eef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -1,7 +1,9 @@
package graphite
import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
"reflect"
"strings"
"testing"
)
@ -161,3 +163,27 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
},
})
}
func Test_streamContext_Read(t *testing.T) {
f := func(s string, rowsExpected *Rows) {
t.Helper()
ctx := &streamContext{}
ctx.Read(strings.NewReader(s))
if len(ctx.Rows.Rows) != len(rowsExpected.Rows) {
t.Fatalf("different len of expected rows;\ngot\n%+v;\nwant\n%+v", ctx.Rows, rowsExpected.Rows)
}
if !reflect.DeepEqual(ctx.Rows.Rows, rowsExpected.Rows) {
t.Fatalf("unexpected rows;\ngot\n%+v;\nwant\n%+v", ctx.Rows.Rows, rowsExpected.Rows)
}
}
// -1 timestamp
currentTimestamp := int64(fasttime.UnixTimestamp())
f("aaa 1123", &Rows{
Rows: []Row{{
Metric: "aaa",
Value: 1123,
Timestamp: currentTimestamp * 1000,
}},
})
}

View file

@ -75,7 +75,7 @@ func (ctx *streamContext) Read(r io.Reader) bool {
currentTimestamp := int64(fasttime.UnixTimestamp())
for i := range rows {
r := &rows[i]
if r.Timestamp == 0 {
if r.Timestamp == 0 || r.Timestamp == -1 {
r.Timestamp = currentTimestamp
}
}