Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions crates/buzz-admin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,18 @@ enum ProductFeedbackCommand {
}

/// JSON log subscriber. Without `RUST_LOG`, it keeps warnings from the
/// operator's own crates and errors from everything else.
/// operator's own crates, the community deletion purge's per-batch progress,
/// and errors from everything else.
fn log_subscriber<W>(rust_log: Option<&str>, writer: W) -> impl tracing::Subscriber + Send + Sync
where
W: for<'w> tracing_subscriber::fmt::MakeWriter<'w> + Send + Sync + 'static,
{
tracing_subscriber::fmt()
.json()
.with_writer(writer)
.with_env_filter(tracing_subscriber::EnvFilter::new(
rust_log.unwrap_or("error,buzz_admin=warn,buzz_db=warn,buzz_deletion=warn"),
))
.with_env_filter(tracing_subscriber::EnvFilter::new(rust_log.unwrap_or(
"error,buzz_admin=warn,buzz_db=warn,buzz_db::store::deletion=info,buzz_deletion=warn",
)))
.finish()
}

Expand Down Expand Up @@ -983,8 +984,9 @@ mod tests {
use super::*;

/// The default subscriber writes the deletion executor's warnings, such
/// as a request blocked at claim, as one JSON record with their fields,
/// and drops other crates' warnings. RUST_LOG replaces the default.
/// as a request blocked at claim, and the purge's per-batch progress as
/// JSON records with their fields. It drops other buzz_db info and other
/// crates' warnings. RUST_LOG replaces the default.
#[test]
fn log_subscriber_writes_deletion_warnings_as_json() {
let emit = |rust_log: Option<&str>| -> Vec<serde_json::Value> {
Expand All @@ -996,20 +998,28 @@ mod tests {
blocked_reason = "catalog drift",
"community deletion request blocked at claim"
);
tracing::info!(target: "buzz_db::store::deletion", "below the default level");
tracing::info!(
target: "buzz_db::store::deletion",
rows = 5000,
elapsed_ms = 12,
"community deletion purge batch committed"
);
tracing::info!(target: "buzz_db::pool", "below the default level");
tracing::warn!(target: "sqlx::query", "another crate's warning");
});
logs.records()
};

let logged = emit(None);
assert_eq!(logged.len(), 1, "{logged:?}");
assert_eq!(logged.len(), 2, "{logged:?}");
assert_eq!(logged[0]["level"], "WARN");
assert_eq!(logged[0]["target"], "buzz_db::store::deletion");
assert_eq!(logged[0]["fields"]["request_id"], "request-1");
assert_eq!(logged[0]["fields"]["blocked_reason"], "catalog drift");
assert_eq!(logged[1]["level"], "INFO");
assert_eq!(logged[1]["fields"]["elapsed_ms"], 12);
assert!(emit(Some("off")).is_empty());
assert_eq!(emit(Some("info")).len(), 3);
assert_eq!(emit(Some("info")).len(), 4);
}

/// Log output captured from a test subscriber.
Expand Down
1 change: 0 additions & 1 deletion crates/buzz-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ metrics = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }
tracing-subscriber = { workspace = true }
metrics-util = { workspace = true }
tracing-subscriber = { workspace = true }
Loading
Loading