vector/conditions/
is_metric.rs

1use crate::event::Event;
2
3pub(crate) const fn check_is_metric(e: Event) -> (bool, Event) {
4    (matches!(e, Event::Metric(_)), e)
5}
6
7pub(crate) fn check_is_metric_with_context(e: Event) -> (Result<(), String>, Event) {
8    let (result, event) = check_is_metric(e);
9    if result {
10        (Ok(()), event)
11    } else {
12        (Err("event is not a metric type".to_string()), event)
13    }
14}
15
16#[cfg(test)]
17mod test {
18    use super::check_is_metric;
19    use crate::event::{
20        metric::{Metric, MetricKind, MetricValue},
21        Event, LogEvent,
22    };
23
24    #[test]
25    fn is_metric_basic() {
26        assert!(!check_is_metric(Event::from(LogEvent::from("just a log"))).0);
27        assert!(
28            check_is_metric(Event::from(Metric::new(
29                "test metric",
30                MetricKind::Incremental,
31                MetricValue::Counter { value: 1.0 },
32            )))
33            .0,
34        );
35    }
36}