Skip to content

Commit 6361e77

Browse files
committed
refactor(plus): extract Litestream into a shared bencher_litestream crate
Move the Litestream config types, YAML rendering, restore/replicate runtime, and the autocheckpoint PRAGMA out of bencher_json and the API server into a new Bencher Plus crate, plus/bencher_litestream, so the code can be shared by path with other consumers. - bencher_json re-exports the config types from the new crate at their existing paths and keeps the From<LogLevel> conversion, so the public API and the OpenAPI schema are unchanged. - services/api calls bencher_litestream::run_litestream, computing the database path, config path, and log level at the call site. - bencher_config uses bencher_litestream::DISABLE_AUTOCHECKPOINT_PRAGMA. The crate is feature-gated (yaml, runtime, schema) so config-only consumers stay light. The moved unit tests pass and cargo gen-spec / gen-ts produce no diff.
1 parent 7d99034 commit 6361e77

18 files changed

Lines changed: 844 additions & 717 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ bencher_github_client = { path = "plus/bencher_github_client" }
6161
bencher_google_client = { path = "plus/bencher_google_client" }
6262
bencher_google_index = { path = "plus/bencher_google_index" }
6363
bencher_license = { path = "plus/bencher_license" }
64+
bencher_litestream = { path = "plus/bencher_litestream" }
6465
bencher_otel = { path = "plus/bencher_otel" }
6566
bencher_otel_provider = { path = "plus/bencher_otel_provider" }
6667
bencher_oci_storage = { path = "plus/bencher_oci_storage" }

docker/bench.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ RUN cargo init --lib bencher_recaptcha
6363
RUN cargo init --lib bencher_rootfs
6464
RUN cargo init --lib bencher_runner
6565
RUN cargo init --lib bencher_init
66+
COPY plus/bencher_litestream bencher_litestream
6667

6768
WORKDIR /usr/src/bencher/tasks
6869
RUN cargo init --bin bin_version

lib/bencher_config/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ default = []
1111
plus = [
1212
"dep:bencher_github_client",
1313
"dep:bencher_google_client",
14+
"dep:bencher_litestream",
1415
"dep:bencher_oci_storage",
1516
"bencher_billing/plus",
1617
"bencher_endpoint/plus",
@@ -30,6 +31,7 @@ bencher_github_client = { workspace = true, optional = true }
3031
bencher_google_client = { workspace = true, optional = true }
3132
bencher_json.workspace = true
3233
bencher_license = { workspace = true, optional = true }
34+
bencher_litestream = { workspace = true, optional = true }
3335
bencher_oci_storage = { workspace = true, optional = true }
3436
bencher_rbac.workspace = true
3537
bencher_recaptcha = { workspace = true, optional = true }

lib/bencher_config/src/config_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn run_litestream(database: &mut DbConnection) -> Result<(), ConfigTxError> {
419419
// https://litestream.io/tips/#disable-autocheckpoints-for-high-write-load-servers
420420
// https://sqlite.org/wal.html#automatic_checkpoint
421421
database
422-
.batch_execute("PRAGMA wal_autocheckpoint = 0")
422+
.batch_execute(bencher_litestream::DISABLE_AUTOCHECKPOINT_PRAGMA)
423423
.map_err(ConfigTxError::Pragma)?;
424424

425425
Ok(())

lib/bencher_json/Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ default = []
1111
client = ["bencher_context/client", "bencher_valid/client"]
1212
table = ["dep:tabled"]
1313
server = ["bencher_context/server", "bencher_valid/server"]
14-
schema = ["dep:schemars", "bencher_context/schema", "ordered-float/schemars"]
15-
db = ["dep:diesel", "dep:serde_yaml", "bencher_valid/db"]
16-
plus = ["dep:camino", "bencher_valid/plus"]
14+
schema = [
15+
"dep:schemars",
16+
"bencher_context/schema",
17+
"ordered-float/schemars",
18+
"bencher_litestream?/schema",
19+
]
20+
db = ["dep:diesel", "bencher_valid/db", "bencher_litestream?/yaml"]
21+
plus = ["dep:camino", "dep:bencher_litestream", "bencher_valid/plus"]
1722
test-clock = ["bencher_valid/test-clock"]
1823

1924
[dependencies]
2025
bencher_context.workspace = true
26+
bencher_litestream = { workspace = true, optional = true }
2127
bencher_valid = { workspace = true, features = ["schema"] }
2228
camino = { workspace = true, features = ["serde1"], optional = true }
2329
derive_more.workspace = true
@@ -28,15 +34,11 @@ schemars = { workspace = true, optional = true, features = ["chrono", "url"] }
2834
serde.workspace = true
2935
serde_json.workspace = true
3036
serde_urlencoded.workspace = true
31-
serde_yaml = { workspace = true, optional = true }
3237
tabled = { workspace = true, optional = true }
3338
thiserror.workspace = true
3439
typeshare.workspace = true
3540
url = { workspace = true, features = ["serde"] }
3641
uuid = { workspace = true, features = ["v4", "serde"] }
3742

38-
[dev-dependencies]
39-
pretty_assertions.workspace = true
40-
4143
[lints]
4244
workspace = true

lib/bencher_json/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub use bencher_valid::{
1717
#[cfg(feature = "schema")]
1818
use schemars::JsonSchema;
1919
use serde::{Deserialize, Serialize};
20-
#[cfg(all(not(feature = "plus"), feature = "db"))]
21-
use serde_yaml as _;
2220

2321
mod auth;
2422
pub mod big_int;

0 commit comments

Comments
 (0)