vector/components/validation/validators/
mod.rs

1mod 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
11/// A component validator.
12///
13/// Validators perform the actual validation logic that, based on the given inputs, determine of the
14/// component is valid or not for the given validator.
15pub trait Validator {
16    /// Gets the unique name of this validator.
17    fn name(&self) -> &'static str;
18
19    /// Processes the given set of inputs/outputs, generating the validation results.
20    ///
21    /// Additionally, all telemetry events received for the component for the validation run are
22    /// provided as well.
23    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
34/// Standard component validators.
35///
36/// This is an helper enum whose variants can trivially converted into a boxed `dyn Validator`
37/// implementation, suitable for use with `Runner::add_validator`.
38pub enum StandardValidators {
39    /// Validates that the component meets the requirements of the [Component Specification][component_spec].
40    ///
41    /// See [`ComponentSpecValidator`] for more information.
42    ///
43    /// [component_spec]: https://github.com/vectordotdev/vector/blob/master/docs/specs/component.md
44    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}