Skip to content

chore: strict validation performance part two#14269

Merged
chandler-solo merged 10 commits into
kgateway-dev:mainfrom
chandler-solo:chandler/14009guess--cachethewhole
Jun 25, 2026
Merged

chore: strict validation performance part two#14269
chandler-solo merged 10 commits into
kgateway-dev:mainfrom
chandler-solo:chandler/14009guess--cachethewhole

Conversation

@chandler-solo

@chandler-solo chandler-solo commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description

Strict validation can become expensive when a Gateway has many valid HTTPRoutes, because each route may require an Envoy validation invocation. This PR reduces that cost while preserving the existing safety behavior for bad routes.

What changed:

  • Generated Gateway API matchers are prechecked in-process when possible, so clearly invalid generated matchers can be rejected before invoking Envoy.
  • Strict full-route validation is batched per virtual host, so the common valid-route path validates many routes with one Envoy call.
  • If a batched validation fails, kgateway falls back to per-route validation to isolate the bad route and preserve current replacement behavior.
  • The AttachedRoutes load test uses the validation metrics from chore: strict validation metrics and benchmarking #14026 to report validation deltas during incremental route creation.
  • Load-test metric scraping now proxies to a ready controller pod and fails the test if metrics are unavailable.
  • E2E installs can set VALIDATION_MODE=strict to exercise strict validation through the local chart install path.

Change Type

/kind fix
/kind cleanup

Changelog

Improved strict HTTPRoute validation performance by batching full-route Envoy validation per virtual host.

Additional Notes

This PR does not add new validation metrics. It consumes the metrics from #14026 so reviewers can see how much Envoy validation work strict mode performs during the AttachedRoutes load test.

generated matchers still take 1 full-route Envoy call. (This does
not solve the 5000 valid-route benchmark problem. It helps invalid
matcher cases, but the big issue remains: valid routes are still
validated one-by-one.)

Signed-off-by: David L. Chandler <[email protected]>
Signed-off-by: David L. Chandler <[email protected]>
Signed-off-by: David L. Chandler <[email protected]>
@gateway-bot gateway-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note labels Jun 17, 2026
Signed-off-by: David L. Chandler <[email protected]>
@gateway-bot gateway-bot added the kind/fix Categorizes issue or PR as related to a bug. label Jun 17, 2026
if matcher == nil {
return fmt.Errorf("%s is missing", field)
}
if err := regexutils.CheckRegexString(matcher.GetRegex()); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

envoy regex has default max program size of 100 and can be changed but it doesn't look like change it in the Matcher setting. I have see people complain about this. Can we and should we change max program size here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not familiar with this but this PR will still call out to Envoy when strict validation is in use, and catch it that way. Added a comment in 1f2c238

Signed-off-by: David L. Chandler <[email protected]>
@chandler-solo
chandler-solo marked this pull request as ready for review June 17, 2026 22:29
Copilot AI review requested due to automatic review settings June 17, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces the cost of strict HTTPRoute validation by moving cheap matcher validation in-process and batching full-route Envoy validation per virtual host, with a fallback to per-route validation to preserve existing “drop vs replace” behavior for bad routes. It also tightens the AttachedRoutes load test to measure/require validation metrics and allows exercising strict validation through the local Helm install path.

Changes:

  • Add pre-Envoy validation for common generated matcher shapes (notably regex validity) and batch strict full-route Envoy validation across vhost routes, falling back to per-route isolation on failure.
  • Update load-test metrics scraping to proxy to a ready controller pod, and fail the load test when metrics are unavailable.
  • Allow E2E installs to set strict validation via VALIDATION_MODE -> Helm validation.level.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/e2e/tests/kgateway_test.go Adds env-controlled Helm value wiring to run E2E installs in strict validation mode.
test/e2e/features/loadtesting/loadtest_manager.go Fetches controller metrics by proxying to a ready pod with retries (used for validation metrics collection).
test/e2e/features/loadtesting/attachedroutes_suite.go Improves incremental-route timing/error reporting and makes validation metrics required for the load test.
pkg/kgateway/translator/irtranslator/validate.go Introduces pre-Envoy matcher checks and batched full-route validation helpers for strict mode.
pkg/kgateway/translator/irtranslator/route.go Batches strict validation per virtual host; isolates invalid routes on batch failure while preserving replacement semantics.
pkg/kgateway/translator/irtranslator/route_test.go Adds unit coverage for strict batching behavior and matcher precheck behavior.

Comment on lines +392 to +395
var lastErr error
timeout := time.After(60 * time.Second)
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
Signed-off-by: David L. Chandler <[email protected]>
@chandler-solo
chandler-solo requested a review from a team as a code owner June 18, 2026 14:37
Signed-off-by: David L. Chandler <[email protected]>
@chandler-solo
chandler-solo added this pull request to the merge queue Jun 25, 2026
@chandler-solo
chandler-solo removed this pull request from the merge queue due to a manual request Jun 25, 2026
@chandler-solo
chandler-solo added this pull request to the merge queue Jun 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 25, 2026
@chandler-solo
chandler-solo added this pull request to the merge queue Jun 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 25, 2026
@chandler-solo
chandler-solo added this pull request to the merge queue Jun 25, 2026
Merged via the queue into kgateway-dev:main with commit 8b782d6 Jun 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/fix Categorizes issue or PR as related to a bug. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants