Skip to content
Draft
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
14 changes: 3 additions & 11 deletions lading/src/blackhole/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
//! ## Metrics
//!
//! `bytes_received`: Total bytes received
//! `bytes_received_distr`: Distribution of compressed bytes per request (with `path` label)
//! `decoded_bytes_received`: Total decoded bytes received
//! `decoded_bytes_received_distr`: Distribution of decompressed bytes per request (with `path` label)
//! `requests_received`: Total requests received
//!

use bytes::Bytes;
use http::{HeaderMap, header::InvalidHeaderValue, status::InvalidStatusCode};
use http_body_util::{BodyExt, combinators::BoxBody};
use hyper::{Request, Response, StatusCode, header};
use metrics::{counter, histogram};
use metrics::counter;
use serde::{Deserialize, Serialize};
use std::{net::SocketAddr, time::Duration};
use tracing::error;
Expand Down Expand Up @@ -154,23 +151,18 @@ async fn srv(
) -> Result<hyper::Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
counter!("requests_received", &metric_labels).increment(1);

let path = req.uri().path().to_string();

// Split into parts
let (parts, body) = req.into_parts();

// Convert the `Body` into `Bytes`
let body: Bytes = body.boxed().collect().await?.to_bytes();

counter!("bytes_received", &metric_labels).increment(body.len() as u64);

let mut labels_with_path = metric_labels.clone();
labels_with_path.push(("path".to_string(), path));
histogram!("bytes_received_distr", &labels_with_path).record(body.len() as f64);

match crate::codec::decode(parts.headers.get(hyper::header::CONTENT_ENCODING), body) {
Err(response) => Ok(*response),
Ok(body) => {
counter!("decoded_bytes_received", &metric_labels).increment(body.len() as u64);
histogram!("decoded_bytes_received_distr", &labels_with_path).record(body.len() as f64);

tokio::time::sleep(response_delay).await;

Expand Down
Loading