Skip to content

Commit

Permalink
Restore context in logs by moving the fields in HttpContext
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>
  • Loading branch information
Wonshtrum authored and Keksoj committed Apr 5, 2024
1 parent b9df0c1 commit 8faa16c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 72 deletions.
9 changes: 6 additions & 3 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ impl HttpSession {
let back_token = match http.backend_token {
Some(back_token) => back_token,
None => {
warn!("Could not upgrade http request on cluster '{:?}' ({:?}) using backend '{:?}' into websocket for request '{}'", http.cluster_id, self.frontend_token, http.backend_id, http.context.id);
warn!(
"Could not upgrade http request on cluster '{:?}' ({:?}) using backend '{:?}' into websocket for request '{}'",
http.context.cluster_id, self.frontend_token, http.context.backend_id, http.context.id
);
return None;
}
};
Expand All @@ -239,12 +242,12 @@ impl HttpSession {

let mut pipe = Pipe::new(
backend_buffer,
http.backend_id,
http.context.backend_id,
http.backend_socket,
http.backend,
Some(container_backend_timeout),
Some(container_frontend_timeout),
http.cluster_id,
http.context.cluster_id,
http.request_stream.storage.buffer,
front_token,
http.frontend_socket,
Expand Down
9 changes: 6 additions & 3 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ impl HttpsSession {
let back_token = match http.backend_token {
Some(back_token) => back_token,
None => {
warn!("Could not upgrade https request on cluster '{:?}' ({:?}) using backend '{:?}' into secure websocket for request '{}'", http.cluster_id, self.frontend_token, http.backend_id, http.context.id);
warn!(
"Could not upgrade https request on cluster '{:?}' ({:?}) using backend '{:?}' into secure websocket for request '{}'",
http.context.cluster_id, self.frontend_token, http.context.backend_id, http.context.id
);
return None;
}
};
Expand All @@ -365,12 +368,12 @@ impl HttpsSession {

let mut pipe = Pipe::new(
backend_buffer,
http.backend_id,
http.context.backend_id,
http.backend_socket,
http.backend,
Some(container_backend_timeout),
Some(container_frontend_timeout),
http.cluster_id,
http.context.cluster_id,
http.request_stream.storage.buffer,
front_token,
http.frontend_socket,
Expand Down
12 changes: 12 additions & 0 deletions lib/src/protocol/kawa_h1/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::{
Protocol,
};

use sozu_command_lib::logging::LogContext;

/// This is the container used to store and use information about the session from within a Kawa parser callback
#[derive(Debug)]
pub struct HttpContext {
Expand Down Expand Up @@ -40,6 +42,8 @@ pub struct HttpContext {
pub closing: bool,
/// the value of the custom header, named "Sozu-Id", that Kawa should write (request and response)
pub id: Ulid,
pub backend_id: Option<String>,
pub cluster_id: Option<String>,
/// the value of the protocol Kawa should write in the Forwarded headers of the request
pub protocol: Protocol,
/// the value of the public address Kawa should write in the Forwarded headers of the request
Expand Down Expand Up @@ -353,4 +357,12 @@ impl HttpContext {
self.reason = None;
self.user_agent = None;
}

pub fn log_context(&self) -> LogContext {
LogContext {
request_id: self.id,
cluster_id: self.cluster_id.as_deref(),
backend_id: self.backend_id.as_deref(),
}
}
}
Loading

0 comments on commit 8faa16c

Please sign in to comment.