use async_graphql::{Object, Union};
use crate::api::schema::events::log::Log;
use crate::api::schema::events::metric::Metric;
use crate::api::schema::events::trace::Trace;
use vector_lib::tap::controller::TapPayload;
use vector_lib::tap::notification::Notification;
#[derive(Debug, Clone)]
pub struct EventNotification {
pub notification: Notification,
}
#[Object]
impl EventNotification {
async fn notification(&self) -> &Notification {
&self.notification
}
async fn message(&self) -> &str {
self.notification.as_str()
}
}
#[derive(Union, Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum OutputEventsPayload {
Log(Log),
Metric(Metric),
Notification(EventNotification),
Trace(Trace),
}
pub(crate) fn from_tap_payload_to_output_events(t: TapPayload) -> Vec<OutputEventsPayload> {
match t {
TapPayload::Log(output, log_array) => log_array
.into_iter()
.map(|log| OutputEventsPayload::Log(Log::new(output.clone(), log)))
.collect(),
TapPayload::Metric(output, metric_array) => metric_array
.into_iter()
.map(|metric| OutputEventsPayload::Metric(Metric::new(output.clone(), metric)))
.collect(),
TapPayload::Notification(notification) => {
vec![OutputEventsPayload::Notification(EventNotification {
notification,
})]
}
TapPayload::Trace(output, trace_array) => trace_array
.into_iter()
.map(|trace| OutputEventsPayload::Trace(Trace::new(output.clone(), trace)))
.collect(),
}
}