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

openapi parsing performance improvement with protobuffer #4568

Merged
merged 4 commits into from
Apr 18, 2022

Conversation

natasha41575
Copy link
Contributor

@natasha41575 natasha41575 commented Apr 4, 2022

Fixes #2987
Fixes #4100
Fixes #3670

Related: #4569

The performance improvement changes the format we use to parse our builtin openapi from JSON to proto. See kubernetes/kube-openapi#283, it reduces the parsing time from ~628ms to ~39ms.

You can see the performance improvement when running the example provided on this issue:

Previously:

$ time kustomize build
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
  name: example

real    0m0.670s
user    0m0.688s
sys     0m0.037s

With this branch:

$ time kustomize build
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
  name: example

real    0m0.109s
user    0m0.114s
sys     0m0.029s

You can also see about a half second improvement in performance when running certain tests, e.g.

On master:

$ time go test -run TestPatchesInOneFile
PASS
ok      sigs.k8s.io/kustomize/api/krusty        0.902s

real    0m2.407s
user    0m2.540s
sys     0m1.120s

On this branch:

$ time go test -run TestPatchesInOneFile
PASS
ok      sigs.k8s.io/kustomize/api/krusty        0.343s

real    0m1.845s
user    0m1.990s
sys     0m1.144s

There is a separate PR to update the openapi scripts here: #4582

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 4, 2022
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 4, 2022
@natasha41575 natasha41575 force-pushed the openapiconverter branch 2 times, most recently from 1f5db6d to 7b84dcf Compare April 4, 2022 20:03
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 4, 2022
@natasha41575 natasha41575 force-pushed the openapiconverter branch 9 times, most recently from f679c5c to bf635a8 Compare April 4, 2022 21:17
@k8s-ci-robot
Copy link
Contributor

@natasha41575: This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@natasha41575 natasha41575 changed the title openapi performance improvement openapi parsing performance improvement Apr 4, 2022
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 4, 2022
@natasha41575 natasha41575 reopened this Apr 4, 2022
@natasha41575
Copy link
Contributor Author

@KnVerey @mengqiy Thank you for your patience and apologies for the long delay! The PR is updated and is ready for another review.

type format string

const (
JSON format = "json"
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the implementation below, it seems we can handle json or yaml when the format is json.
Maybe we can call it JsonOrYaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Changed to JsonOrYaml

"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1218pb"
v1212 "sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1212"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should use a newer version of the schema. Maybe v1.22?
It can be done in a followup PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Yeah we were thinking about bumping the schema since we are pretty far behind. I filed #4583, let's discuss in a followup.

@mengqiy
Copy link
Member

mengqiy commented Apr 15, 2022

/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 Apr 15, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mengqiy, natasha41575

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

@KnVerey
Copy link
Contributor

KnVerey commented Apr 18, 2022

One question, but not a blocker.

/lgtm


const (
JsonOrYaml format = "jsonOrYaml"
Proto format = "proto"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these constants public but their type private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see a purpose in making the type public, but I can see a potential use case in the future of passing in the format from another package once we start supporting user-provided proto schemas, hence why I made the const public.

I'm happy to change them to both being public or both being private if that makes more sense, I don't have a strong preference either way.

@natasha41575
Copy link
Contributor Author

/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 Apr 18, 2022
@natasha41575
Copy link
Contributor Author

Thanks everyone for the quick reviews!

@k8s-ci-robot k8s-ci-robot merged commit cf89eae into kubernetes-sigs:master Apr 18, 2022
@natasha41575 natasha41575 deleted the openapiconverter branch April 18, 2022 22:39
@ephesused
Copy link
Contributor

Thanks so much for this fix. It was very nice to see these results this morning...

Test_kustomize/kust-issue-2767/kustomize/branch-master (0.15s)
kustomize_test.go:182: Runtime variation (0.14x): branch-master ran in 143ms; release-v4.5.1 ran in 1000ms.

Test_kustomize/kust-issue-2808/kustomize/branch-master (0.13s)
kustomize_test.go:182: Runtime variation (0.13x): branch-master ran in 131ms; release-v4.5.1 ran in 1010ms.

Test_kustomize/kust-issue-2907/kustomize/branch-master (0.14s)
kustomize_test.go:182: Runtime variation (0.14x): branch-master ran in 138ms; release-v4.5.1 ran in 1022ms.

Test_kustomize/kust-issue-2987/kustomize/branch-master (0.13s)
kustomize_test.go:182: Runtime variation (0.13x): branch-master ran in 128ms; release-v4.5.1 ran in 997ms.

Test_kustomize/kust-issue-3157/kustomize/branch-master (0.14s)
kustomize_test.go:182: Runtime variation (0.13x): branch-master ran in 137ms; release-v4.5.1 ran in 1015ms.

Test_kustomize/kust-issue-3419/kustomize/branch-master (0.14s)
kustomize_test.go:182: Runtime variation (0.14x): branch-master ran in 135ms; release-v4.5.1 ran in 982ms.

@alexdyas
Copy link

Thanks @natasha41575!

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
6 participants