Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ligustah committed May 3, 2024
1 parent b482c1f commit 470c84a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use tower::buffer::BufferLayer;
use tower::limit::RateLimitLayer;
use tower::{BoxError, ServiceBuilder};

const NO_METRICS_ENDPOINTS: [&str; 2] = ["/health", "/metrics"];

#[derive(Clone)]
pub struct AppState {
pub db: SqlitePool,
Expand Down Expand Up @@ -103,6 +105,10 @@ pub fn with_admin_routes(state: AppState, router: Router<AppState>) -> Router<Ap

pub async fn metrics_middleware(request: Request, next: Next) -> Response {
let path = request.uri().to_string();
if NO_METRICS_ENDPOINTS.contains(&path.as_str()) {
return next.run(request).await;
}

let start = SystemTime::now();
let resp = next.run(request).await;
let end = start
Expand Down
6 changes: 5 additions & 1 deletion src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ impl Controller {
.map(|_r| evaluation)
.wrap_err("Failed to store premint")
} else {
tracing::info!("Premint failed validation: {:?}", premint);
tracing::info!(
"Premint {:?} failed validation: {:?}",
premint.metadata().id,
evaluation.only_failures()
);
tracing::info!(histogram.rules_rejected = 1);

Err(evaluation).wrap_err("Premint failed validation")
Expand Down
15 changes: 13 additions & 2 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ impl Results {
.any(|r| matches!(r.result, Ok(Evaluation::Reject(_))))
}

pub fn only_failures(&self) -> Self {
Self(
self.0
.iter()
.filter(|r| r.result.is_err() || matches!(r.result, Ok(Evaluation::Reject(_))))
.cloned()
.collect(),
)
}

pub fn is_err(&self) -> bool {
self.0.iter().any(|r| r.result.is_err())
}
Expand Down Expand Up @@ -443,8 +453,9 @@ mod general {
Ok(Accept)
} else {
reject!(
"Existing premint with higher version {} exists",
existing.metadata().version
"Existing premint with version {} exists, trying to store version {}",
existing.metadata().version,
meta.version
)
}
}
Expand Down

0 comments on commit 470c84a

Please sign in to comment.