diff options
Diffstat (limited to 'src/https.rs')
-rw-r--r-- | src/https.rs | 49 |
1 files changed, 30 insertions, 19 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, |