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

crates.io: Add support for download URLs without placeholders #365

Merged
merged 2 commits into from
Dec 7, 2023

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Nov 17, 2023

In https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/placeholders.20in.20index.20config.2Ejson I asked what cargo version added support for placeholders in the dl config field of the package index and apparently the answer is Rust 1.24.

In the future the crates.io team would like to move crate file downloads directly to the CDN, instead of them having to go through our own backend, since that has proven to be a somewhat problematic bottleneck. To be able to support earlier cargo versions, this PR introduces URL rewriting for /crates/:crate/:version/download requests for the CloudFront and Fastly CDNs.

This should allow us to change https://github.com/rust-lang/crates.io-index/blob/27423df2d3aecc0642d64eee2b321ffa1e6860ba/config.json#L2 to "dl": "https://static.crates.io/crates" in the future.

@Turbo87
Copy link
Member Author

Turbo87 commented Nov 17, 2023

side note: I've added a basic test case for the Fastly implementation, but the WASI target is making it somewhat difficult to test. if the target declarations in rust-toolchain.toml and .cargo/config are commented out the test will run on the host machine and appears to be passing without issues here.

Copy link
Member

@jdno jdno left a comment

Choose a reason for hiding this comment

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

Looks generally good, just the use of unwrap is something I'd like to fix or discuss.

terragrunt/modules/crates-io/compute-static/Cargo.toml Outdated Show resolved Hide resolved
let path = url.path();

if let Some(captures) = RE.captures(path) {
let krate = captures.name("crate").unwrap().as_str();
Copy link
Member

Choose a reason for hiding this comment

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

Unwrapping here seems dangerous. I'm not sure how much debugging information we'll get if we just fail hard. Instead, I think it is better to change the return type of the function to Result<(), Error> and handle the error gracefully. And if we log an error with error!, we'll get to see that in the service logs.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, can you think of a scenario where the unwrap would panic? the outer if let ensures that the regex matches and both of the captures are non-optional so I think unwrap is safe here for this regex 🤔

Copy link
Member

Choose a reason for hiding this comment

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

That's a good argument. I don't think this can panic in its current form, but I'm also somewhat paranoid about changes in the future and other people assuming, based on this example, that it's okay to unwrap in this binary.

@Turbo87 Turbo87 force-pushed the downloads-without-placeholders branch from c35d876 to f1c91c2 Compare December 5, 2023 20:44
Copy link
Member

@jdno jdno left a comment

Choose a reason for hiding this comment

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

I'm fine merging this as-is. Let me deploy it to staging so that we can smoketest the implementation before merging the pull request and deploying to production.

let path = url.path();

if let Some(captures) = RE.captures(path) {
let krate = captures.name("crate").unwrap().as_str();
Copy link
Member

Choose a reason for hiding this comment

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

That's a good argument. I don't think this can panic in its current form, but I'm also somewhat paranoid about changes in the future and other people assuming, based on this example, that it's okay to unwrap in this binary.

@jdno
Copy link
Member

jdno commented Dec 6, 2023

This is now live in staging. 🚀

@Turbo87
Copy link
Member Author

Turbo87 commented Dec 6, 2023

looks like it's working as intended. e.g. https://static.staging.crates.io/crates/crates-staging-test-tb/0.69.86/download

@jdno
Copy link
Member

jdno commented Dec 7, 2023

Seems to work on staging, so I'll merge this and deploy to production.

@Turbo87 Turbo87 force-pushed the downloads-without-placeholders branch from f1c91c2 to 456e3c7 Compare December 7, 2023 13:31
@Turbo87 Turbo87 force-pushed the downloads-without-placeholders branch from 456e3c7 to 2c6252e Compare December 7, 2023 13:38
@jdno
Copy link
Member

jdno commented Dec 7, 2023

We fixed a last issue with the use of let, which is not supported by the used runtime.

@jdno jdno merged commit 64d262c into rust-lang:master Dec 7, 2023
3 checks passed
jdno added a commit to jdno/rust-simpleinfra that referenced this pull request Dec 7, 2023
jdno added a commit that referenced this pull request Dec 7, 2023
@Turbo87 Turbo87 deleted the downloads-without-placeholders branch December 10, 2023 11:36
@jdno jdno mentioned this pull request Dec 11, 2023
8 tasks
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.

2 participants