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: Process webhook refresh in background to not block the request (#14269) #18173

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

dhruvang1
Copy link
Contributor

@dhruvang1 dhruvang1 commented May 12, 2024

This PR moves the webhook processing for both Application and ApplicationSet to a goroutine. This would allow the server to quickly send HTTP 200 to the webhook request adhering to the quick response guidelines set by GitHub, GitLab, etc.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Fixes #14269

@dhruvang1 dhruvang1 requested a review from a team as a code owner May 12, 2024 01:10
@dhruvang1 dhruvang1 force-pushed the process-webhook-in-background branch 2 times, most recently from 81d564b to 409a7c2 Compare May 12, 2024 17:12
applicationset/webhook/webhook.go Outdated Show resolved Hide resolved
@dhruvang1 dhruvang1 force-pushed the process-webhook-in-background branch from 409a7c2 to 9533cd5 Compare June 15, 2024 19:25
@dhruvang1 dhruvang1 requested a review from a team as a code owner June 15, 2024 19:25
@dhruvang1 dhruvang1 force-pushed the process-webhook-in-background branch 2 times, most recently from a61c546 to f720109 Compare June 15, 2024 20:19
Copy link

codecov bot commented Jun 15, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 50.28%. Comparing base (1aeed6a) to head (5d4e308).
Report is 3 commits behind head on master.

Files Patch % Lines
applicationset/webhook/webhook.go 85.00% 3 Missing ⚠️
cmd/argocd-server/commands/argocd_server.go 0.00% 3 Missing ⚠️
util/webhook/webhook.go 83.33% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #18173      +/-   ##
==========================================
+ Coverage   50.25%   50.28%   +0.03%     
==========================================
  Files         315      315              
  Lines       43125    43162      +37     
==========================================
+ Hits        21671    21705      +34     
- Misses      18967    18976       +9     
+ Partials     2487     2481       -6     

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

@dhruvang1 dhruvang1 requested a review from gdsoumya June 17, 2024 16:07
@dhruvang1 dhruvang1 force-pushed the process-webhook-in-background branch 2 times, most recently from 92a549b to 498b5ee Compare June 21, 2024 06:21
@dhruvang1
Copy link
Contributor Author

@gdsoumya Could you take a re-look when you are available? It would be nice to merge the PR as a lot of folks, including us, are impacted by this issue.

Copy link
Member

@gdsoumya gdsoumya left a comment

Choose a reason for hiding this comment

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

LGTM, minor comments

@@ -241,6 +242,7 @@ func NewCommand() *cobra.Command {
command.Flags().StringVar(&scmRootCAPath, "scm-root-ca-path", env.StringFromEnv("ARGOCD_APPLICATIONSET_CONTROLLER_SCM_ROOT_CA_PATH", ""), "Provide Root CA Path for self-signed TLS Certificates")
command.Flags().StringSliceVar(&globalPreservedAnnotations, "preserved-annotations", env.StringsFromEnv("ARGOCD_APPLICATIONSET_CONTROLLER_GLOBAL_PRESERVED_ANNOTATIONS", []string{}, ","), "Sets global preserved field values for annotations")
command.Flags().StringSliceVar(&globalPreservedLabels, "preserved-labels", env.StringsFromEnv("ARGOCD_APPLICATIONSET_CONTROLLER_GLOBAL_PRESERVED_LABELS", []string{}, ","), "Sets global preserved field values for labels")
command.Flags().IntVar(&webhookParallelism, "webhook-parallelism-limit", env.ParseNumFromEnv("ARGOCD_APPLICATIONSET_CONTROLLER_WEBHOOK_PARALLELISM_LIMIT", 25, 1, 1000), "Number of webhook requests processed concurrently")
Copy link
Member

Choose a reason for hiding this comment

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

Might want to increase the default value and the max limit. 1000 limit might be small for some users. Also we should document this so that others are aware of this setting.

Copy link
Contributor Author

@dhruvang1 dhruvang1 Jun 21, 2024

Choose a reason for hiding this comment

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

1000 is set as max limit to avoid footguns. If a large setup has say 5K Applications, and each application is 4KB (from what I see), 1000 concurrent processing will use 5K * 4KB * 1K = 20GB of memory. I think that already is a very large number. If you still think its less, I can set it to more, maybe 5K or 10K?

Do you have any guidance on default values? I can set it to 50 or 100.

Also we should document this so that others are aware of this setting.

I have noted this flag in argocd-server.md. Could you point out where else would you like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gdsoumya I have updated the default to 50. I also see you are talking about AppSet flag documentation, but I don't see any obvious place to document this. Maybe in the appset webhook section in the git generator?

https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Git/#webhook-configuration

Copy link
Member

Choose a reason for hiding this comment

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

Adding to argocd-cmd-params-cm.yaml is good enough. Thanks!

…rgoproj#14269)

Signed-off-by: dhruvang1 <dhruvang1@users.noreply.github.com>
@dhruvang1 dhruvang1 force-pushed the process-webhook-in-background branch from 498b5ee to 5d4e308 Compare June 21, 2024 16:46
Copy link
Member

@gdsoumya gdsoumya left a comment

Choose a reason for hiding this comment

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

LGTM

@gdsoumya gdsoumya merged commit 95be90b into argoproj:master Jun 26, 2024
27 checks passed
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.

Too many applications causing webhook to timeout
2 participants