исправить: закрыть ревью критических ошибок
CI / Rust Checks (pull_request) Successful in 6m4s
CI / UI Checks (pull_request) Successful in 5s
CI / Community Image Smoke (pull_request) Successful in 4m27s
CI / Frontend E2E (pull_request) Successful in 5m19s
CI / Deploy (pull_request) Has been skipped
CI / Rust Checks (push) Successful in 6m5s
CI / UI Checks (push) Successful in 5s
CI / Community Image Smoke (push) Successful in 1m5s
CI / Frontend E2E (push) Successful in 3m54s
CI / Deploy (push) Failing after 45s

This commit is contained in:
2026-07-31 09:31:38 +03:00
parent 9b1a739e39
commit c30461cc92
7 changed files with 200 additions and 27 deletions
+11 -10
View File
@@ -21,6 +21,8 @@ use sqlx::postgres::PgConnectOptions;
use tokio::net::TcpListener;
use tracing::{info, warn};
const MAX_INVOCATION_LOG_RETENTION_DAYS: i64 = 36_500;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let observability = crank_observability::init(ObservabilityConfig::from_env(
@@ -106,8 +108,7 @@ async fn run(
.with_outbound_http_policy(outbound_http_policy)
.with_identity_provider(std::sync::Arc::new(identity_provider))
.build();
let invocation_log_retention_days =
positive_i64_from_env("CRANK_INVOCATION_LOG_RETENTION_DAYS", 30)?;
let invocation_log_retention_days = invocation_log_retention_days_from_env()?;
service.bootstrap_admin_user().await?;
if env_flag("CRANK_DEMO_SEED") {
service.seed_demo_assets().await?;
@@ -159,17 +160,17 @@ async fn run(
Ok(())
}
fn positive_i64_from_env(
name: &'static str,
default: i64,
) -> Result<i64, Box<dyn std::error::Error>> {
let value = match env::var(name) {
fn invocation_log_retention_days_from_env() -> Result<i64, Box<dyn std::error::Error>> {
const NAME: &str = "CRANK_INVOCATION_LOG_RETENTION_DAYS";
let value = match env::var(NAME) {
Ok(raw) => raw.parse::<i64>()?,
Err(env::VarError::NotPresent) => default,
Err(env::VarError::NotPresent) => 30,
Err(error) => return Err(error.into()),
};
if value <= 0 {
return Err(format!("{name} must be greater than zero").into());
if !(1..=MAX_INVOCATION_LOG_RETENTION_DAYS).contains(&value) {
return Err(
format!("{NAME} must be between 1 and {MAX_INVOCATION_LOG_RETENTION_DAYS}").into(),
);
}
Ok(value)
}
+7 -3
View File
@@ -1,5 +1,5 @@
use axum::{
extract::Request,
extract::{MatchedPath, Request},
http::{HeaderName, HeaderValue},
middleware::Next,
response::Response,
@@ -19,7 +19,11 @@ pub async fn apply_request_context(mut request: Request, next: Next) -> Response
request_id: RequestId::resolve_from_headers(request.headers()).into_string(),
};
let method = request.method().clone();
let path = request.uri().path().to_owned();
let route = request
.extensions()
.get::<MatchedPath>()
.map_or("unmatched", MatchedPath::as_str)
.to_owned();
let span = info_span!(
target: "crank::trace",
"http.request",
@@ -34,7 +38,7 @@ pub async fn apply_request_context(mut request: Request, next: Next) -> Response
name: "admin.request.completed",
request_id = %context.request_id,
method = %method,
path,
route,
status = response.status().as_u16(),
"admin request completed"
);
@@ -65,6 +65,7 @@ async fn logs_request_completion_and_rejects_untrusted_values() {
.unwrap();
assert_eq!(event["request_id"], "req_admin_trace_123");
assert_eq!(event["fields"]["status"], 200);
assert_eq!(event["fields"]["route"], "/probe");
let invalid_response = app
.oneshot(