-
Notifications
You must be signed in to change notification settings - Fork 340
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
perf(rules): add withNegation
flag to simplify to
policy flow
#13151
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… from-policies Signed-off-by: Ilya Lobkov <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
withNegation
flag to simplify to
policy flow
Reviewer Checklist🔍 Each of these sections need to be checked by the reviewer of the PR 🔍:
|
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
lobkovilya
reviewed
Mar 21, 2025
Signed-off-by: Lukasz Dziedziak <[email protected]>
lobkovilya
reviewed
Mar 21, 2025
pkg/api-server/testdata/resources/inspect/dataplanes/_rules/meshhttproute.golden.json
Show resolved
Hide resolved
lobkovilya
reviewed
Mar 21, 2025
...ver/testdata/resources/inspect/dataplanes/_rules/resource_rule_meshtimeout_index.golden.json
Show resolved
Hide resolved
lobkovilya
reviewed
Mar 21, 2025
Signed-off-by: Lukasz Dziedziak <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
withNegation
flag to simplify to
policy flowwithNegation
flag to simplify to
policy flow
lobkovilya
reviewed
Mar 21, 2025
Signed-off-by: Lukasz Dziedziak <[email protected]>
lobkovilya
reviewed
Mar 24, 2025
pkg/api-server/testdata/resources/inspect/meshgateways/_rules/meshhttproute.golden.json
Outdated
Show resolved
Hide resolved
Signed-off-by: Lukasz Dziedziak <[email protected]>
lobkovilya
approved these changes
Mar 24, 2025
kumahq bot
pushed a commit
that referenced
this pull request
Mar 25, 2025
…3151) ## Motivation > [!NOTE] > This is not a problem when using `meshServices.mode: Exclusive` with policies in a new style When a user has multiple `to` policies for a single top-level target reference and a default to Mesh target, CPU usage spikes due to the expensive matching process. <img width="2053" alt="Screenshot 2025-03-20 at 18 43 36" src="https://github.com/user-attachments/assets/259af8fb-357f-4cfe-ae54-257ce0cd36d9" /> ## Implementation information After analyzing the issue with @lobkovilya, we discovered that for `to` policies, our logic checks every permutation of tags. However, this is unnecessary because the only possible tags for `to` policies are `kuma.io/service`, or no tags at all when the target is `Mesh`. The only exception is `MeshHTTPRoute`, where we generate the `__rule-matches-hash__` tag, which points to a hash of the matcher. Since we don’t need to evaluate all permutations, we decided to iterate through the subsets and match them directly with the policies. To optimize further, we first deduplicate entries to avoid redundant computations. After implementing these changes, I deployed the update and ran a performance profile, which showed significant improvements.  fix: #13149 --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
kumahq bot
pushed a commit
that referenced
this pull request
Mar 25, 2025
…3151) > [!NOTE] > This is not a problem when using `meshServices.mode: Exclusive` with policies in a new style When a user has multiple `to` policies for a single top-level target reference and a default to Mesh target, CPU usage spikes due to the expensive matching process. <img width="2053" alt="Screenshot 2025-03-20 at 18 43 36" src="https://github.com/user-attachments/assets/259af8fb-357f-4cfe-ae54-257ce0cd36d9" /> After analyzing the issue with @lobkovilya, we discovered that for `to` policies, our logic checks every permutation of tags. However, this is unnecessary because the only possible tags for `to` policies are `kuma.io/service`, or no tags at all when the target is `Mesh`. The only exception is `MeshHTTPRoute`, where we generate the `__rule-matches-hash__` tag, which points to a hash of the matcher. Since we don’t need to evaluate all permutations, we decided to iterate through the subsets and match them directly with the policies. To optimize further, we first deduplicate entries to avoid redundant computations. After implementing these changes, I deployed the update and ran a performance profile, which showed significant improvements.  fix: #13149 --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
kumahq bot
pushed a commit
that referenced
this pull request
Mar 25, 2025
…3151) > [!NOTE] > This is not a problem when using `meshServices.mode: Exclusive` with policies in a new style When a user has multiple `to` policies for a single top-level target reference and a default to Mesh target, CPU usage spikes due to the expensive matching process. <img width="2053" alt="Screenshot 2025-03-20 at 18 43 36" src="https://github.com/user-attachments/assets/259af8fb-357f-4cfe-ae54-257ce0cd36d9" /> After analyzing the issue with @lobkovilya, we discovered that for `to` policies, our logic checks every permutation of tags. However, this is unnecessary because the only possible tags for `to` policies are `kuma.io/service`, or no tags at all when the target is `Mesh`. The only exception is `MeshHTTPRoute`, where we generate the `__rule-matches-hash__` tag, which points to a hash of the matcher. Since we don’t need to evaluate all permutations, we decided to iterate through the subsets and match them directly with the policies. To optimize further, we first deduplicate entries to avoid redundant computations. After implementing these changes, I deployed the update and ran a performance profile, which showed significant improvements.  fix: #13149 --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
kumahq bot
pushed a commit
that referenced
this pull request
Mar 25, 2025
…3151) > [!NOTE] > This is not a problem when using `meshServices.mode: Exclusive` with policies in a new style When a user has multiple `to` policies for a single top-level target reference and a default to Mesh target, CPU usage spikes due to the expensive matching process. <img width="2053" alt="Screenshot 2025-03-20 at 18 43 36" src="https://github.com/user-attachments/assets/259af8fb-357f-4cfe-ae54-257ce0cd36d9" /> After analyzing the issue with @lobkovilya, we discovered that for `to` policies, our logic checks every permutation of tags. However, this is unnecessary because the only possible tags for `to` policies are `kuma.io/service`, or no tags at all when the target is `Mesh`. The only exception is `MeshHTTPRoute`, where we generate the `__rule-matches-hash__` tag, which points to a hash of the matcher. Since we don’t need to evaluate all permutations, we decided to iterate through the subsets and match them directly with the policies. To optimize further, we first deduplicate entries to avoid redundant computations. After implementing these changes, I deployed the update and ran a performance profile, which showed significant improvements.  fix: #13149 --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
This was referenced Mar 25, 2025
lukidzi
added a commit
that referenced
this pull request
Mar 25, 2025
…ckport of #13151) (#13193) Automatic cherry-pick of #13151 for branch release-2.10 Generated by [action](https://github.com/kumahq/kuma/actions/runs/14056954185) cherry-picked commit c3781d4 Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
bartsmykla
pushed a commit
that referenced
this pull request
Mar 26, 2025
…ckport of #13151) (#13196) Automatic cherry-pick of #13151 for branch release-2.7 Generated by [action](https://github.com/kumahq/kuma/actions/runs/14056954185) cherry-picked commit c3781d4⚠️ ⚠️ ⚠️ Conflicts happened when cherry-picking!⚠️ ⚠️ ⚠️ ``` On branch release-2.7 Your branch is up to date with 'origin/release-2.7'. You are currently cherry-picking commit c3781d4. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/overriding_meshtimeout.golden.json modified: pkg/plugins/policies/core/matchers/egress.go modified: pkg/plugins/policies/core/matchers/testdata/matchedpolicies/torules/03.policies.yaml modified: pkg/plugins/policies/core/rules/testdata/rules/to/meshtimeout.golden.yaml modified: pkg/plugins/policies/core/rules/testdata/rules/to/single-to.golden.yaml Unmerged paths: (use "git add/rm <file>..." as appropriate to mark resolution) both modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/meshhttproute.golden.json deleted by us: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/resource_rule_meshtimeout_index.golden.json both modified: pkg/plugins/policies/core/matchers/testdata/matchedpolicies/torules/03.golden.yaml both modified: pkg/plugins/policies/core/rules/rules.go deleted by us: pkg/plugins/policies/core/rules/subsetutils/subset.go ``` --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
bartsmykla
pushed a commit
that referenced
this pull request
Mar 26, 2025
…ckport of #13151) (#13195) Automatic cherry-pick of #13151 for branch release-2.8 Generated by [action](https://github.com/kumahq/kuma/actions/runs/14056954185) cherry-picked commit c3781d4⚠️ ⚠️ ⚠️ Conflicts happened when cherry-picking!⚠️ ⚠️ ⚠️ ``` On branch release-2.8 Your branch is up to date with 'origin/release-2.8'. You are currently cherry-picking commit c3781d4. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/overriding_meshtimeout.golden.json modified: pkg/plugins/policies/core/matchers/egress.go modified: pkg/plugins/policies/core/matchers/testdata/matchedpolicies/torules/03.policies.yaml modified: pkg/plugins/policies/core/rules/testdata/rules/to/meshtimeout.golden.yaml modified: pkg/plugins/policies/core/rules/testdata/rules/to/single-to.golden.yaml Unmerged paths: (use "git add/rm <file>..." as appropriate to mark resolution) both modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/meshhttproute.golden.json deleted by us: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/resource_rule_meshtimeout_index.golden.json both modified: pkg/plugins/policies/core/matchers/testdata/matchedpolicies/torules/03.golden.yaml both modified: pkg/plugins/policies/core/rules/rules.go deleted by us: pkg/plugins/policies/core/rules/subsetutils/subset.go ``` --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
bartsmykla
pushed a commit
that referenced
this pull request
Mar 26, 2025
…ckport of #13151) (#13194) Automatic cherry-pick of #13151 for branch release-2.9 Generated by [action](https://github.com/kumahq/kuma/actions/runs/14056954185) cherry-picked commit c3781d4⚠️ ⚠️ ⚠️ Conflicts happened when cherry-picking!⚠️ ⚠️ ⚠️ ``` On branch release-2.9 Your branch is up to date with 'origin/release-2.9'. You are currently cherry-picking commit c3781d4. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/overriding_meshtimeout.golden.json modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/resource_rule_meshtimeout_index.golden.json modified: pkg/plugins/policies/core/matchers/egress.go modified: pkg/plugins/policies/core/matchers/testdata/matchedpolicies/torules/03.golden.yaml modified: pkg/plugins/policies/core/matchers/testdata/matchedpolicies/torules/03.policies.yaml modified: pkg/plugins/policies/core/rules/testdata/rules/to/meshtimeout.golden.yaml modified: pkg/plugins/policies/core/rules/testdata/rules/to/single-to.golden.yaml Unmerged paths: (use "git add/rm <file>..." as appropriate to mark resolution) both modified: pkg/api-server/testdata/resources/inspect/dataplanes/_rules/meshhttproute.golden.json both modified: pkg/plugins/policies/core/rules/rules.go deleted by us: pkg/plugins/policies/core/rules/subsetutils/subset.go ``` --------- Signed-off-by: Ilya Lobkov <[email protected]> Signed-off-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Lukasz Dziedziak <[email protected]> Co-authored-by: Ilya Lobkov <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Note
This is not a problem when using
meshServices.mode: Exclusive
with policies in a new styleWhen a user has multiple

to
policies for a single top-level target reference and a default to Mesh target, CPU usage spikes due to the expensive matching process.Implementation information
After analyzing the issue with @lobkovilya, we discovered that for
to
policies, our logic checks every permutation of tags. However, this is unnecessary because the only possible tags forto
policies arekuma.io/service
, or no tags at all when the target isMesh
.The only exception is
MeshHTTPRoute
, where we generate the__rule-matches-hash__
tag, which points to a hash of the matcher. Since we don’t need to evaluate all permutations, we decided to iterate through the subsets and match them directly with the policies. To optimize further, we first deduplicate entries to avoid redundant computations.After implementing these changes, I deployed the update and ran a performance profile, which showed significant improvements.
fix: #13149