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 Aliaksandr Valialkin
parent fad008df7e
commit 1ae0334e17
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
}
}