From 3170d1121835b4acf79ec65cf12c22c016bc9b33 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 21 Oct 2024 16:57:23 +0300 Subject: [PATCH] fix: health check trigger compile metrics. hotfix --- api/src/handlers/compile.rs | 25 ++++++++++++++++--------- api/src/handlers/mod.rs | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/api/src/handlers/compile.rs b/api/src/handlers/compile.rs index 20da3e2..511fb8a 100644 --- a/api/src/handlers/compile.rs +++ b/api/src/handlers/compile.rs @@ -32,7 +32,7 @@ pub async fn compile( ) -> Json { info!("/compile/{:?}", request_json.config); - do_compile(request_json.0, &engine.metrics) + do_compile(request_json.0, &engine.metrics, false) .await .unwrap_or_else(|e| { Json(CompileResponse { @@ -71,6 +71,7 @@ pub async fn get_compile_result(process_id: String, engine: &State pub async fn do_compile( compilation_request: CompilationRequest, metrics: &Metrics, + is_health_check: bool, ) -> Result> { let zksolc_version = compilation_request.config.version; @@ -170,10 +171,13 @@ pub async fn do_compile( "Compilation error: {}", String::from_utf8_lossy(&output.stderr) ); - metrics - .action_failures_total - .with_label_values(&[COMPILATION_LABEL_VALUE]) - .inc(); + + if !is_health_check { + metrics + .action_failures_total + .with_label_values(&[COMPILATION_LABEL_VALUE]) + .inc(); + } return Ok(Json(CompileResponse { file_content: vec![], @@ -211,10 +215,13 @@ pub async fn do_compile( // calling here explicitly to avoid dropping the AutoCleanUp struct auto_clean_up.clean_up().await; - metrics - .action_successes_total - .with_label_values(&[COMPILATION_LABEL_VALUE]) - .inc(); + if !is_health_check { + metrics + .action_successes_total + .with_label_values(&[COMPILATION_LABEL_VALUE]) + .inc(); + } + Ok(Json(CompileResponse { file_content: file_contents, status: status_code_to_message(status.code()), diff --git a/api/src/handlers/mod.rs b/api/src/handlers/mod.rs index 4de39d1..cba1bad 100644 --- a/api/src/handlers/mod.rs +++ b/api/src/handlers/mod.rs @@ -31,7 +31,7 @@ lazy_static! { pub async fn health(engine: &State) -> HealthCheckResponse { info!("/health"); - let result = do_compile(generate_mock_compile_request(), &engine.metrics).await; + let result = do_compile(generate_mock_compile_request(), &engine.metrics, true).await; if result.is_ok() { HealthCheckResponse::ok() @@ -59,7 +59,7 @@ pub async fn dispatch_command( Err(e) => Err(e), }, ApiCommand::Compile(request) => { - let res = match do_compile(request, metrics).await { + let res = match do_compile(request, metrics, false).await { Ok(compile_response) => { Ok(ApiCommandResult::Compile(compile_response.into_inner())) }