Skip to content

Commit b5d12aa

Browse files
authored
Merge pull request #8010 from Turbo87/cdn-logs
Implement CDN log file parsers
2 parents 6031a24 + c5fd445 commit b5d12aa

24 files changed

+1393
-0
lines changed

Cargo.lock

Lines changed: 177 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates_io_cdn_logs/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "crates_io_cdn_logs"
3+
version = "0.0.0"
4+
license = "MIT OR Apache-2.0"
5+
edition = "2021"
6+
7+
[lints]
8+
workspace = true
9+
10+
[dependencies]
11+
anyhow = "=1.0.79"
12+
async-compression = { version = "=0.4.6", features = ["gzip", "tokio", "zstd"] }
13+
chrono = { version = "=0.4.33", features = ["serde"] }
14+
percent-encoding = "=2.3.1"
15+
semver = "=1.0.21"
16+
serde = { version = "=1.0.196", features = ["derive"] }
17+
serde_json = "=1.0.113"
18+
tokio = { version = "=1.35.1", features = ["io-util"] }
19+
tracing = "=0.1.40"
20+
21+
[dev-dependencies]
22+
claims = "=0.7.1"
23+
clap = { version = "=4.4.18", features = ["derive"] }
24+
criterion = { version = "=0.5.1", features = ["async_tokio"] }
25+
insta = "=1.34.0"
26+
tokio = { version = "=1.35.1", features = ["fs", "macros", "rt", "rt-multi-thread"] }
27+
tracing-subscriber = { version = "=0.3.18", features = ["env-filter"] }
28+
29+
[[bench]]
30+
name = "count_downloads"
31+
harness = false

crates_io_cdn_logs/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
crates_io_cdn_logs
2+
===============================================================================
3+
4+
This package contains code to parse the log files from the crates.io CDNs
5+
(AWS CloudFront and Fastly) and to count how often crates/versions are
6+
downloaded each day.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crates_io_cdn_logs::{cloudfront, fastly};
2+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
3+
use std::io::Cursor;
4+
5+
fn criterion_benchmark(c: &mut Criterion) {
6+
let rt = tokio::runtime::Builder::new_current_thread()
7+
.enable_all()
8+
.build()
9+
.unwrap();
10+
11+
let bytes = include_bytes!("../test_data/cloudfront/basic.log");
12+
c.bench_function("cloudfront", |b| {
13+
// Insert a call to `to_async` to convert the bencher to async mode.
14+
// The timing loops are the same as with the normal bencher.
15+
b.to_async(&rt)
16+
.iter(|| cloudfront::count_downloads(black_box(Cursor::new(bytes))));
17+
});
18+
19+
let bytes = include_bytes!("../test_data/fastly/basic.log");
20+
c.bench_function("fastly", |b| {
21+
// Insert a call to `to_async` to convert the bencher to async mode.
22+
// The timing loops are the same as with the normal bencher.
23+
b.to_async(&rt)
24+
.iter(|| fastly::count_downloads(black_box(Cursor::new(bytes))));
25+
});
26+
}
27+
28+
criterion_group!(benches, criterion_benchmark);
29+
criterion_main!(benches);

0 commit comments

Comments
 (0)