From 5cc073420a1b7c553320a99ce11addb29ec48a69 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Wed, 16 Jun 2021 10:10:10 -0600 Subject: [PATCH] metrics: Don't unwrap client instantiation errors --- metrics/src/metrics.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/metrics/src/metrics.rs b/metrics/src/metrics.rs index 4484e8220b..6d55b89e7e 100644 --- a/metrics/src/metrics.rs +++ b/metrics/src/metrics.rs @@ -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());