Skip to content

Commit

Permalink
Merge pull request #8010 from Turbo87/cdn-logs
Browse files Browse the repository at this point in the history
Implement CDN log file parsers
  • Loading branch information
Turbo87 authored Jan 31, 2024
2 parents 6031a24 + c5fd445 commit b5d12aa
Show file tree
Hide file tree
Showing 24 changed files with 1,393 additions and 0 deletions.
177 changes: 177 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions crates_io_cdn_logs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "crates_io_cdn_logs"
version = "0.0.0"
license = "MIT OR Apache-2.0"
edition = "2021"

[lints]
workspace = true

[dependencies]
anyhow = "=1.0.79"
async-compression = { version = "=0.4.6", features = ["gzip", "tokio", "zstd"] }
chrono = { version = "=0.4.33", features = ["serde"] }
percent-encoding = "=2.3.1"
semver = "=1.0.21"
serde = { version = "=1.0.196", features = ["derive"] }
serde_json = "=1.0.113"
tokio = { version = "=1.35.1", features = ["io-util"] }
tracing = "=0.1.40"

[dev-dependencies]
claims = "=0.7.1"
clap = { version = "=4.4.18", features = ["derive"] }
criterion = { version = "=0.5.1", features = ["async_tokio"] }
insta = "=1.34.0"
tokio = { version = "=1.35.1", features = ["fs", "macros", "rt", "rt-multi-thread"] }
tracing-subscriber = { version = "=0.3.18", features = ["env-filter"] }

[[bench]]
name = "count_downloads"
harness = false
6 changes: 6 additions & 0 deletions crates_io_cdn_logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
crates_io_cdn_logs
===============================================================================

This package contains code to parse the log files from the crates.io CDNs
(AWS CloudFront and Fastly) and to count how often crates/versions are
downloaded each day.
29 changes: 29 additions & 0 deletions crates_io_cdn_logs/benches/count_downloads.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crates_io_cdn_logs::{cloudfront, fastly};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::io::Cursor;

fn criterion_benchmark(c: &mut Criterion) {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();

let bytes = include_bytes!("../test_data/cloudfront/basic.log");
c.bench_function("cloudfront", |b| {
// Insert a call to `to_async` to convert the bencher to async mode.
// The timing loops are the same as with the normal bencher.
b.to_async(&rt)
.iter(|| cloudfront::count_downloads(black_box(Cursor::new(bytes))));
});

let bytes = include_bytes!("../test_data/fastly/basic.log");
c.bench_function("fastly", |b| {
// Insert a call to `to_async` to convert the bencher to async mode.
// The timing loops are the same as with the normal bencher.
b.to_async(&rt)
.iter(|| fastly::count_downloads(black_box(Cursor::new(bytes))));
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Loading

0 comments on commit b5d12aa

Please sign in to comment.