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

Cache github api requests in ApplicationSet #11376

Open
WillAbides opened this issue Nov 20, 2022 · 5 comments · May be fixed by #21309
Open

Cache github api requests in ApplicationSet #11376

WillAbides opened this issue Nov 20, 2022 · 5 comments · May be fixed by #21309
Labels
component:application-sets Bulk application management related enhancement New feature or request type:scalability Issues related to scalability and performance related issues

Comments

@WillAbides
Copy link
Contributor

Summary

Make the github api client used by ApplicationSet cache responses.

Motivation

Using an scm_provider generator with allBranches leads to a lot of queries to the GitHub API. This takes some time and eats through GitHub's rate limit.

We can save time and rate limit by caching responses and using the If-None-Match and If-Modified-Since headers to check whether the cached response is up to date. This is described in GitHub's api documentation here: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests

Proposal

I propose using https://github.com/gregjones/httpcache and https://github.com/die-net/lrucache to implement the cache. httpcache provides an http transport that does the header checks and wraps a cache. lrucache is an in-memory least-recently-used cache made to be used with httpcache. I have used this combination with the go-github client successfully other projects.

An environment variable ARGOCD_APPLICATIONSET_CONTROLLER_GITHUB_CLIENT_CACHE_SIZE can be added to set the cache size. If it is unset, no cache will be used. Otherwise an LRU cache will be created with the given size in kilobytes.

This is what the code might look like:

AWholeNewOrg@7516d64?w=1

@WillAbides WillAbides added the enhancement New feature or request label Nov 20, 2022
@crenshaw-dev crenshaw-dev added type:scalability Issues related to scalability and performance related issues component:application-sets Bulk application management related labels Dec 15, 2022
@crenshaw-dev
Copy link
Member

This seems like a good idea to me. Anything I can do to help move it forward?

@kaos
Copy link

kaos commented Feb 1, 2024

Using those libraries, does anyone know if they also implement backoff when hitting rate limits or other client side issues (4xx responses)?

@aburan28
Copy link

currently running into issues with rate limiting using scm generator and figure that I could work on implementing the httpcache if no one else is currently working on this

@aburan28
Copy link

aburan28 commented Sep 8, 2024

Would it be a good idea to use the redis deployment that the repo server uses to hold the cache of these requests? @crenshaw-dev

@aburan28
Copy link

Feel free to assign this issue over to me. I plan on working on this in early 2025

@aburan28 aburan28 linked a pull request Dec 24, 2024 that will close this issue
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:application-sets Bulk application management related enhancement New feature or request type:scalability Issues related to scalability and performance related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants