Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: special case the return values from a sharded first/last_over_time query #13578

Merged
merged 7 commits into from
Jul 25, 2024

Conversation

cstyan
Copy link
Contributor

@cstyan cstyan commented Jul 18, 2024

We noticed during the rollout of first/last_over_time sharding earlier this week that instant queries would return vectors only (as intended), and the code for handling merging of sharded first/last_over_time queries expected to only receive matrices.

With this PR we're special casing the return value from JoinSampleVector if the operation type is the sharded first/last_over_time.

Signed-off-by: Callum Styan <callumstyan@gmail.com>
@cstyan cstyan requested a review from a team as a code owner July 18, 2024 23:58
@cstyan cstyan changed the title special case the return values from a sharded first/last_over_time query fix: special case the return values from a sharded first/last_over_time query Jul 19, 2024
@@ -381,9 +385,36 @@ func (q *query) evalSample(ctx context.Context, expr syntax.SampleExpr) (promql_
return nil, errors.New("unexpected empty result")
}

func (q *query) JoinSampleVector(next bool, r StepResult, stepEvaluator StepEvaluator, maxSeries int) (promql_parser.Value, error) {
func vectorsToSeries(vec promql.Vector) ([]promql.Series, map[uint64]*promql.Series) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a test function for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is tested via TestMappingEquivalence_Instant, we could add a test specifically for this but it didn't feel necessary

Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and few bits of feedback mainly around tests

pkg/logql/downstream_test.go Outdated Show resolved Hide resolved
@@ -395,6 +426,14 @@ func (q *query) JoinSampleVector(next bool, r StepResult, stepEvaluator StepEval
}

if GetRangeType(q.params) == InstantType {
// an instant query sharded first/last_over_time can return a single vector
if mergeFirstLast {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does TestMappingEquivalence_Instant need a test for the false case (existing behavior) here? Or is that adequately covered elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests here execute both the sharded and unsharded (aka not mergeFirstLast) versions of the queries, and then compare the results

Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
TestMappingEquivalence

Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Callum Styan <callumstyan@gmail.com>
@cstyan cstyan merged commit 29a37d5 into main Jul 25, 2024
61 checks passed
@cstyan cstyan deleted the callum-fix-fl-shard-instant branch July 25, 2024 17:37
@cstyan cstyan added type/bug Somehing is not working as expected backport k212 labels Jul 25, 2024
grafanabot pushed a commit that referenced this pull request Jul 25, 2024
…me query (#13578)

Signed-off-by: Callum Styan <callumstyan@gmail.com>
(cherry picked from commit 29a37d5)
benclive pushed a commit to cyriltovena/loki that referenced this pull request Jul 31, 2024
…me query (grafana#13578)

Signed-off-by: Callum Styan <callumstyan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport k212 size/L type/bug Somehing is not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants