Skip to content

fix: cache strict-validation verdicts by config content#14253

Merged
chandler-solo merged 1 commit into
kgateway-dev:mainfrom
chandler-solo:chandler/forwardport14242caching
Jun 15, 2026
Merged

fix: cache strict-validation verdicts by config content#14253
chandler-solo merged 1 commit into
kgateway-dev:mainfrom
chandler-solo:chandler/forwardport14242caching

Conversation

@chandler-solo

Copy link
Copy Markdown
Contributor

Description

Performance fix; forward port of #14242

Ref #14184

Change Type

/kind fix

Changelog

Strict validation (KGW_VALIDATION_MODE=STRICT) now caches validation verdicts by config content
hash, eliminating redundant envoy invocations across per-client translation and recomputes. New
settings: KGW_VALIDATOR_MODE (CACHE [default] | BINARY) and KGW_VALIDATOR_CACHE_SIZE (default
4096).

Additional Notes

Copilot AI review requested due to automatic review settings June 15, 2026 15:13
@chandler-solo
chandler-solo requested a review from a team as a code owner June 15, 2026 15:13
Performance fix; forward port of kgateway-dev#14242

Ref kgateway-dev#14184

Signed-off-by: David L. Chandler <[email protected]>
@chandler-solo
chandler-solo force-pushed the chandler/forwardport14242caching branch from c74218f to b05c2bf Compare June 15, 2026 15:14
@chandler-solo
chandler-solo enabled auto-merge June 15, 2026 15:14

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

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves strict validation performance by adding a content-hash keyed caching validator and wiring it into setup and settings, reducing redundant Envoy validation invocations.

Changes:

  • Add cachingValidator (LRU + singleflight) and a factory to select validator mode from settings.
  • Introduce settings/env vars for validator mode and cache size; update setup wiring to use the factory.
  • Add unit tests and benchmarks to validate caching behavior and measure overhead.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pkg/validator/cache.go Implements LRU + singleflight caching validator keyed by bootstrap content hash.
pkg/validator/cache_test.go Adds tests for cache hits/misses, eviction, transient errors, and concurrency collapse.
pkg/validator/validator.go Adds cacheKeyFor hashing helper used by caching validator.
pkg/validator/factory.go Adds settings-based validator constructor selecting CACHE vs BINARY behavior.
pkg/validator/factory_test.go Tests validator factory behavior across modes and defaults.
pkg/validator/validator_bench_test.go Adds microbenchmarks to compare binary vs cached mode overhead.
api/settings/settings.go Adds ValidatorMode and ValidatorCacheSize settings and decoding.
api/settings/settings_test.go Extends settings tests to cover new env vars and validation.
pkg/kgateway/setup/setup.go Switches setup to build validator via settings-driven factory.
pkg/kgateway/translator/irtranslator/validate.go Optimizes strict route validation to 1 call for valid routes, 2 for invalid.
pkg/kgateway/translator/irtranslator/validate_test.go Adds tests ensuring updated strict validation call behavior and error attribution.
pkg/kgateway/translator/irtranslator/backend_validation_test.go Adds tests asserting strict validation caching across backend translations.
pkg/kgateway/proxy_syncer/perclient_bench_test.go Adds per-client connect/drain benchmark comparing cached vs uncached validation.
go.mod Promotes golang-lru/v2 to a direct dependency.
hack/utils/oss_compliance/osa_included.md Records new direct dependency for OSS compliance.

Comment thread pkg/validator/cache_test.go
Comment thread pkg/validator/cache_test.go
Comment thread pkg/validator/validator_bench_test.go
Comment thread pkg/kgateway/proxy_syncer/perclient_bench_test.go
Comment thread pkg/kgateway/translator/irtranslator/backend_validation_test.go
Comment thread pkg/validator/validator.go
Comment thread pkg/validator/cache.go
Comment thread pkg/validator/factory.go
@gateway-bot gateway-bot added kind/fix Categorizes issue or PR as related to a bug. release-note labels Jun 15, 2026
@chandler-solo
chandler-solo added this pull request to the merge queue Jun 15, 2026
Merged via the queue into kgateway-dev:main with commit 8358a9e Jun 15, 2026
34 of 35 checks passed
@chandler-solo
chandler-solo deleted the chandler/forwardport14242caching branch June 15, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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