Skip to content

Commit

Permalink
Add labels to hls errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Firaenix committed Jan 9, 2025
1 parent b8f03a8 commit 79c7aba
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions src/collectors/hls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ impl Collector for HlsCollector {
})
})
.send()
.await
.inspect_err(|e| {
self.handle_error(e);
})?;
.await?;

Ok(response.into_inner())
}
Expand Down Expand Up @@ -222,12 +219,12 @@ impl Collector for HlsCollector {

Ok(())
} else {
self.record_failure("missing_result");
self.record_failure(&labels);
Err(CollectorErrors::MissingData(endpoint, "hls_result"))
}
}
_ => {
self.record_failure("missing_data");
self.record_failure(&labels);
Err(CollectorErrors::MissingData(endpoint, "hls"))
}
}
Expand Down Expand Up @@ -460,29 +457,10 @@ impl HlsCollector {
Ok(())
}



fn handle_error(&self, error: &Error<PerformHlsResponse>) {
let error_type = match error.status() {
Some(StatusCode::NOT_FOUND) => {
warn!(?self.config.common_config.network, "No nodes found for criteria");
"no_nodes_found"
}
Some(StatusCode::UNAUTHORIZED) => "unauthorized",
Some(StatusCode::TOO_MANY_REQUESTS) => "rate_limited",
_ => {
error!("API request failed: {:#?}", error);
"api_error"
}
};

self.record_failure(error_type);
}

fn record_failure(&self, error_type: &str) {
fn record_failure(&self,labels: &[(&'static str, String)]) {
counter!(
format!("{}hls_failures_total", self.config.common_config.prefix),
"error_type" => error_type.to_string()
labels
)
.increment(1);
}
Expand Down

0 comments on commit 79c7aba

Please sign in to comment.