Skip to content

Commit

Permalink
fix(logqlengine): include one step after end
Browse files Browse the repository at this point in the history
Loki does that, so we do too.
  • Loading branch information
tdakkota committed Apr 12, 2024
1 parent 2c14d78 commit 39bcfb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internal/logql/logqlengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,17 @@ func generateLiteralMatrix(value float64, params EvalParams) lokiapi.Matrix {
}
)

strValue := strconv.FormatFloat(value, 'f', -1, 64)
for ts := start; ts.Equal(end) || ts.Before(end); ts = ts.Add(params.Step) {
var (
until = end.Add(params.Step)
strValue = strconv.FormatFloat(value, 'f', -1, 64)
)
for ts := start; !ts.After(until); ts = ts.Add(params.Step) {
series.Values = append(series.Values, lokiapi.FPoint{
T: getPrometheusTimestamp(ts),
V: strValue,
})
}

return lokiapi.Matrix{series}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/logql/logqlengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ func TestEngineEvalLiteral(t *testing.T) {
{T: 1700000001, V: result},
{T: 1700000002, V: result},
{T: 1700000003, V: result},
// Loki includes one step after end, so we do.
{T: 1700000004, V: result},
},
},
},
Expand Down Expand Up @@ -585,6 +587,7 @@ func TestEngineEvalLiteral(t *testing.T) {
{T: 1700000001, V: "3.14"},
{T: 1700000002, V: "3.14"},
{T: 1700000003, V: "3.14"},
{T: 1700000004, V: "3.14"},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/logql/logqlengine/logqlmetric/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func newStepper(
) stepper {
return stepper{
current: start.Add(-step),
end: end,
end: end.Add(step),
step: step,
}
}
Expand Down

0 comments on commit 39bcfb9

Please sign in to comment.