Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #234 from NethermindEth/feat/log-metrics-increases
Browse files Browse the repository at this point in the history
Consider serivice healthy on response
  • Loading branch information
taco-paco authored Oct 22, 2024
2 parents 9865bcd + 3170d11 commit 26e762a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 16 additions & 9 deletions api/src/handlers/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn compile(
) -> Json<CompileResponse> {
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 {
Expand Down Expand Up @@ -71,6 +71,7 @@ pub async fn get_compile_result(process_id: String, engine: &State<WorkerEngine>
pub async fn do_compile(
compilation_request: CompilationRequest,
metrics: &Metrics,
is_health_check: bool,
) -> Result<Json<CompileResponse>> {
let zksolc_version = compilation_request.config.version;

Expand Down Expand Up @@ -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![],
Expand Down Expand Up @@ -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()),
Expand Down
4 changes: 2 additions & 2 deletions api/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy_static! {
pub async fn health(engine: &State<WorkerEngine>) -> 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()
Expand Down Expand Up @@ -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()))
}
Expand Down

0 comments on commit 26e762a

Please sign in to comment.