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(http): Etag support #22302

Merged
merged 12 commits into from May 25, 2023
Merged

Conversation

zharinov
Copy link
Collaborator

@zharinov zharinov commented May 18, 2023

Changes

  • Integrate ETag support into http API

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@zharinov zharinov requested review from viceice and rarkins May 18, 2023 15:56
lib/util/http/index.ts Outdated Show resolved Hide resolved
@zharinov zharinov marked this pull request as draft May 18, 2023 16:12
lib/util/http/bitbucket.ts Outdated Show resolved Hide resolved
lib/util/http/index.spec.ts Outdated Show resolved Hide resolved
lib/util/http/index.ts Outdated Show resolved Hide resolved
lib/util/http/index.ts Outdated Show resolved Hide resolved
@zharinov zharinov requested a review from viceice May 18, 2023 17:50
@zharinov zharinov marked this pull request as ready for review May 18, 2023 18:58
@rarkins
Copy link
Collaborator

rarkins commented May 19, 2023

Does this now return the previous/existing response in the body with a 304?

What's the use case for this?

In npm for example, where etags are already successfully used, we don't cache the raw http body response. We cache the getPkgReleases response.

@zharinov
Copy link
Collaborator Author

Does this now return the previous/existing response in the body with a 304?

In npm for example, where etags are already successfully used, we don't cache the raw http body response. We cache the getPkgReleases response.

I am refactoring this Npm code to make all the data transformation to be performed inside the zod schema. Raw response will be parsed by schema inside http call, so res.body for http.getJson(url, schema) will contain ReleaseResult instead of npm-specific format. Subsequent runs of http.getJson(url, { etagCache }, schema) will bypass schema-driven parsing and return etagCache.data that was previously cached.

It won't protect us from malformed data from cache (since we skip the validation/transform), but type system will require us to have ReleaseResult in the etagCache.data field.

What's the use case for this?

I want to use it for long-term caching of https://rubygems.org/api/v1/versions/$package.json endpoint since we want rubygems datasource to return metadata. Once properly cached (and throttled), I don't see any benefits of dealing with /versions endpoint and the complexities it adds.

@rarkins
Copy link
Collaborator

rarkins commented May 19, 2023

I'm not sure you'll be able to drop /versions because we will be too slow if we stick to rate limits. Are you assuming that 304 won't count towards rate limit?

lib/util/http/index.ts Outdated Show resolved Hide resolved
lib/util/http/index.ts Show resolved Hide resolved
@zharinov zharinov requested a review from viceice May 19, 2023 08:32
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

I think we should move the paginate logic to the getJson function, as it's the only one which will work anyways.

@zharinov zharinov requested a review from viceice May 19, 2023 12:32
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

LGTM beside the open discussion

@zharinov zharinov requested a review from viceice May 20, 2023 06:07
@zharinov zharinov requested review from rarkins and viceice May 25, 2023 11:46
@zharinov
Copy link
Collaborator Author

Please merge this one, it's blocker for me

@rarkins rarkins enabled auto-merge May 25, 2023 12:17
@rarkins rarkins added this pull request to the merge queue May 25, 2023
Merged via the queue into renovatebot:main with commit 290b78d May 25, 2023
11 checks passed
@rarkins rarkins deleted the feat/http-etag-support branch May 25, 2023 12:38
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 35.101.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants