Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(dev): Move some macros into vector-core #19002

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/vector-config/src/component/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@
pub trait GenerateConfig {
fn generate_config() -> toml::Value;
}

#[macro_export]
macro_rules! impl_generate_config_from_default {
($type:ty) => {
impl $crate::component::GenerateConfig for $type {
fn generate_config() -> toml::value::Value {
toml::value::Value::try_from(&Self::default()).unwrap()
}
}
};
}
40 changes: 40 additions & 0 deletions lib/vector-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,43 @@ pub(crate) use vector_common::{Error, Result};
pub(crate) fn float_eq(l_value: f64, r_value: f64) -> bool {
(l_value.is_nan() && r_value.is_nan()) || l_value.eq_ulps(&r_value, &1)
}

// These macros aren't actually usable in lib crates without some `vector_lib` shenanigans.
// This test version won't be needed once all `InternalEvent`s implement `name()`.
#[cfg(feature = "test")]
#[macro_export]
macro_rules! emit {
($event:expr) => {
vector_lib::internal_event::emit(vector_lib::internal_event::DefaultName {
event: $event,
name: stringify!($event),
})
};
}

#[cfg(not(feature = "test"))]
#[macro_export]
macro_rules! emit {
($event:expr) => {
vector_lib::internal_event::emit($event)
};
}

#[cfg(feature = "test")]
#[macro_export]
macro_rules! register {
($event:expr) => {
vector_lib::internal_event::register(vector_lib::internal_event::DefaultName {
event: $event,
name: stringify!($event),
})
};
}

#[cfg(not(feature = "test"))]
#[macro_export]
macro_rules! register {
($event:expr) => {
vector_lib::internal_event::register($event)
};
}
6 changes: 4 additions & 2 deletions lib/vector-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ pub use vector_common::{
TimeZone,
};
pub use vector_config as configurable;
pub use vector_config::impl_generate_config_from_default;
#[cfg(feature = "vrl")]
pub use vector_core::compile_vrl;
#[cfg(feature = "test")]
pub use vector_core::event_test_util;
pub use vector_core::{
buckets, default_data_dir, event, fanout, metric_tags, metrics, partition, quantiles, samples,
schema, serde, sink, source, tcp, tls, transform, update_counter, EstimatedJsonEncodedSizeOf,
buckets, default_data_dir, emit, event, fanout, metric_tags, metrics, partition, quantiles,
register, samples, schema, serde, sink, source, tcp, tls, transform, update_counter,
EstimatedJsonEncodedSizeOf,
};
pub use vector_lookup as lookup;
pub use vector_stream as stream;
Expand Down
4 changes: 1 addition & 3 deletions src/conditions/vrl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use vector_lib::compile_vrl;
use vector_lib::configurable::configurable_component;
use vector_lib::TimeZone;
use vector_lib::{compile_vrl, emit, TimeZone};
use vrl::compiler::runtime::{Runtime, RuntimeResult, Terminate};
use vrl::compiler::{CompilationResult, CompileConfig, Program, TypeState, VrlRuntime};
use vrl::diagnostic::Formatter;
Expand All @@ -10,7 +9,6 @@ use crate::config::LogNamespace;
use crate::event::TargetEvents;
use crate::{
conditions::{Condition, Conditional, ConditionalConfig},
emit,
event::{Event, VrlTarget},
internal_events::VrlConditionExecutionError,
};
Expand Down
11 changes: 0 additions & 11 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,6 @@ impl Default for HealthcheckOptions {
}
}

#[macro_export]
macro_rules! impl_generate_config_from_default {
($type:ty) => {
impl $crate::config::GenerateConfig for $type {
fn generate_config() -> toml::value::Value {
toml::value::Value::try_from(&Self::default()).unwrap()
}
}
};
}

/// Unique thing, like port, of which only one owner can be.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Resource {
Expand Down
1 change: 0 additions & 1 deletion src/config/unit_test/unit_test_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
config::{
AcknowledgementsConfig, SinkConfig, SinkContext, SourceConfig, SourceContext, SourceOutput,
},
impl_generate_config_from_default,
sinks::Healthcheck,
sources,
};
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/adaptive_concurrency.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::time::Duration;

use metrics::{register_histogram, Histogram};
use vector_lib::registered_event;

