Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Added
- Lading now supports histogram approximations in its capture files.
- HTTP blackhole now tracks distribution of bytes received, both decoded and
compressed.
compressed; as well as a gauge for individual packets.
- New "Static Chunks" generator that divides static files by lines into blocks
(as opposed to static which turns each file into a block).
- Fingerprint mechanism now calculates Shannon entropy.
Expand Down
13 changes: 8 additions & 5 deletions lading/src/blackhole/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
//! ## Metrics
//!
//! `bytes_received`: Total bytes received
//! `bytes_received_distr`: Distribution of compressed bytes per request (with `path` label)
//! `bytes_received_gauge`: Compressed body sizes, in bytes (with `path` label)
//! `decoded_bytes_received`: Total decoded bytes received
//! `decoded_bytes_received_distr`: Distribution of decompressed bytes per request (with `path` label)
//! `decoded_bytes_received_gauge`: Decompressed request body sizes, in bytes (with `path` label)
//! `requests_received`: Total requests received
//! `bytes_sent_gauge`: Response packets body sizes, in bytes (with `path` label)
//!

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, gauge}; // NOMERGE: temporarily remove histogram! calls as they're not yet supported in the metrics processing backends
use serde::{Deserialize, Serialize};
use std::{net::SocketAddr, time::Duration};
use tracing::error;
Expand Down Expand Up @@ -164,16 +165,18 @@ async fn srv(

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);
gauge!("bytes_received_gauge", &labels_with_path).set(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);
gauge!("decoded_bytes_received_gauge", &labels_with_path).set(body.len() as f64);

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

gauge!("bytes_sent_gauge", &labels_with_path).set(body_bytes.len() as f64);

let mut okay = Response::default();
*okay.status_mut() = status;
*okay.headers_mut() = headers;
Expand Down
Loading