fix: Improve debugging ability for influxdb2_client (#5533)
* fix: Separate errors to make debugging easier * feat: Turn on reqwest verbose connection logging for debugging https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html#method.connection_verbose > Enabling this option will emit log messages at the TRACE level for read and write operations on connections. Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>pull/24376/head
parent
d219f93241
commit
d84b062a69
|
@ -2,7 +2,10 @@
|
||||||
//!
|
//!
|
||||||
//! Query InfluxDB using InfluxQL or Flux Query
|
//! Query InfluxDB using InfluxQL or Flux Query
|
||||||
|
|
||||||
use crate::{Client, HttpSnafu, RequestError, ReqwestProcessingSnafu, SerializingSnafu};
|
use crate::{
|
||||||
|
Client, HttpSnafu, RequestError, ReqwestProcessingSnafu, ResponseBytesSnafu,
|
||||||
|
ResponseStringSnafu, SerializingSnafu,
|
||||||
|
};
|
||||||
use reqwest::{Method, StatusCode};
|
use reqwest::{Method, StatusCode};
|
||||||
use snafu::ResultExt;
|
use snafu::ResultExt;
|
||||||
|
|
||||||
|
@ -73,10 +76,20 @@ impl Client {
|
||||||
.context(ReqwestProcessingSnafu)?;
|
.context(ReqwestProcessingSnafu)?;
|
||||||
|
|
||||||
match response.status() {
|
match response.status() {
|
||||||
StatusCode::OK => Ok(response
|
StatusCode::OK => {
|
||||||
.json::<String>()
|
let bytes = response.bytes().await.context(ResponseBytesSnafu)?;
|
||||||
.await
|
|
||||||
.context(ReqwestProcessingSnafu)?),
|
let json_result = serde_json::from_slice::<String>(&bytes);
|
||||||
|
match json_result {
|
||||||
|
Ok(json) => Ok(json),
|
||||||
|
Err(source) => {
|
||||||
|
let text =
|
||||||
|
String::from_utf8(bytes.to_vec()).context(ResponseStringSnafu)?;
|
||||||
|
|
||||||
|
Err(RequestError::DeserializingJsonResponse { source, text })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
status => {
|
status => {
|
||||||
let text = response.text().await.context(ReqwestProcessingSnafu)?;
|
let text = response.text().await.context(ReqwestProcessingSnafu)?;
|
||||||
HttpSnafu { status, text }.fail()?
|
HttpSnafu { status, text }.fail()?
|
||||||
|
|
|
@ -92,6 +92,29 @@ pub enum RequestError {
|
||||||
/// The underlying error object from `serde_json`.
|
/// The underlying error object from `serde_json`.
|
||||||
source: serde_json::error::Error,
|
source: serde_json::error::Error,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// While deserializing the response as JSON, something went wrong.
|
||||||
|
#[snafu(display("Could not deserialize as JSON. Error: {source}\nText: `{text}`"))]
|
||||||
|
DeserializingJsonResponse {
|
||||||
|
/// The text of the response
|
||||||
|
text: String,
|
||||||
|
/// The underlying error object from serde
|
||||||
|
source: serde_json::Error,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Something went wrong getting the raw bytes of the response
|
||||||
|
#[snafu(display("Could not get response bytes: {source}"))]
|
||||||
|
ResponseBytes {
|
||||||
|
/// The underlying error object from reqwest
|
||||||
|
source: reqwest::Error,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Something went wrong converting the raw bytes of the response to a UTF-8 string
|
||||||
|
#[snafu(display("Invalid UTF-8: {source}"))]
|
||||||
|
ResponseString {
|
||||||
|
/// The underlying error object from std
|
||||||
|
source: std::string::FromUtf8Error,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Client to a server supporting the InfluxData 2.0 API.
|
/// Client to a server supporting the InfluxData 2.0 API.
|
||||||
|
@ -128,7 +151,10 @@ impl Client {
|
||||||
Self {
|
Self {
|
||||||
url: url.into(),
|
url: url.into(),
|
||||||
auth_header,
|
auth_header,
|
||||||
reqwest: reqwest::Client::new(),
|
reqwest: reqwest::Client::builder()
|
||||||
|
.connection_verbose(true)
|
||||||
|
.build()
|
||||||
|
.expect("reqwest::Client should have built"),
|
||||||
jaeger_debug_header: None,
|
jaeger_debug_header: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue