|
3 | 3 | //! ## Metrics |
4 | 4 | //! |
5 | 5 | //! `bytes_received`: Total bytes received |
6 | | -//! `bytes_received_distr`: Distribution of compressed bytes per request (with `path` label) |
| 6 | +//! `bytes_received_gauge`: Compressed body sizes, in bytes (with `path` label) |
7 | 7 | //! `decoded_bytes_received`: Total decoded bytes received |
8 | | -//! `decoded_bytes_received_distr`: Distribution of decompressed bytes per request (with `path` label) |
| 8 | +//! `decoded_bytes_received_gauge`: Decompressed request body sizes, in bytes (with `path` label) |
9 | 9 | //! `requests_received`: Total requests received |
| 10 | +//! `bytes_sent_gauge`: Response packets body sizes, in bytes (with `path` label) |
10 | 11 | //! |
11 | 12 |
|
12 | 13 | use bytes::Bytes; |
13 | 14 | use http::{HeaderMap, header::InvalidHeaderValue, status::InvalidStatusCode}; |
14 | 15 | use http_body_util::{BodyExt, combinators::BoxBody}; |
15 | 16 | use hyper::{Request, Response, StatusCode, header}; |
16 | | -use metrics::{counter, histogram}; |
| 17 | +use metrics::{counter, gauge}; // NOMERGE: temporarily remove histogram! calls as they're not yet supported in the metrics processing backends |
17 | 18 | use serde::{Deserialize, Serialize}; |
18 | 19 | use std::{net::SocketAddr, time::Duration}; |
19 | 20 | use tracing::error; |
@@ -164,16 +165,18 @@ async fn srv( |
164 | 165 |
|
165 | 166 | let mut labels_with_path = metric_labels.clone(); |
166 | 167 | labels_with_path.push(("path".to_string(), path)); |
167 | | - histogram!("bytes_received_distr", &labels_with_path).record(body.len() as f64); |
| 168 | + gauge!("bytes_received_gauge", &labels_with_path).set(body.len() as f64); |
168 | 169 |
|
169 | 170 | match crate::codec::decode(parts.headers.get(hyper::header::CONTENT_ENCODING), body) { |
170 | 171 | Err(response) => Ok(*response), |
171 | 172 | Ok(body) => { |
172 | 173 | counter!("decoded_bytes_received", &metric_labels).increment(body.len() as u64); |
173 | | - histogram!("decoded_bytes_received_distr", &labels_with_path).record(body.len() as f64); |
| 174 | + gauge!("decoded_bytes_received_gauge", &labels_with_path).set(body.len() as f64); |
174 | 175 |
|
175 | 176 | tokio::time::sleep(response_delay).await; |
176 | 177 |
|
| 178 | + gauge!("bytes_sent_gauge", &labels_with_path).set(body_bytes.len() as f64); |
| 179 | + |
177 | 180 | let mut okay = Response::default(); |
178 | 181 | *okay.status_mut() = status; |
179 | 182 | *okay.headers_mut() = headers; |
|
0 commit comments