Skip to content

Commit

Permalink
Add a way to debug the Body contents with tracing
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Nov 23, 2024
1 parent 9f93e2f commit 95ab7d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions kube-client/src/client/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use http_body::{Body as HttpBody, Frame, SizeHint};
use http_body_util::{combinators::UnsyncBoxBody, BodyExt};

/// A request body.
#[derive(Debug)]
pub struct Body {
kind: Kind,
}

/*
impl fmt::Debug for Body {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut builder = f.debug_struct("Body");
Expand All @@ -23,8 +24,9 @@ impl fmt::Debug for Body {
};
builder.finish()
}
}
}*/

#[derive(Debug)]
enum Kind {
Once(Option<Bytes>),
Wrap(UnsyncBoxBody<Bytes, Box<dyn StdError + Send + Sync>>),
Expand Down
13 changes: 10 additions & 3 deletions kube-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl Client {
/// create a proxy server or application-level gateway between localhost and the API server.
pub async fn send(&self, request: Request<Body>) -> Result<Response<Body>> {
let mut svc = self.inner.clone();
tracing::trace!("actual send body: {:?}", request.body());
let res = svc
.ready()
.await
Expand Down Expand Up @@ -254,7 +255,11 @@ impl Client {
/// Perform a raw HTTP request against the API and get back the response
/// as a string
pub async fn request_text(&self, request: Request<Vec<u8>>) -> Result<String> {
let res = self.send(request.map(Body::from)).await?;
let body = request.map(Body::from);
tracing::trace!("body: {body:?}");
let res = self.send(body).await?;
tracing::trace!("requesting: {:?}: {}", res.version(), res.status().as_str());
tracing::trace!("headers: {:?}", res.headers());
let res = handle_api_errors(res).await?;
let body_bytes = res.into_body().collect().await?.to_bytes();
let text = String::from_utf8(body_bytes.to_vec()).map_err(Error::FromUtf8)?;
Expand Down Expand Up @@ -305,8 +310,10 @@ impl Client {
where
T: Clone + DeserializeOwned,
{
let res = self.send(request.map(Body::from)).await?;
// trace!("Streaming from {} -> {}", res.url(), res.status().as_str());
let body = request.map(Body::from);
tracing::trace!("body: {body:?}");
let res = self.send(body).await?;
tracing::trace!("Streaming {:?}: {}", res.version(), res.status().as_str());
tracing::trace!("headers: {:?}", res.headers());

let frames = FramedRead::new(
Expand Down

0 comments on commit 95ab7d6

Please sign in to comment.