diff --git a/lib/protoparser/graphite/parser_test.go b/lib/protoparser/graphite/parser_test.go index ca8bcccb1..3eefef35a 100644 --- a/lib/protoparser/graphite/parser_test.go +++ b/lib/protoparser/graphite/parser_test.go @@ -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, + }}, + }) +} diff --git a/lib/protoparser/graphite/streamparser.go b/lib/protoparser/graphite/streamparser.go index 825ffdcb7..cdca2a3ed 100644 --- a/lib/protoparser/graphite/streamparser.go +++ b/lib/protoparser/graphite/streamparser.go @@ -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 } }