use otel_arrow_dfe_config::SignalType;
#[derive(Debug, Clone, Copy, Default)]
pub struct AdmissionContext<'a> {
signal: Option<SignalType>,
tenant_key: Option<&'a str>,
scope_key: Option<&'a str>,
}
impl<'a> AdmissionContext<'a> {
pub const EMPTY: Self = Self {
signal: None,
tenant_key: None,
scope_key: None,
};
#[must_use]
pub const fn for_signal(signal: SignalType) -> Self {
Self {
signal: Some(signal),
tenant_key: None,
scope_key: None,
}
}
#[must_use]
pub const fn with_tenant_key(mut self, tenant_key: &'a str) -> Self {
self.tenant_key = Some(tenant_key);
self
}
#[must_use]
pub const fn with_scope_key(mut self, scope_key: &'a str) -> Self {
self.scope_key = Some(scope_key);
self
}
#[must_use]
pub const fn signal(&self) -> Option<SignalType> {
self.signal
}
#[must_use]
pub const fn tenant_key(&self) -> Option<&'a str> {
self.tenant_key
}
#[must_use]
pub const fn scope_key(&self) -> Option<&'a str> {
self.scope_key
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_context_reports_no_identity() {
let ctx = AdmissionContext::EMPTY;
assert_eq!(ctx.signal(), None);
assert_eq!(ctx.tenant_key(), None);
assert_eq!(ctx.scope_key(), None);
}
#[test]
fn context_round_trips_signal_tenant_and_scope() {
let ctx = AdmissionContext::for_signal(SignalType::Logs)
.with_tenant_key("tenant-a")
.with_scope_key("group-1");
assert_eq!(ctx.signal(), Some(SignalType::Logs));
assert_eq!(ctx.tenant_key(), Some("tenant-a"));
assert_eq!(ctx.scope_key(), Some("group-1"));
}
#[test]
fn context_is_copy_and_allocation_free() {
let ctx = AdmissionContext::for_signal(SignalType::Metrics);
let copied = ctx;
assert_eq!(ctx.signal(), copied.signal());
}
}