diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/https.rs | 49 | ||||
-rw-r--r-- | src/metrics.rs | 8 |
2 files changed, 33 insertions, 24 deletions
diff --git a/src/https.rs b/src/https.rs index 6e83c9e..125e429 100644 --- a/src/https.rs +++ b/src/https.rs @@ -33,6 +33,8 @@ pub struct HttpsConfig { pub bind_addr: SocketAddr, pub enable_compression: bool, pub compress_mime_types: Vec<String>, + + // used internally to convert Instants to u64 pub time_origin: Instant, } @@ -159,23 +161,28 @@ async fn handle_request( proxy_config: Arc<ProxyConfig>, metrics: Arc<HttpsMetrics>, ) -> Result<Response<Body>, Infallible> { - let mut tags = vec![ - KeyValue::new("method", req.method().to_string()), - KeyValue::new( - "host", - req.uri() - .authority() - .map(|auth| auth.to_string()) - .or_else(|| { - req.headers() - .get("host") - .map(|host| host.to_str().unwrap_or_default().to_string()) - }) - .unwrap_or_default(), - ), - ]; - metrics.requests_received.add(1, &tags); + let method_tag = KeyValue::new("method", req.method().to_string()); + + // The host tag is only included in the requests_received metric, + // as for other metrics it can easily lead to cardinality explosions. + let host_tag = KeyValue::new( + "host", + req.uri() + .authority() + .map(|auth| auth.to_string()) + .or_else(|| { + req.headers() + .get("host") + .map(|host| host.to_str().unwrap_or_default().to_string()) + }) + .unwrap_or_default(), + ); + + metrics + .requests_received + .add(1, &[host_tag, method_tag.clone()]); + let mut tags = vec![method_tag]; let resp = select_target_and_proxy( &https_config, &proxy_config, @@ -188,7 +195,11 @@ async fn handle_request( tags.push(KeyValue::new( "status_code", - resp.status().as_u16().to_string(), + format!( + "{} {}", + resp.status().as_u16(), + resp.status().canonical_reason().unwrap_or_default() + ), )); metrics.requests_served.add(1, &tags); @@ -256,8 +267,8 @@ async fn select_target_and_proxy( "target_addr", proxy_to.target_addr.to_string(), )); - tags.push(KeyValue::new("same_node", proxy_to.same_node.to_string())); - tags.push(KeyValue::new("same_site", proxy_to.same_site.to_string())); + tags.push(KeyValue::new("same_node", proxy_to.same_node)); + tags.push(KeyValue::new("same_site", proxy_to.same_site)); proxy_to.last_call.fetch_max( (received_time - https_config.time_origin).as_millis() as i64, diff --git a/src/metrics.rs b/src/metrics.rs index 46b69af..fa2657c 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -24,11 +24,9 @@ impl MetricsServer { let exporter = opentelemetry_prometheus::exporter() .with_default_summary_quantiles(vec![0.25, 0.5, 0.75, 0.9, 0.95, 0.99]) .with_default_histogram_boundaries(vec![ - 0.001, 0.0015, 0.002, 0.003, 0.005, 0.007, - 0.01, 0.015, 0.02, 0.03, 0.05, 0.07, - 0.1, 0.15, 0.2, 0.3, 0.5, 0.7, - 1., 1.5, 2., 3., 5., 7., - 10., 15., 20., 30., 40., 50., 60., 70., 100. + 0.001, 0.0015, 0.002, 0.003, 0.005, 0.007, 0.01, 0.015, 0.02, 0.03, 0.05, 0.07, + 0.1, 0.15, 0.2, 0.3, 0.5, 0.7, 1., 1.5, 2., 3., 5., 7., 10., 15., 20., 30., 40., + 50., 60., 70., 100., ]) .init(); Self { |