Skip to content

fix: route level policy should override gateway wide compression setting#6904

Closed
sudiptob2 wants to merge 3 commits intoenvoyproxy:mainfrom
sudiptob2:fix/6775/merge-policy
Closed

fix: route level policy should override gateway wide compression setting#6904
sudiptob2 wants to merge 3 commits intoenvoyproxy:mainfrom
sudiptob2:fix/6775/merge-policy

Conversation

@sudiptob2
Copy link
Copy Markdown
Member

Fixes #6775

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 8, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.06%. Comparing base (4e33b31) to head (ac30731).
⚠️ Report is 187 commits behind head on main.

Files with missing lines Patch % Lines
internal/gatewayapi/backendtrafficpolicy.go 66.66% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6904   +/-   ##
=======================================
  Coverage   71.06%   71.06%           
=======================================
  Files         225      225           
  Lines       39871    39878    +7     
=======================================
+ Hits        28336    28341    +5     
  Misses       9863     9863           
- Partials     1672     1674    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sudiptob2 sudiptob2 marked this pull request as ready for review September 8, 2025 02:35
@sudiptob2 sudiptob2 requested a review from a team as a code owner September 8, 2025 02:35
@zirain
Copy link
Copy Markdown
Member

zirain commented Sep 8, 2025

will Compression []*Compression json:"compression,omitempty" patchMergeKey:"type" patchStrategy:"replace"`` help on this instead of a custom logic?

@sudiptob2
Copy link
Copy Markdown
Member Author

Just tried that approach, but it has a couple of issues:

  1. Setting compression: [] is treated as empty so its omitted. As a result, the merge utility sees it as empty and doesn’t override the gateway-wide policy.

  2. If omitempty is removed from the type, then it will always override the gateway-wide policy when nothing is set at the route level. This is also not expected.

Any thoughts on working around these? @zirain

@zirain
Copy link
Copy Markdown
Member

zirain commented Sep 8, 2025

Just tried that approach, but it has a couple of issues:

  1. Setting compression: [] is treated as empty so its omitted. As a result, the merge utility sees it as empty and doesn’t override the gateway-wide policy.
  2. If omitempty is removed from the type, then it will always override the gateway-wide policy when nothing is set at the route level. This is also not expected.

Any thoughts on working around these? @zirain

git it, then we need document it Note: to disable compression in route level, set compression to empty array i.e compression: [].

@sudiptob2 sudiptob2 force-pushed the fix/6775/merge-policy branch from f64d6ad to 75e1fb4 Compare September 8, 2025 14:28
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.

can we add a yaml test in testdata/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added yaml tests

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.

can we avoid this ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not sure if the custom logic is avoidable. Another approach suggested by Zirain to use annotations but it had a couple of isssues - discussed here.

Let me know if you have any other approach in mind.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Using custom logic is not uncommon; merging the ratelimit policy also uses something similar.

// Since GlobalRateLimit merge relies on IR auto-generated key: (<policy-ns>/<policy-name>/rule/<rule-index>)
// We can't simply merge the BTP's using utils.Merge() we need to specifically merge the GlobalRateLimit.Rules using IR fields.
// Since ir.TrafficFeatures is not a built-in Kubernetes API object with defined merging strategies and it does not support a deep merge (for lists/maps).
// Handle rate limit merging cases:
// 1. Both policies have rate limits - merge them
// 2. Only gateway policy has rate limits - preserve gateway policy's rule names
// 3. Only route policy has rate limits - use route policy's rule names (default behavior)
if policy.Spec.RateLimit != nil && gwPolicy.Spec.RateLimit != nil {
// Case 1: Both policies have rate limits - merge them
tfGW, _ := t.buildTrafficFeatures(gwPolicy, resources)
tfRoute, _ := t.buildTrafficFeatures(policy, resources)
if tfGW != nil && tfRoute != nil &&
tfGW.RateLimit != nil && tfRoute.RateLimit != nil {
mergedRL, err := utils.Merge(tfGW.RateLimit, tfRoute.RateLimit, *policy.Spec.MergeType)
if err != nil {
return fmt.Errorf("error merging rate limits: %w", err)
}
// Replace the rate limit in the merged features if successful
tf.RateLimit = mergedRL

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.

the plan is to rm this custom logic

Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
… logic

Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label Oct 10, 2025
@sudiptob2 sudiptob2 closed this Oct 20, 2025
@sudiptob2 sudiptob2 deleted the fix/6775/merge-policy branch March 1, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to patch out fields using mergeType in BackendTrafficPolicy

3 participants