#[derive(Clone, Copy)]
pub struct AdaptiveConcurrencyLimitData {
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/aws_cloudwatch_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

use crate::emit;

#[derive(Debug)]
pub struct AwsCloudwatchLogsMessageSizeError {
pub size: usize,
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/aws_ec2_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/internal_events/aws_ecs_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;

use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::{
internal_event::{error_stage, error_type},
internal_event::{error_stage, error_type, InternalEvent},
json_size::JsonSize,
};

Expand Down
1 change: 0 additions & 1 deletion src/internal_events/aws_kinesis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// Used in both `aws_kinesis_streams` and `aws_kinesis_firehose` sinks
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/aws_sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use metrics::counter;
#[cfg(feature = "sources-aws_s3")]
pub use s3::*;
use vector_lib::internal_event::InternalEvent;

#[cfg(any(feature = "sources-aws_s3", feature = "sources-aws_sqs"))]
use vector_lib::internal_event::{error_stage, error_type};

Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/batch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/codecs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/common.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::time::Instant;

use crate::emit;
use metrics::{counter, histogram};
pub use vector_lib::internal_event::EventsReceived;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/conditions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug, Copy, Clone)]
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/datadog_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/datadog_traces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/dedupe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::emit;
use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/dnstap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/eventstoredb_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/exec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::time::Duration;

use crate::emit;
use metrics::{counter, histogram};
use tokio::time::error::Elapsed;
use vector_lib::internal_event::InternalEvent;
Expand Down
4 changes: 1 addition & 3 deletions src/internal_events/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use metrics::{counter, gauge};
use std::borrow::Cow;
use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, UNINTENTIONAL};

use crate::emit;

#[cfg(any(feature = "sources-file", feature = "sources-kubernetes_logs"))]
pub use self::source::*;

Expand Down Expand Up @@ -86,7 +84,7 @@ mod source {
use vector_lib::file_source::FileSourceInternalEvents;

use super::{FileOpen, InternalEvent};
use crate::emit;
use vector_lib::emit;
use vector_lib::{
internal_event::{error_stage, error_type},
json_size::JsonSize,
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/filter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use vector_lib::internal_event::{ComponentEventsDropped, Count, Registered, INTENTIONAL};

use crate::register;

vector_lib::registered_event! (
FilterEventsDropped => {
events_dropped: Registered<ComponentEventsDropped<'static, INTENTIONAL>>
Expand Down
2 changes: 1 addition & 1 deletion src/internal_events/fluent.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type};

use crate::sources::fluent::DecodeError;
use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
pub struct FluentMessageReceived {
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/gcp_pubsub.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

pub struct GcpPubsubConnectError {
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/host_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{error::Error, time::Duration};
use http::Response;
use metrics::{counter, histogram};
use vector_lib::internal_event::InternalEvent;

use vector_lib::{
internal_event::{error_stage, error_type},
json_size::JsonSize,
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use http::{
use hyper::{body::HttpBody, Error};
use metrics::{counter, histogram};
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/influxdb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/journald.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use metrics::counter;
use vector_lib::codecs::decoding::BoxedFramingError;
use vector_lib::internal_event::InternalEvent;

use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/internal_events/kafka.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use metrics::{counter, gauge};
use vector_lib::{internal_event::InternalEvent, update_counter};
use vrl::path::OwnedTargetPath;

use vector_lib::{
internal_event::{error_stage, error_type},
json_size::JsonSize,
};
use vrl::path::OwnedTargetPath;

#[derive(Debug)]
pub struct KafkaBytesReceived<'a> {
Expand Down
5 changes: 2 additions & 3 deletions src/internal_events/kubernetes_logs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use crate::emit;
use crate::event::Event;
use vector_lib::{
internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL},
json_size::JsonSize,
};

use crate::event::Event;

#[derive(Debug)]
pub struct KubernetesLogsEventsReceived<'a> {
pub file: &'a str,
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/log_to_metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::num::ParseFloatError;

use metrics::counter;
use vector_lib::internal_event::InternalEvent;

use crate::emit;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

pub struct LogToMetricFieldNullError<'a> {
Expand Down
1 change: 0 additions & 1 deletion src/internal_events/loki.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::emit;
use metrics::counter;
use vector_lib::internal_event::{error_stage, error_type};
use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL};
Expand Down
3 changes: 1 addition & 2 deletions src/internal_events/lua.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use metrics::{counter, gauge};
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

use crate::emit;
use crate::transforms::lua::v2::BuildError;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
pub struct LuaGcTriggered {
Expand Down
2 changes: 0 additions & 2 deletions src/internal_events/metric_to_log.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use metrics::counter;
use serde_json::Error;
use vector_lib::internal_event::InternalEvent;

use crate::emit;
use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};

#[derive(Debug)]
Expand Down
Loading
Loading