Skip to content
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

Fix CEL cost handling of zero length replacement strings #120097

Merged
merged 2 commits into from Aug 22, 2023

Conversation

jpbetz
Copy link
Contributor

@jpbetz jpbetz commented Aug 22, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes issues found in ppc64le tests of CEL estimated cost for the replace() function: #119800 (comment)

The difference in cost was caused by ppc64le calculating this expression differently than amd64:

uint64(math.Ceil(float64(sz.Max)/float64(toReplaceSz.Min))) * replaceWithSz.Max

https://gist.github.com/jpbetz/032b54ce4ef8f5427c4812c023f6c693 shows the exact difference, which is that uint64(+Inf) results in 9223372036854775808 for amd64 but 18446744073709551615 for ppc64le (and arm64?).

The fix is to avoid the divide the creates the +Inf by handling the cost edge cases for replace(). I've verified this fix works on both architectures.

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixed CEL estimated cost of `replace()` to handle a zero length replacement string correctly.
Previously this would cause the estimated cost to be higher than it should be.

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 22, 2023
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver labels Aug 22, 2023
@jpbetz jpbetz force-pushed the fix-ppc64le branch 4 times, most recently from d725a12 to 60c512b Compare August 22, 2023 05:43
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 22, 2023
@jpbetz
Copy link
Contributor Author

jpbetz commented Aug 22, 2023

/cc @Rajalakshmi-Girish
/assign @liggitt

@Rajalakshmi-Girish
Copy link
Contributor

/lgtm
It fixes the failure on ppc64le

[root@raji-workspace2 kubernetes]# uname -m
ppc64le
[root@raji-workspace2 kubernetes]#
[root@raji-workspace2 fix]# git clone https://github.com/jpbetz/kubernetes
Cloning into 'kubernetes'...
remote: Enumerating objects: 1418172, done.
remote: Counting objects: 100% (201/201), done.
remote: Compressing objects: 100% (111/111), done.
remote: Total 1418172 (delta 101), reused 123 (delta 85), pack-reused 1417971
Receiving objects: 100% (1418172/1418172), 979.50 MiB | 16.09 MiB/s, done.
Resolving deltas: 100% (1040719/1040719), done.
Updating files: 100% (23557/23557), done.
[root@raji-workspace2 fix]# cd kubernetes/
[root@raji-workspace2 kubernetes]# go test -v -timeout 30s -run ^TestCostEstimation/extended_library_replace$ k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel
=== RUN   TestCostEstimation
=== RUN   TestCostEstimation/extended_library_replace
=== RUN   TestCostEstimation/extended_library_replace/calc_maxLength
=== RUN   TestCostEstimation/extended_library_replace/set_maxLength
--- PASS: TestCostEstimation (0.01s)
    --- PASS: TestCostEstimation/extended_library_replace (0.01s)
        --- PASS: TestCostEstimation/extended_library_replace/calc_maxLength (0.01s)
        --- PASS: TestCostEstimation/extended_library_replace/set_maxLength (0.00s)
PASS
ok      k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel 0.022s
[root@raji-workspace2 kubernetes]# git checkout fix-ppc64le
Updating files: 100% (15550/15550), done.
branch 'fix-ppc64le' set up to track 'origin/fix-ppc64le'.
Switched to a new branch 'fix-ppc64le'
[root@raji-workspace2 kubernetes]# go test -v -timeout 30s -run ^TestCostEstimation/extended_library_replace$ k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel
=== RUN   TestCostEstimation
=== RUN   TestCostEstimation/extended_library_replace
=== RUN   TestCostEstimation/extended_library_replace/calc_maxLength
=== RUN   TestCostEstimation/extended_library_replace/set_maxLength
--- PASS: TestCostEstimation (0.01s)
    --- PASS: TestCostEstimation/extended_library_replace (0.01s)
        --- PASS: TestCostEstimation/extended_library_replace/calc_maxLength (0.01s)
        --- PASS: TestCostEstimation/extended_library_replace/set_maxLength (0.00s)
PASS
ok      k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel 0.032s
[root@raji-workspace2 kubernetes]#

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 22, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 034969ae302920a6d5004b023ad04c8d0cc7e373

@dims
Copy link
Member

dims commented Aug 22, 2023

/retest
/approve
/lgtm

Co-authored-by: Jordan Liggitt <jordan@liggitt.net>
@liggitt
Copy link
Member

liggitt commented Aug 22, 2023

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 22, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: e1cec82593af66156924a3036926ff32d41653a8

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, jpbetz, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@liggitt
Copy link
Member

liggitt commented Aug 22, 2023

once merged, update the cherry-pick PRs (https://github.com/kubernetes/kubernetes/pulls?q=is%3Apr+-base%3Amaster+119800) to include this commit

@jpbetz
Copy link
Contributor Author

jpbetz commented Aug 22, 2023

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 22, 2023
@jpbetz
Copy link
Contributor Author

jpbetz commented Aug 22, 2023

/retest

@alexzielenski
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 22, 2023
@jpbetz
Copy link
Contributor Author

jpbetz commented Aug 22, 2023

/retest

@BenTheElder
Copy link
Member

When you see a flaking unit test, please file an issue or add a reference to the existing issue, unit tests should NOT be flaking : (

I don't see one so I filed #120112

@sftim
Copy link
Contributor

sftim commented Aug 23, 2023

Changelog suggestion

-Fix CEL estimated cost of replace() to handle a zero length replacement string correctly.
-Previously this would cause the estimated cost to be higher than it should be.
+Fixed CEL estimated cost of `replace()` to handle a zero length replacement string correctly.
+Previously this would cause the estimated cost to be higher than it should be.

@jpbetz
Copy link
Contributor Author

jpbetz commented Aug 23, 2023

Changelog suggestion

Applied. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants