Update to use Feature, with log line about time and compression ratio

This commit is contained in:
Channing Conger
2025-12-18 16:51:18 -08:00
parent c069660811
commit eef24681c8
7 changed files with 159 additions and 33 deletions

View File

@@ -20,6 +20,8 @@ use http::header::CONTENT_TYPE;
use serde_json::Value;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
use tracing::info;
use zstd::stream::encode_all;
pub(crate) struct StreamingClient<T: HttpTransport, A: AuthProvider> {
@@ -105,8 +107,16 @@ fn encode_body(body: &Value, compression: RequestCompression) -> Result<Body, St
RequestCompression::Zstd => {
let json = serde_json::to_vec(body)
.map_err(|err| format!("failed to encode request body as json: {err}"))?;
let started_at = Instant::now();
let compressed = encode_all(json.as_slice(), 0)
.map_err(|err| format!("failed to compress request body: {err}"))?;
let elapsed = started_at.elapsed();
info!(
input_bytes = json.len(),
output_bytes = compressed.len(),
elapsed_ms = elapsed.as_millis(),
"compressed request body"
);
Ok(Body::Bytes(Bytes::from(compressed)))
}
}