use serde::{Deserialize, Serialize};
use crate::evaluation::DecisionKind;
use crate::model::{RelationKey, SubjectRef};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct TransitionObservation {
pub operation: &'static str,
pub relation: RelationKey,
pub subject_kind: String,
pub decision: DecisionKind,
}
impl TransitionObservation {
#[must_use]
pub fn new(
operation: &'static str,
relation: RelationKey,
subject: &SubjectRef,
decision: DecisionKind,
) -> Self {
Self {
operation,
relation,
subject_kind: subject.kind().to_owned(),
decision,
}
}
}
pub trait TransitionObserver: Send + Sync {
fn observe(&self, observation: &TransitionObservation);
}
#[derive(Debug, Clone, Copy, Default)]
pub struct NoopTransitionObserver;
impl TransitionObserver for NoopTransitionObserver {
fn observe(&self, _observation: &TransitionObservation) {}
}
pub trait MetricsRecorder: Send + Sync {
fn increment(&self, name: &'static str, labels: &[(&'static str, String)]);
fn timing_ms(&self, name: &'static str, value: u64, labels: &[(&'static str, String)]);
}
#[derive(Debug, Clone, Copy, Default)]
pub struct NoopMetricsRecorder;
impl MetricsRecorder for NoopMetricsRecorder {
fn increment(&self, _name: &'static str, _labels: &[(&'static str, String)]) {}
fn timing_ms(&self, _name: &'static str, _value: u64, _labels: &[(&'static str, String)]) {}
}