mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
Fix graphite minus one timestamp (#609)
* fix graphite -1 timestamp * format the graphite fix -1 timestamp
This commit is contained in:
parent
fad008df7e
commit
1ae0334e17
@ -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,
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user