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

chore: rate limit modal and auto login #22

Merged
merged 15 commits into from
May 5, 2024

Conversation

Keyrxng
Copy link
Contributor

@Keyrxng Keyrxng commented Mar 3, 2024

Resolves #20

  • with tasks and no user we display the login rate limit
  • With no tasks and no user we display the login rate limit
  • with no tasks and a user we force another login (logging in required a fresh to fetch the issues, this prevents that manual refresh)
  • with tasks and a user we display an alternative rate limit message
  • added a new env var for SUPABASE_REF and a little helper so it's easier for the likes of myself

I tried to debug why the issues wouldn't load first attempt after logging in following being rate limited but couldn't see why. I presume it's to do with token storage as you clearly see the auth token being handled in the URL.

I couldn't QA for being limited while auth'd for obv reasons but all bases are covered

@0x4007
Copy link
Member

0x4007 commented Mar 4, 2024

I couldn't QA for being limited while auth'd for obv reasons but all bases are covered

You just need to refresh ~80 times within an hour assuming 30 tasks. I was able to hit these limits while developing the UI.

Each "task" that is loaded invokes three requests: 1. the preview 2. the full details 3. sometimes, the image (although i have caching for this)

.env.example Outdated Show resolved Hide resolved
cypress/e2e/devpool.cy.ts Outdated Show resolved Hide resolved
@Keyrxng
Copy link
Contributor Author

Keyrxng commented Mar 4, 2024

Me trying to get rate limited spamming refresh and calling fetchAndDisplayPreviewsFromCache() & fetchIssuesFull() x30 lmao

image

I'm seeing no success so I check my rate limit remaining in a separate script, still 5K.

image

Running it down for QA sake but I'm amazed you were able to hit that locally, I had cache logic disabled and was clearing browser cache every run or two

@0x4007
Copy link
Member

0x4007 commented Mar 4, 2024

It must have been from before I implemented cache then. If it's really not going down due to cache then I'd say don't worry about it anymore.

@Keyrxng
Copy link
Contributor Author

Keyrxng commented Mar 4, 2024

Found two scenarios

  1. The auth provider can't be reached and returns an error instead of the auth token into the url
  2. You get the API rate limit exceeded for user ID 106.... If you reach out to GitHub Support for help, ...

Got the first one maxing it the first time, then number two the second time.

I'd say it's very unlikely to happen but I've added a notice for them anyway.

The getNewSessionToken() error handling isn't very robust but I wasn't sure whether to log any error into the modal or be explicit with them Error getting user profile from external provider could be a number of things I suppose

@gentlementlegen
Copy link
Member

The rate limited cases can be very easily simulated within Cypress by intercepting routes and sending back the appropriate response. It should help you develop and test these cases without having to really spam the endpoint. Also, would be nice to see these testing cases implemented.

@Keyrxng
Copy link
Contributor Author

Keyrxng commented Mar 12, 2024

The rate limited cases can be very easily simulated within Cypress by intercepting routes and sending back the appropriate response. It should help you develop and test these cases without having to really spam the endpoint. Also, would be nice to see these testing cases implemented.

Makes sense. I'm not as exp with testing as you seem to be and my default is usually: mocking requires pre-knowledge of what's going to happen for a fact, as opposed to simulating a response I never knew existed and even if I do know it exists, mocking it sort of defeats the purpose lmao probs a naïve outlook and why I'm not so great with writing them. Always happy to learn and improve but so

As part of this PR would you like me to add in test cases to cover what I've done here? @FernandVEYRIER

@gentlementlegen
Copy link
Member

The rate limited cases can be very easily simulated within Cypress by intercepting routes and sending back the appropriate response. It should help you develop and test these cases without having to really spam the endpoint. Also, would be nice to see these testing cases implemented.

Makes sense. I'm not as exp with testing as you seem to be and my default is usually: mocking requires pre-knowledge of what's going to happen for a fact, as opposed to simulating a response I never knew existed and even if I do know it exists, mocking it sort of defeats the purpose lmao probs a naïve outlook and why I'm not so great with writing them. Always happy to learn and improve but so

As part of this PR would you like me to add in test cases to cover what I've done here? @FernandVEYRIER

There are JSON example responses in the docs, they don't include failed cases but for each route you have the return codes, which I believe should suffice. That would be really great to have some test for sure!

@Keyrxng
Copy link
Contributor Author

Keyrxng commented Mar 12, 2024

Not a problem, will get on this today

@ubiquity-os-deployer
Copy link

ubiquity-os-deployer bot commented Mar 13, 2024

@gentlementlegen gentlementlegen self-requested a review March 13, 2024 05:55
cypress/e2e/devpool.cy.ts Outdated Show resolved Hide resolved
Co-authored-by: Mentlegen <9807008+gentlementlegen@users.noreply.github.com>
src/home/fetch-github/fetch-issues-preview.ts Outdated Show resolved Hide resolved
src/home/getters/get-github-user.ts Outdated Show resolved Hide resolved
src/home/rendering/render-github-login-button.ts Outdated Show resolved Hide resolved
const resetParsed = rate.reset && new Date(rate.reset * 1000).toLocaleTimeString();

if (!rate.user) {
rateLimitModal(`You have been rate limited. Please log in to GitHub to increase your GitHub API limits, otherwise you can try again at ${resetParsed}.`);
Copy link
Member

Choose a reason for hiding this comment

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

Does this take the UTC into account when displayed?

Copy link
Member

@0x4007 0x4007 Apr 8, 2024

Choose a reason for hiding this comment

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

.toLocaleTimeString();

It uses local time. This is relevant for the user, and in my testing, it is accurate.

Just realized, this pull needs to be rebased/reopened. Pretty sure this is my code from a long time ago that's already in production.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code is similar I guess but this pr is up to date with development if that's where prod is running from

Copy link
Member

@gentlementlegen gentlementlegen left a comment

Choose a reason for hiding this comment

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

Good to go when @pavlovcik is

src/home/getters/get-github-user.ts Show resolved Hide resolved
return response.data;
} catch (error) {
if (error instanceof RequestError && error.status === 403) {
await handleRateLimit(providerToken ? octokit : undefined, error);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await handleRateLimit(providerToken ? octokit : undefined, error);
await handleRateLimit(providerToken ?? octokit, error);

Is this more concise?

Copy link
Contributor Author

@Keyrxng Keyrxng Apr 9, 2024

Choose a reason for hiding this comment

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

Although if there is a providerToken and we get an error it'll pass providerToken as an arg instead of octokit which would mean rebuilding octokit within handleRateLimit() while both invocations of handleRateLimit() already have octokit built, one is guaranteed to have a provider token and this one in question is not.

If we make this more concise we litter the rate limit function

I guess if(typeof octokit == "string") would work instead of if(octokit){}else{} but typing octokit as string seemed daft when it first popped into my head 😂

@Keyrxng
Copy link
Contributor Author

Keyrxng commented Apr 23, 2024

Can this be merged? @0x4007 @gentlementlegen

@gentlementlegen gentlementlegen requested a review from 0x4007 April 25, 2024 03:40
@gentlementlegen gentlementlegen merged commit 2672cbf into ubiquity:development May 5, 2024
1 check passed
ghost pushed a commit to ariesgun/work.ubq.fi that referenced this pull request Oct 13, 2024
…lt-conf

feat: cypress default configuration
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.

GitHub Rate Limiting Modal on Load
3 participants