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