-
Notifications
You must be signed in to change notification settings - Fork 146
Clean up build-time API calls to Open Processing #831
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
Comments
Hi @ksen0, tagging you for visibility! Let me know what you think |
Hey thanks @clairep94 ! Looking into it, will report back. Edited to add: besides asking to change OP rate-limit, we can also potentially consider splitting build step so that fetching from OP API is not required for every single PR, but rather only when building main or dev-2.0 |
Hello 👋,
Looking at how the data is being used, I think it can be optimized to just use api/curation/sketches endpoint, as it contains all the data you need (including sketch and user metadata). I understand that p5js.org/sketches/[id] endpoint uses /api/sketch endpoint. To optimize this, you can lookup the initial curation/sketches data to find sketch metadata instead of making a new call to the API. Not sure where "sketch/code" is used, as you are using iframes instead of rebuilding the whole sketch. Note that, this /code endpoint will require more strict authentication soon, to prevent webscraping efforts, etc. Possibly Bear Token. Otherwise, I can also add specific IPs to whitelist to prevent rateLimiting, however that's not my preference, as some wrong code may hog the OP server and we wouldn't want that 😄... |
Thank you @msawired ! I agree that solutions that do not require changing rate limit should be fully investigated first and looks like removing the use of Potentially we can do temporary whitelisting to unblock merging, but I do think changing rate limit even temporarily can create more problems by accident, and I don't see critical PRs in the pipeline. So if this can be resolved n a few days, I think that could be alright. @clairep94 what do you think / do you want to work on the fix? |
Hi both happy to work on the fix for the refactor! Will probably have some time this weekend I think we might need to update
@msawired would it be possible to add the following properties to items returned by the curation endpoint?
|
@clairep94 thank you for working on this! That's a good point that some information is missing. Do you think a temporary fix would be possible of e.g., building in a pause to stay under 40 requests/min? Or if removing Though it would be good if the What do you think? |
yes I can add those data points. |
Will have something for review likely tomorrow, thanks both :) |
The requests are happening on build so I guess we can consider it "backend"? It will run on each build and that includes all CI build step on each PR. It doesn't run on the built site served to users as the requested data are already built into the site. @msawired One thing I'm thinking, not sure if there already is something like this already is a bulk request endpoint, so that we can pass a list of sketch ID and OP's API can return all the required data all in one round of request. That way we reduce the number of overall requests and it might be easier on your end for db queries as well if you can group that into one query too. We don't have to do it for this round of fix and can implement this later. @clairep94 I think you all have a good handle on this and I'm just chiming in to confirm the above, but do ping me whenever if you need any clarifications or help. |
Hi @ksen0 @msawired @limzykenneth I have opened a PR to resolve the pipeline block here: I looked into removing the call to If Otherwise, if @msawired sorry to bother again!
The current PR 838 should unblock merging any open PRs, but I'll make a followup PR to do the optimisation to eliminate the call to
|
I don't extract width/height so no information is available for that. I may recommend to set the iframe full width and height fixed (or as tall as possible, such as 80vh). The iframe should then center the sketch if possible, smaller than windowWidth/windowHeight. |
@msawired Would it be possible to also add
Really appreciate your responsiveness! This is my first open source contribution so I appreciate the feedback |
One of the reasons why we detect the width/height is so we can change how scaling works on those sketches. On mobile, a fixed sized sketch like 800x600 will require scrolling within the iframe to see the whole thing. If we detect those cases though, we make a fixed-size iframe that we scale up or down with CSS to make sure mobile viewers still see the whole thing by default. I also think the width/height probably won't ever be part of the API because it's just a heuristic right now -- to do it properly we'd have to actually evaluate the code. There's possibly a world where at runtime, the sketch communicates the size info up to its parent window, but that also isn't super easy to do, so our current solution is to try to catch simple cases via code parsing. Anyway, using the default iframe would mean compromising on the mobile experience, but if there aren't other good ways to work around API limits then we can consider it to unblock builds. |
Ah ok, in that case maybe the changes on the PR as-is is sufficient? Builds will still make the call to |
Thank you for the fix @clairep94 ! I just merged it into main, looks great 💯 Do you have time to make the equivalent patch for the |
PS:
Great work! Please do feel free to add yourself to the p5.js all-contributors |
🙌 great to hear all is resolved. Do you still need license and fullname on the endpoints above? |
Thanks @ksen0! Happy to do the path for @msawired For the patch, since we don't have
For
|
Hi @clairep94 ! I happen to have a moment now and wanted to unblock a couple of PRs on 2.0, so I went ahead and copied the patch here: #842 (This was done by creating a new branch under 2.0, then running Please feel free to keep this issue around for the remaining improvements to OP re: license and full name. @msawired no rush on adding those (since the immediate patch is done), but seems like it would be helpful for a cleanup here. @clairep94 please feel free to update the name of this issue to be more descriptive of this cleanup of OP API usage? Regarding bearer auth: @msawired this would be great long-term! I think it's farther outside scope of this issue though. @clairep94 do you mind creating a new issue please, for updating website to use bear token when that has been implemented by @msawired ? If that sounds reasonable to you both. Big thanks to everyone on the thread for finding and resolving this issue! |
Sure, I will post it back here once the token implementation is live! |
Cleanup post-resolution of failed builds (edited on May 14th):
Following the patch-fix to resolve builds hitting OP rate limits and discussions around updates to the
api/sketch/[id]
andapi/curation/sketches
, there are a few follow-up tasks for final cleanup:getSketch
to removelicense: ''
from below:SketchLayout
andSketchesLayout
by removingauthorName
fromSketchLayout
propsUpdated issue (last edited May 5th):
After further investigating the original issue below, it seems that the source of PRs failing test in the past week is that when the static site
build
is happening, and the project is trying to fetch sketch-data from OpenProcessing API, it is hitting429 Too Many Requests
I've added error logging on data-fetching functions on PR #832, which still fail as expected, but show us the 429 status and error message below.
I have created a patch-fix solution on my fork here, which passes
tests/build
but we can see in the call-stack that after generating a certain amount of pages for individual sketches, we hit the limit on calls to OpenProcessing API again (please see PR details for screenshots & proposed solutions).This leads to me believe that the solution may be to copy this issue to the OpenProcessing API repo, which seems to be private, and see if the rate-limit can be raised by 25 hits/10 minutes when being hit for site-builds. I have also proposed a second solution on clairep94#2, which could greatly reduce the amount of hits to OpenProcessing API that a build requires, but which would require some refactoring on the website & update to the API spec for
getCurationSketches
Keen to hear everyone's thoughts!
Original Issue:
Potential bug with builds failing locally and on GHA when generating pages for some sketches
Most appropriate sections of the p5.js website?
Community (Sketches, Libraries, Events)
What is your operating system?
Mac OS
Web browser and version
Not an issue on the production site, but with
build
on GHA & locallyActual Behavior
I noticed that some PR's created in the last week have been failing on a similar error to below, and the changes in the PRs seem unrelated to the errors.
I tried to build from
main
locally and encountered the same error, but with varying sketch ids.I then tried to make a test PR with a nominal change (added a period in some homepage text), and encountered the same error, so potentially there may be something with the metadata of this sketch 2225254, or another source that is having a side-effect of this sketch page failing on build.
Expected Behavior
Build should not fail unless there is a breaking change on the branch
Test failures should vary between PRs given they are working on different issues
Steps to reproduce
npm run build
locally, or make PR into mainWould you like to work on the issue?
Happy to look into it further or have it be assigned
The text was updated successfully, but these errors were encountered: