From 6ed195e4a3159fc0a9e85ef38c7fe2929ab39454 Mon Sep 17 00:00:00 2001 From: Trevor Whitney Date: Mon, 3 Jun 2024 09:25:37 -0600 Subject: [PATCH] fix: nanosecond values in test with non-decimal seconds value --- pkg/util/marshal/marshal.go | 4 +++- pkg/util/marshal/marshal_test.go | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/util/marshal/marshal.go b/pkg/util/marshal/marshal.go index 3c8ffbe9d0e31..5d146083a4bdd 100644 --- a/pkg/util/marshal/marshal.go +++ b/pkg/util/marshal/marshal.go @@ -9,6 +9,7 @@ import ( "github.com/gorilla/websocket" jsoniter "github.com/json-iterator/go" + "github.com/prometheus/common/model" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql/parser" @@ -278,7 +279,8 @@ func logprotoSeriesToPromQLMatrix(series []logproto.Series) (promql.Matrix, erro Floats: make([]promql.FPoint, len(s.Samples)), } for i, sample := range s.Samples { - promSeries.Floats[i] = promql.FPoint{T: sample.Timestamp / 1e6, F: sample.Value} + t := model.TimeFromUnixNano(sample.Timestamp) + promSeries.Floats[i] = promql.FPoint{T: int64(t), F: sample.Value} } promMatrix[i] = promSeries } diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index e72bce625de39..b8c90c5a61d4d 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -1162,8 +1162,8 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) { { Labels: `{foo="bar"}`, Samples: []logproto.Sample{ - {Timestamp: 1, Value: 1}, - {Timestamp: 2, Value: 2}, + {Timestamp: 1e9, Value: 1}, + {Timestamp: 2e9, Value: 2}, }, }, }, @@ -1174,8 +1174,8 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) { "foo": "bar" }, "values": [ - [0.001, "1"], - [0.002, "2"] + [1, "1"], + [2, "2"] ] } ]`), @@ -1186,15 +1186,15 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) { { Labels: `{foo="bar"}`, Samples: []logproto.Sample{ - {Timestamp: 1, Value: 1}, - {Timestamp: 2, Value: 2}, + {Timestamp: 1e9, Value: 1}, + {Timestamp: 2e9, Value: 2}, }, }, { Labels: `{foo="buzz"}`, Samples: []logproto.Sample{ - {Timestamp: 3, Value: 1}, - {Timestamp: 3, Value: 2}, + {Timestamp: 3e9, Value: 1}, + {Timestamp: 3e9, Value: 2}, }, }, }, @@ -1205,8 +1205,8 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) { "foo": "bar" }, "values": [ - [0.001, "1"], - [0.002, "2"] + [1, "1"], + [2, "2"] ] }, { @@ -1214,8 +1214,8 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) { "foo": "buzz" }, "values": [ - [0.003, "1"], - [0.003, "2"] + [3, "1"], + [3, "2"] ] } ]`),