aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Davies <jpds@protonmail.com>2023-08-02 14:30:04 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-02-14 14:36:20 +0100
commit8b9cc5ca3fea35ee54e309bde5a0a651c3b31322 (patch)
tree97279ea6e19949b4286cc0221a282bd54255402e
parenta1533d291942b8daa2550f7e5f4bad8a8e29c8bc (diff)
downloadgarage-8b9cc5ca3fea35ee54e309bde5a0a651c3b31322.tar.gz
garage-8b9cc5ca3fea35ee54e309bde5a0a651c3b31322.zip
web_server.rs: Added bucket domain to observability.
-rw-r--r--src/web/web_server.rs40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs
index 48dcb5b1..2ab3f53b 100644
--- a/src/web/web_server.rs
+++ b/src/web/web_server.rs
@@ -120,18 +120,34 @@ impl WebServer {
req: Request<IncomingBody>,
addr: String,
) -> Result<Response<BoxBody<Error>>, http::Error> {
+ let request_host_bucket = req
+ .headers()
+ .get(HOST)
+ .expect("No host header found")
+ .to_str()
+ .expect("Error converting host header to string")
+ .to_string();
+
if let Ok(forwarded_for_ip_addr) =
forwarded_headers::handle_forwarded_for_headers(req.headers())
{
+ // uri() below has a preceding '/', so no space with host
info!(
- "{} (via {}) {} {}",
+ "{} (via {}) {} {}{}",
forwarded_for_ip_addr,
addr,
req.method(),
+ request_host_bucket,
req.uri()
);
} else {
- info!("{} {} {}", addr, req.method(), req.uri());
+ info!(
+ "{} {} {}{}",
+ addr,
+ req.method(),
+ request_host_bucket,
+ req.uri()
+ );
}
// Lots of instrumentation
@@ -140,12 +156,16 @@ impl WebServer {
.span_builder(format!("Web {} request", req.method()))
.with_trace_id(gen_trace_id())
.with_attributes(vec![
+ KeyValue::new("domain", format!("{}", request_host_bucket.to_string())),
KeyValue::new("method", format!("{}", req.method())),
KeyValue::new("uri", req.uri().to_string()),
])
.start(&tracer);
- let metrics_tags = &[KeyValue::new("method", req.method().to_string())];
+ let metrics_tags = &[
+ KeyValue::new("domain", request_host_bucket.to_string()),
+ KeyValue::new("method", req.method().to_string()),
+ ];
// The actual handler
let res = self
@@ -160,22 +180,30 @@ impl WebServer {
// Returning the result
match res {
Ok(res) => {
- debug!("{} {} {}", req.method(), res.status(), req.uri());
+ debug!(
+ "{} {} {}{}",
+ req.method(),
+ res.status(),
+ request_host_bucket,
+ req.uri()
+ );
Ok(res
.map(|body| BoxBody::new(http_body_util::BodyExt::map_err(body, Error::from))))
}
Err(error) => {
info!(
- "{} {} {} {}",
+ "{} {} {}{} {}",
req.method(),
error.http_status_code(),
+ request_host_bucket,
req.uri(),
error
);
self.metrics.error_counter.add(
1,
&[
- metrics_tags[0].clone(),
+ KeyValue::new("domain", request_host_bucket.to_string()),
+ KeyValue::new("method", req.method().to_string()),
KeyValue::new("status_code", error.http_status_code().to_string()),
],
);