Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to debug the Body contents with tracing #1648

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions kube-client/src/client/body.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
error::Error as StdError,
fmt,

Check warning on line 3 in kube-client/src/client/body.rs

View workflow job for this annotation

GitHub Actions / clippy_nightly

unused import: `fmt`

warning: unused import: `fmt` --> kube-client/src/client/body.rs:3:5 | 3 | fmt, | ^^^ | = note: `#[warn(unused_imports)]` on by default
pin::{pin, Pin},
task::{Context, Poll},
};
Expand All @@ -10,10 +10,11 @@
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 @@
};
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