Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

metrics: Don't unwrap client instantiation errors (backport #18005) #18018

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions metrics/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,23 @@ impl MetricsWriter for InfluxDbMetricsWriter {

let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(5))
.build()
.unwrap();
.build();
let client = match client {
Ok(client) => client,
Err(err) => {
warn!("client instantiation failed: {}", err);
return;
}
};

let response = client.post(write_url.as_str()).body(line).send();
if let Ok(resp) = response {
if !resp.status().is_success() {
warn!(
"submit response unsuccessful: {} {}",
resp.status(),
resp.text().unwrap()
);
let status = resp.status();
if !status.is_success() {
let text = resp
.text()
.unwrap_or_else(|_| "[text body empty]".to_string());
warn!("submit response unsuccessful: {} {}", status, text,);
}
} else {
warn!("submit error: {}", response.unwrap_err());
Expand Down