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

(cherry picked from commit 5cc073420a)

Co-authored-by: Trent Nelson <trent@solana.com>
This commit is contained in:
mergify[bot]
2021-06-16 22:02:43 +00:00
committed by GitHub
parent 4733d6dfc3
commit 392d2dbd8a

View File

@ -103,16 +103,23 @@ impl MetricsWriter for InfluxDbMetricsWriter {
let client = reqwest::blocking::Client::builder() let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(5)) .timeout(Duration::from_secs(5))
.build() .build();
.unwrap(); 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(); let response = client.post(write_url.as_str()).body(line).send();
if let Ok(resp) = response { if let Ok(resp) = response {
if !resp.status().is_success() { let status = resp.status();
warn!( if !status.is_success() {
"submit response unsuccessful: {} {}", let text = resp
resp.status(), .text()
resp.text().unwrap() .unwrap_or_else(|_| "[text body empty]".to_string());
); warn!("submit response unsuccessful: {} {}", status, text,);
} }
} else { } else {
warn!("submit error: {}", response.unwrap_err()); warn!("submit error: {}", response.unwrap_err());