This commit is contained in:
Mateusz Gruszczyński committed 2026-10-05 19:05:55 +02:00
1 parent ddc5c6593f
commit b9d137eee1
63 files changed
+1232 -445

No files matched your search

+74 -2
View File
@@ -2,9 +2,14 @@
pub struct LogEntry {
pub event: &'static str,
pub protocol_error: Option<&'static str>,
pub reason: Option<&'static str>,
pub error_detail: Option<String>,
pub error: Option<String>,
pub local_addr: Option<String>,
pub tls_sni: Option<String>,
pub sni: Option<String>,
pub authority: Option<String>,
pub matched_by: Option<&'static str>,
pub vhost: Option<String>,
pub route: Option<String>,
pub cache_effective_enabled: Option<bool>,
@@ -85,6 +90,21 @@ fn protocol_error_detail(detail: impl std::fmt::Display) -> String {
detail
}
fn protocol_identity_field(value: Option<String>) -> Option<String> {
value.map(|value| {
let mut value: String = value.chars().filter(|ch| !ch.is_control()).collect();
if value.len() > 512 {
let mut end = 512;
while !value.is_char_boundary(end) {
end -= 1;
}
value.truncate(end);
value.push_str("...");
}
value
})
}
impl Logs {
pub fn start(settings: Settings, shutdown: CancellationToken) -> Arc<Self> {
let (tx, rx) = mpsc::channel(SINK_QUEUE);
@@ -143,18 +163,47 @@ impl Logs {
http_version: &'static str,
status: u16,
tls_sni: Option<String>,
) {
self.push_protocol_error_attributed(
kind, detail, client, local, transport, http_version, status, tls_sni, None, None,
"none",
);
}
#[allow(clippy::too_many_arguments)]
pub fn push_protocol_error_attributed(
&self,
kind: &'static str,
detail: impl std::fmt::Display,
client: std::net::SocketAddr,
local: std::net::SocketAddr,
transport: &'static str,
http_version: &'static str,
status: u16,
tls_sni: Option<String>,
authority: Option<String>,
vhost: Option<String>,
matched_by: &'static str,
) {
if !self.settings.load().enabled() {
return;
}
let detail = protocol_error_detail(detail);
let tls_sni = protocol_identity_field(tls_sni);
let authority = protocol_identity_field(authority);
let sni = tls_sni.clone();
self.push_sink(LogEntry {
event: "protocol_error",
protocol_error: Some(kind),
error_detail: Some(detail),
reason: Some(kind),
error_detail: Some(detail.clone()),
error: Some(detail),
local_addr: Some(local.to_string()),
tls_sni,
vhost: None,
sni,
authority,
matched_by: Some(matched_by),
vhost,
route: None,
cache_effective_enabled: None,
transform_effective_enabled: None,
@@ -221,11 +270,20 @@ fn value_for(entry: &LogEntry, name: &str) -> Value {
.protocol_error
.map(|v| Value::String(v.into()))
.unwrap_or(Value::Null),
"reason" => entry
.reason
.map(|v| Value::String(v.into()))
.unwrap_or(Value::Null),
"error_detail" => entry
.error_detail
.clone()
.map(Value::String)
.unwrap_or(Value::Null),
"error" => entry
.error
.clone()
.map(Value::String)
.unwrap_or(Value::Null),
"local_addr" => entry
.local_addr
.clone()
@@ -236,6 +294,20 @@ fn value_for(entry: &LogEntry, name: &str) -> Value {
.clone()
.map(Value::String)
.unwrap_or(Value::Null),
"sni" => entry
.sni
.clone()
.map(Value::String)
.unwrap_or(Value::Null),
"authority" => entry
.authority
.clone()
.map(Value::String)
.unwrap_or(Value::Null),
"matched_by" => entry
.matched_by
.map(|v| Value::String(v.into()))
.unwrap_or(Value::Null),
"vhost" => entry
.vhost
.clone()