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

Feat: optimize empty patch request #5600

Merged

Conversation

Somefive
Copy link
Collaborator

@Somefive Somefive commented Mar 3, 2023

Description of your changes

Enhance performance by reducing reconcile time from 56ms to 44ms, ~20% optimization.

image
image

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Special notes for your reviewer

@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Patch coverage: 85.71% and project coverage change: -16.31 ⚠️

Comparison is base (76a8d13) 61.56% compared to head (6f0825e) 45.25%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5600       +/-   ##
===========================================
- Coverage   61.56%   45.25%   -16.31%     
===========================================
  Files         311      274       -37     
  Lines       48018    41176     -6842     
===========================================
- Hits        29561    18636    -10925     
- Misses      15391    20822     +5431     
+ Partials     3066     1718     -1348     
Flag Coverage Δ
apiserver-e2etests ?
apiserver-unittests ?
core-unittests 55.66% <71.42%> (+0.01%) ⬆️
e2e-multicluster-test 18.92% <85.71%> (-0.07%) ⬇️
e2e-rollout-tests 21.60% <85.71%> (+0.08%) ⬆️
e2etests 27.15% <85.71%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ller/core.oam.dev/v1alpha2/application/revision.go 71.98% <ø> (ø)
pkg/utils/apply/patch.go 68.75% <50.00%> (-1.07%) ⬇️
...dev/v1alpha2/application/application_controller.go 85.04% <100.00%> (+0.90%) ⬆️
pkg/utils/apply/apply.go 86.87% <100.00%> (+0.14%) ⬆️
pkg/apiserver/utils/version.go 0.00% <0.00%> (-100.00%) ⬇️
pkg/apiserver/domain/service/tags.go 0.00% <0.00%> (-100.00%) ⬇️
pkg/apiserver/utils/cache.go 0.00% <0.00%> (-95.00%) ⬇️
...kg/apiserver/interfaces/api/assembler/v1/do2dto.go 0.00% <0.00%> (-91.67%) ⬇️
pkg/apiserver/domain/service/service.go 0.00% <0.00%> (-91.43%) ⬇️
pkg/apiserver/utils/http.go 0.00% <0.00%> (-88.89%) ⬇️
... and 129 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Somefive Somefive force-pushed the feat/optimize-empty-patch-request branch 5 times, most recently from 5a9ce71 to 058beb3 Compare March 6, 2023 04:57
@Somefive Somefive marked this pull request as ready for review March 6, 2023 05:22
if patch == nil {
return true
}
data, _ := patch.Data(nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why pass a nil into the patch.Data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because that is the interface parameter. The generated patch already contain data.
Reference

  1. https://github.com/kubernetes-sigs/controller-runtime/blob/cd0058ad295c268da1e7233e609a9a18dd60b5f6/pkg/client/patch.go#L48
  2. return client.RawPatch(patchType, patchData), nil

@@ -632,3 +640,16 @@ func (r *Reconciler) matchControllerRequirement(app *v1beta1.Application) bool {
}
return true
}

const (
originalAppKey contextKey = "original-app"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
originalAppKey contextKey = "original-app"
originalAppKey contextKey = "original-app-obj"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored to use iota.

originalAppKey contextKey = "original-app"
)

func withOriginalApp(ctx context.Context, app *v1beta1.Application) context.Context {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make this function to be a method of ctrlrec.NewReconcileContext

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NewReconcileContext is not only used for application controller. It is used for all KubeVela eco-system controllers.

@Somefive Somefive force-pushed the feat/optimize-empty-patch-request branch from 058beb3 to 57939a1 Compare March 6, 2023 05:39

const (
// ComponentNamespaceContextKey is the key in context that defines the override namespace of component
ComponentNamespaceContextKey contextKey = iota
Copy link
Collaborator

@wonderflow wonderflow Mar 6, 2023

Choose a reason for hiding this comment

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

will it be overriden by context[0] = "other-thing"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. There is no int key 0. It will be pkg/controller/core.oam.dev/v1alpha2/application:contextKey(0).

@Somefive Somefive force-pushed the feat/optimize-empty-patch-request branch from 57939a1 to cc7959c Compare March 6, 2023 13:12
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
@Somefive Somefive force-pushed the feat/optimize-empty-patch-request branch from cc7959c to 6f0825e Compare March 6, 2023 13:45
@Somefive Somefive merged commit d60bb62 into kubevela:master Mar 7, 2023
@Somefive Somefive deleted the feat/optimize-empty-patch-request branch March 7, 2023 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants