|
4 | 4 | //! |
5 | 5 | //! `bytes_received`: Total bytes received |
6 | 6 | //! `total_bytes_received`: Aggregated bytes received across all blackhole types |
7 | | -//! `bytes_received_distr`: Distribution of compressed bytes per request (with `path` label) |
8 | 7 | //! `decoded_bytes_received`: Total decoded bytes received |
9 | | -//! `decoded_bytes_received_distr`: Distribution of decompressed bytes per request (with `path` label) |
10 | 8 | //! `requests_received`: Total requests received |
11 | 9 | //! |
12 | 10 |
|
13 | 11 | use bytes::Bytes; |
14 | 12 | use http::{HeaderMap, header::InvalidHeaderValue, status::InvalidStatusCode}; |
15 | 13 | use http_body_util::{BodyExt, combinators::BoxBody}; |
16 | 14 | use hyper::{Request, Response, StatusCode, header}; |
17 | | -use metrics::{counter, histogram}; |
| 15 | +use metrics::counter; |
18 | 16 | use serde::{Deserialize, Serialize}; |
19 | 17 | use std::{net::SocketAddr, time::Duration}; |
20 | 18 | use tracing::error; |
@@ -155,25 +153,20 @@ async fn srv( |
155 | 153 | ) -> Result<hyper::Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> { |
156 | 154 | counter!("requests_received", &metric_labels).increment(1); |
157 | 155 |
|
158 | | - let path = req.uri().path().to_string(); |
159 | | - |
| 156 | + // Split into parts |
160 | 157 | let (parts, body) = req.into_parts(); |
161 | 158 |
|
| 159 | + // Convert the `Body` into `Bytes` |
162 | 160 | let body: Bytes = body.boxed().collect().await?.to_bytes(); |
163 | 161 |
|
164 | 162 | let body_len = body.len() as u64; |
165 | 163 | counter!("bytes_received", &metric_labels).increment(body_len); |
166 | 164 | counter!("total_bytes_received").increment(body_len); |
167 | 165 |
|
168 | | - let mut labels_with_path = metric_labels.clone(); |
169 | | - labels_with_path.push(("path".to_string(), path)); |
170 | | - histogram!("bytes_received_distr", &labels_with_path).record(body.len() as f64); |
171 | | - |
172 | 166 | match crate::codec::decode(parts.headers.get(hyper::header::CONTENT_ENCODING), body) { |
173 | 167 | Err(response) => Ok(*response), |
174 | 168 | Ok(body) => { |
175 | 169 | counter!("decoded_bytes_received", &metric_labels).increment(body.len() as u64); |
176 | | - histogram!("decoded_bytes_received_distr", &labels_with_path).record(body.len() as f64); |
177 | 170 |
|
178 | 171 | tokio::time::sleep(response_delay).await; |
179 | 172 |
|
|
0 commit comments