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: expire unused assets in [site] uploads #587

Merged
merged 1 commit into from
Mar 17, 2022

Conversation

threepointone
Copy link
Contributor

@threepointone threepointone commented Mar 13, 2022

This expires any previously uploaded assets when using a Sites / [site] configuration. Because we currently do a full iteration of a namespace's keys when publishing, for rapidly changing sites this means that uploads get slower and slower. We can't just delete unused assets because it leads to occasional 404s on older publishes while we're publishing. So we expire previous assets while uploading new ones. The implementation/constraints of the kv api means that uploads may become slower, but should hopefully be faster overall. These optimisations also only matter for rapidly changing sites, so common usecases still have the same perf characteristics.


I've started this PR as a discussion point, to discuss tradeoffs of the approach, and to make the constraints apparent before we move ahead with this. // @jgentes @koeninger

Closes #459

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2022

🦋 Changeset detected

Latest commit: 840c237

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/1998676775/npm-package-wrangler-587

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/587/npm-package-wrangler-587

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/1998676775/npm-package-wrangler-587 dev path/to/script.js

toExpire.map(async (asset) => ({
...asset,
// it would be great if we didn't have to do this fetch at all
value: await getKeyValue(accountId, namespace, asset.key),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to update a value's expiration time without having to fetch and send back the value? This is currently the most expensive part of this strategy.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be ideal if the bulk:kv PUT API did not update values if the value property is missing.
Then we could do this whole update (additions and expirations) in one go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koeninger thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koeninger if this looks fine to you, and there's no additional APIs that can be provided, we'll land this and backport to wrangler 1.x.

Choose a reason for hiding this comment

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

There's nothing different about bulk api in terms of efficiency, it's just a wrapper around multiple individual writes. There's not a way to update expiration without a write.

@threepointone threepointone changed the title WIP feat: expire unused assets in [site] uploads feat: expire unused assets in [site] uploads Mar 17, 2022
@threepointone threepointone marked this pull request as ready for review March 17, 2022 03:13
@threepointone
Copy link
Contributor Author

Opening this up for review, but we'll wait for @koeninger to have a look before we land it

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Just a couple of worries about expiration value and how it is tested.
Otherwise looking great!

packages/wrangler/src/sites.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/publish.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/helpers/mock-kv.ts Outdated Show resolved Hide resolved
@threepointone threepointone force-pushed the expire-unused-assets branch 2 times, most recently from 10c5d78 to 7670bec Compare March 17, 2022 12:19

describe("expire assets", () => {
// it's a 100 seconds past epoch
// everyone's still talking about how great woodstock was
Copy link
Contributor

Choose a reason for hiding this comment

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

🤣

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Smashing!

packages/wrangler/src/__tests__/publish.test.ts Outdated Show resolved Hide resolved
packages/wrangler/src/__tests__/publish.test.ts Outdated Show resolved Hide resolved
@threepointone
Copy link
Contributor Author

I'll wait for a few more hours for @koeninger to have a look; but if he's not around I'll merge this so we can take it for a spin regardless, and he can drop his thoughts whenever.

This expires any previously uploaded assets when using a Sites / `[site]` configuration. Because we currently do a full iteration of a namespace's keys when publishing, for rapidly changing sites this means that uploads get slower and slower. We can't just delete unused assets because it leads to occasional 404s on older publishes while we're publishing. So we expire previous assets while uploading new ones. The implementation/constraints of the kv api means that uploads may become slower, but should hopefully be faster overall. These optimisations also only matter for rapidly changing sites, so common usecases still have the same perf characteristics.
@threepointone
Copy link
Contributor Author

merging, we can review later. I want to actually try it out over the weekend.

@threepointone threepointone merged commit 49869a3 into main Mar 17, 2022
@threepointone threepointone deleted the expire-unused-assets branch March 17, 2022 13:15
@github-actions github-actions bot mentioned this pull request Mar 17, 2022
console.log(`expiring unused ${asset.name}...`);
toExpire.push({
key: asset.name,
value: "", // we'll fill all the values in one go

Choose a reason for hiding this comment

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

Is there any way someone is relying on metadata associated with those keys?

mrbbot added a commit that referenced this pull request Oct 31, 2023
* Use Node's root certificates on Windows

`workerd`'s `trustBrowserCas` uses `SSL_CTX_set_default_verify_paths()`
to enable the system trust store. Unfortunately, this doesn't work on
Windows, meaning any HTTPS `fetch()` would fail, with an
`unable to get local issuer certificate` error.

This change passes the root certificates from Node's bundled CA store
to `workerd` as `trustedCertificates` on Windows.

Closes #3264

* Read extra trusted certificates from `NODE_EXTRA_CA_CERTS`

Wrangler passes the Cloudflare root certificate using the
`NODE_EXTRA_CA_CERTS` environment variable. This change loads CA
certs from this variable, fixing HTTPS `fetch()`s with WARP enabled.
This can also be used for trusting self-signed certificates.

Closes #3218
mrbbot added a commit that referenced this pull request Nov 1, 2023
* Use Node's root certificates on Windows

`workerd`'s `trustBrowserCas` uses `SSL_CTX_set_default_verify_paths()`
to enable the system trust store. Unfortunately, this doesn't work on
Windows, meaning any HTTPS `fetch()` would fail, with an
`unable to get local issuer certificate` error.

This change passes the root certificates from Node's bundled CA store
to `workerd` as `trustedCertificates` on Windows.

Closes #3264

* Read extra trusted certificates from `NODE_EXTRA_CA_CERTS`

Wrangler passes the Cloudflare root certificate using the
`NODE_EXTRA_CA_CERTS` environment variable. This change loads CA
certs from this variable, fixing HTTPS `fetch()`s with WARP enabled.
This can also be used for trusting self-signed certificates.

Closes #3218
mrbbot added a commit that referenced this pull request Nov 1, 2023
* Use Node's root certificates on Windows

`workerd`'s `trustBrowserCas` uses `SSL_CTX_set_default_verify_paths()`
to enable the system trust store. Unfortunately, this doesn't work on
Windows, meaning any HTTPS `fetch()` would fail, with an
`unable to get local issuer certificate` error.

This change passes the root certificates from Node's bundled CA store
to `workerd` as `trustedCertificates` on Windows.

Closes #3264

* Read extra trusted certificates from `NODE_EXTRA_CA_CERTS`

Wrangler passes the Cloudflare root certificate using the
`NODE_EXTRA_CA_CERTS` environment variable. This change loads CA
certs from this variable, fixing HTTPS `fetch()`s with WARP enabled.
This can also be used for trusting self-signed certificates.

Closes #3218
mrbbot added a commit that referenced this pull request Nov 1, 2023
* Use Node's root certificates on Windows

`workerd`'s `trustBrowserCas` uses `SSL_CTX_set_default_verify_paths()`
to enable the system trust store. Unfortunately, this doesn't work on
Windows, meaning any HTTPS `fetch()` would fail, with an
`unable to get local issuer certificate` error.

This change passes the root certificates from Node's bundled CA store
to `workerd` as `trustedCertificates` on Windows.

Closes #3264

* Read extra trusted certificates from `NODE_EXTRA_CA_CERTS`

Wrangler passes the Cloudflare root certificate using the
`NODE_EXTRA_CA_CERTS` environment variable. This change loads CA
certs from this variable, fixing HTTPS `fetch()`s with WARP enabled.
This can also be used for trusting self-signed certificates.

Closes #3218
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.

feat: expire unused assets with [site]
4 participants