Skip to content

Query Frontend For Logical Query Plan Support #6884

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rubywtl
Copy link

@rubywtl rubywtl commented Jul 16, 2025

What this PR does:
This PR adds logical plan generation support to the query frontend as part of the distributed query execution implementation.

Features

  • Added middleware components for:
    • PromQL query parsing
    • Logical plan creation
    • Local optimization pipeline

    Note: Distributed optimizer will be implemented in a future stage

Configuration Changes

  • Added feature flag to query frontend configs to control distributed execution
  • Maintains backwards compatibility with existing Cortex data path

Testing Coverage

  • Integration Tests

    • Verified empty request body when feature flag is disabled
    • Validated existing data path functionality remains intact
  • Unit Tests

    • Confirmed middleware correctly serializes optimized logical query plans
    • Validated request encoding functionality

Which issue(s) this PR fixes:
Related to #6789

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated

@rubywtl rubywtl force-pushed the frontend/middleware-logicalplan-support branch from 5e6383f to 3631c26 Compare July 16, 2025 22:05
@rubywtl rubywtl force-pushed the frontend/middleware-logicalplan-support branch from 7c03859 to 0d12680 Compare July 16, 2025 23:08
@rubywtl rubywtl force-pushed the frontend/middleware-logicalplan-support branch from 5b66cc6 to 22df406 Compare July 17, 2025 20:26
@rubywtl rubywtl force-pushed the frontend/middleware-logicalplan-support branch from 24b8251 to a278837 Compare July 17, 2025 22:19
Copy link
Contributor

@justinjung04 justinjung04 left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for a great start

)

const (
distributedExecEnabled = false
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this constant is decreasing the readability of the code. If you wanted to indicate the new parameter for this, maybe you could have a local variable or just add a comment:

distributedExecEnabled := false
instantQueryMiddleware, err := Middlewares(
		log.NewNopLogger(),
		mockLimitsShard{maxQueryLookback: 2},
		nil,
		qa,
		5*time.Minute,
		distributedExecEnabled,
	)
instantQueryMiddleware, err := Middlewares(
		log.NewNopLogger(),
		mockLimitsShard{maxQueryLookback: 2},
		nil,
		qa,
		5*time.Minute,
		false , // distributedExecEnabled
	)

// Integration test for query round-trip with distributed execution enabled (feature flag).
// Checks logical plan is generated, included in request body, and processed correctly.

func TestRoundTripWithDistributedExec(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having three separate test functions, can we merge them into one with multiple test cases? A lot of code seem to be repeating.

}

// TestRangeLogicalPlan validates the range logical plan generation middleware.
func TestRangeLogicalPlan(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can merge this into the above test, the only difference seem to be start and stop params of prometheus requests.

// Test: Execute middleware to populate the logical plan
_, err := handler.Do(context.Background(), tc.input)
require.NoError(t, err)
require.NotEmpty(t, tc.input.LogicalPlan, "prom request should not be empty")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of just checking emptiness, is there a way to test type or content of the logical plan?

Comment on lines +199 to +201
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider to fallback to non-distributed exec without failing the reqeust with a warning message? Just in case a bug introduced in logical planner doesn't take down the whole query availability.

@@ -25,13 +26,17 @@ var (
ShardedPrometheusCodec = NewPrometheusCodec(false, "", "protobuf")
)

const (
distributedExecEnabled = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above, this const is better to live locally or as a comment for better readability

}
}

func TestRoundTripWithoutDistributedExec(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above comment, let's merge them into single function and just have different test cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants