Skip to content

Commit

Permalink
fix: nanosecond values in test with non-decimal seconds value
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney committed Jun 3, 2024
1 parent cbf9fc0 commit 6ed195e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion pkg/util/marshal/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/util/marshal/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
},
Expand All @@ -1174,8 +1174,8 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) {
"foo": "bar"
},
"values": [
[0.001, "1"],
[0.002, "2"]
[1, "1"],
[2, "2"]
]
}
]`),
Expand All @@ -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},
},
},
},
Expand All @@ -1205,17 +1205,17 @@ func Test_WriteQuerySamplesResponseJSON(t *testing.T) {
"foo": "bar"
},
"values": [
[0.001, "1"],
[0.002, "2"]
[1, "1"],
[2, "2"]
]
},
{
"metric": {
"foo": "buzz"
},
"values": [
[0.003, "1"],
[0.003, "2"]
[3, "1"],
[3, "2"]
]
}
]`),
Expand Down

0 comments on commit 6ed195e

Please sign in to comment.