vector/components/validation/validators/
mod.rs

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