use sonda_core::sink::SinkConfig;
pub fn sink_display(sink: &SinkConfig) -> String {
match sink {
SinkConfig::Stdout => "stdout".to_string(),
SinkConfig::File { path } => format!("file ({path})"),
SinkConfig::Tcp { address, .. } => format!("tcp ({address})"),
SinkConfig::Udp { address } => format!("udp ({address})"),
#[cfg(feature = "http")]
SinkConfig::HttpPush { url, .. } => format!("http_push ({url})"),
#[cfg(not(feature = "http"))]
SinkConfig::HttpPushDisabled {} => "http_push (disabled)".to_string(),
#[cfg(feature = "http")]
SinkConfig::Loki { url, .. } => format!("loki ({url})"),
#[cfg(not(feature = "http"))]
SinkConfig::LokiDisabled {} => "loki (disabled)".to_string(),
#[cfg(feature = "remote-write")]
SinkConfig::RemoteWrite { url, .. } => format!("remote_write ({url})"),
#[cfg(not(feature = "remote-write"))]
SinkConfig::RemoteWriteDisabled {} => "remote_write (disabled)".to_string(),
#[cfg(feature = "kafka")]
SinkConfig::Kafka { brokers, topic, .. } => format!("kafka ({brokers} / {topic})"),
#[cfg(not(feature = "kafka"))]
SinkConfig::KafkaDisabled {} => "kafka (disabled)".to_string(),
#[cfg(feature = "otlp")]
SinkConfig::OtlpGrpc { endpoint, .. } => format!("otlp_grpc ({endpoint})"),
#[cfg(not(feature = "otlp"))]
SinkConfig::OtlpGrpcDisabled {} => "otlp_grpc (disabled)".to_string(),
other => format!("unknown ({other:?})"),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn stdout_renders_without_detail() {
assert_eq!(sink_display(&SinkConfig::Stdout), "stdout");
}
#[test]
fn file_includes_path_in_parens() {
let s = SinkConfig::File {
path: "/tmp/out.txt".to_string(),
};
assert_eq!(sink_display(&s), "file (/tmp/out.txt)");
}
#[test]
fn tcp_includes_address_in_parens() {
let s = SinkConfig::Tcp {
address: "127.0.0.1:9999".to_string(),
retry: None,
};
assert_eq!(sink_display(&s), "tcp (127.0.0.1:9999)");
}
#[test]
fn udp_includes_address_in_parens() {
let s = SinkConfig::Udp {
address: "127.0.0.1:8888".to_string(),
};
assert_eq!(sink_display(&s), "udp (127.0.0.1:8888)");
}
#[cfg(feature = "http")]
#[test]
fn http_push_includes_url_in_parens() {
let s = SinkConfig::HttpPush {
url: "http://localhost:9090/write".to_string(),
content_type: None,
batch_size: None,
max_buffer_age: None,
headers: None,
retry: None,
};
assert_eq!(sink_display(&s), "http_push (http://localhost:9090/write)");
}
#[cfg(not(feature = "http"))]
#[test]
fn http_push_disabled_renders_disabled_marker() {
let s = SinkConfig::HttpPushDisabled {};
assert_eq!(sink_display(&s), "http_push (disabled)");
}
#[cfg(not(feature = "http"))]
#[test]
fn loki_disabled_renders_disabled_marker() {
let s = SinkConfig::LokiDisabled {};
assert_eq!(sink_display(&s), "loki (disabled)");
}
}