vector/components/validation/validators/
mod.rs1mod component_spec;
2
3pub use self::component_spec::ComponentSpecValidator;
4
5use std::fmt::{Display, Formatter};
6
7use vector_lib::event::Event;
8
9use super::{ComponentType, RunnerMetrics, TestCaseExpectation, TestEvent};
10
11pub trait Validator {
16 fn name(&self) -> &'static str;
18
19 fn check_validation(
24 &self,
25 component_type: ComponentType,
26 expectation: TestCaseExpectation,
27 inputs: &[TestEvent],
28 outputs: &[Event],
29 telemetry_events: &[Event],
30 runner_metrics: &RunnerMetrics,
31 ) -> Result<Vec<String>, Vec<String>>;
32}
33
34pub enum StandardValidators {
39 ComponentSpec,
45}
46
47impl From<StandardValidators> for Box<dyn Validator> {
48 fn from(sv: StandardValidators) -> Self {
49 match sv {
50 StandardValidators::ComponentSpec => Box::<ComponentSpecValidator>::default(),
51 }
52 }
53}
54
55#[derive(PartialEq)]
56pub enum ComponentMetricType {
57 EventsReceived,
58 EventsReceivedBytes,
59 ReceivedBytesTotal,
60 SentEventsTotal,
61 SentBytesTotal,
62 SentEventBytesTotal,
63 ErrorsTotal,
64 DiscardedEventsTotal,
65}
66
67impl ComponentMetricType {
68 const fn name(&self) -> &'static str {
69 match self {
70 ComponentMetricType::EventsReceived => "component_received_events_total",
71 ComponentMetricType::EventsReceivedBytes => "component_received_event_bytes_total",
72 ComponentMetricType::ReceivedBytesTotal => "component_received_bytes_total",
73 ComponentMetricType::SentEventsTotal => "component_sent_events_total",
74 ComponentMetricType::SentBytesTotal => "component_sent_bytes_total",
75 ComponentMetricType::SentEventBytesTotal => "component_sent_event_bytes_total",
76 ComponentMetricType::ErrorsTotal => "component_errors_total",
77 ComponentMetricType::DiscardedEventsTotal => "component_discarded_events_total",
78 }
79 }
80}
81
82impl Display for ComponentMetricType {
83 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
84 write!(f, "{}", self.name())
85 }
86}