Remove host="" metric parameter for most things
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex 2022-12-07 11:13:43 +01:00
parent 731b59a41f
commit 752593e274
Signed by: lx
GPG key ID: 0E496D15096376BE
2 changed files with 33 additions and 24 deletions

View file

@ -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,

View file

@ -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 {