From 9d0802a8120685403e7da0e0ccf610ad31d9e7b0 Mon Sep 17 00:00:00 2001 From: Bruce Guenter Date: Mon, 6 Nov 2023 09:18:57 -0600 Subject: [PATCH] chore(dev): Move some macros into `vector-core` (#19002) * chore(dev): Move `emit` and `register` into `vector-core` * Move `impl_generate_config_from_default` to `vector-config` crate * Fix format --- lib/vector-config/src/component/generate.rs | 11 ++++++ lib/vector-core/src/lib.rs | 40 ++++++++++++++++++++ lib/vector-lib/src/lib.rs | 6 ++- src/conditions/vrl.rs | 4 +- src/config/mod.rs | 11 ------ src/config/unit_test/unit_test_components.rs | 1 - src/internal_events/adaptive_concurrency.rs | 1 - src/internal_events/aws_cloudwatch_logs.rs | 2 - src/internal_events/aws_ec2_metadata.rs | 1 - src/internal_events/aws_ecs_metrics.rs | 3 +- src/internal_events/aws_kinesis.rs | 1 - src/internal_events/aws_sqs.rs | 1 - src/internal_events/batch.rs | 2 - src/internal_events/codecs.rs | 2 - src/internal_events/common.rs | 2 - src/internal_events/conditions.rs | 1 - src/internal_events/datadog_metrics.rs | 2 - src/internal_events/datadog_traces.rs | 2 - src/internal_events/dedupe.rs | 1 - src/internal_events/dnstap.rs | 1 - src/internal_events/eventstoredb_metrics.rs | 1 - src/internal_events/exec.rs | 1 - src/internal_events/file.rs | 4 +- src/internal_events/filter.rs | 2 - src/internal_events/fluent.rs | 2 +- src/internal_events/gcp_pubsub.rs | 1 - src/internal_events/host_metrics.rs | 1 - src/internal_events/http.rs | 1 - src/internal_events/http_client.rs | 1 - src/internal_events/influxdb.rs | 1 - src/internal_events/journald.rs | 1 - src/internal_events/kafka.rs | 3 +- src/internal_events/kubernetes_logs.rs | 5 +-- src/internal_events/log_to_metric.rs | 2 - src/internal_events/loki.rs | 1 - src/internal_events/lua.rs | 3 +- src/internal_events/metric_to_log.rs | 2 - src/internal_events/mod.rs | 39 ------------------- src/internal_events/mongodb_metrics.rs | 1 - src/internal_events/nginx_metrics.rs | 4 +- src/internal_events/parser.rs | 2 - src/internal_events/postgresql_metrics.rs | 1 - src/internal_events/process.rs | 2 +- src/internal_events/prometheus.rs | 4 +- src/internal_events/pulsar.rs | 2 - src/internal_events/redis.rs | 1 - src/internal_events/remap.rs | 2 - src/internal_events/sample.rs | 1 - src/internal_events/sematext_metrics.rs | 4 +- src/internal_events/socket.rs | 2 - src/internal_events/splunk_hec.rs | 7 ++-- src/internal_events/statsd_sink.rs | 1 - src/internal_events/tag_cardinality_limit.rs | 1 - src/internal_events/tcp.rs | 5 +-- src/internal_events/template.rs | 4 +- src/internal_events/throttle.rs | 1 - src/internal_events/udp.rs | 7 ++-- src/internal_events/unix.rs | 7 ++-- src/internal_events/windows.rs | 1 - src/lib.rs | 2 + src/sinks/util/service/health.rs | 3 +- src/sinks/websocket/sink.rs | 3 +- 62 files changed, 88 insertions(+), 146 deletions(-) diff --git a/lib/vector-config/src/component/generate.rs b/lib/vector-config/src/component/generate.rs index d1df06af3eff0..c89421d58f04c 100644 --- a/lib/vector-config/src/component/generate.rs +++ b/lib/vector-config/src/component/generate.rs @@ -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() + } + } + }; +} diff --git a/lib/vector-core/src/lib.rs b/lib/vector-core/src/lib.rs index 70e2da523b374..33b8821abf843 100644 --- a/lib/vector-core/src/lib.rs +++ b/lib/vector-core/src/lib.rs @@ -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) + }; +} diff --git a/lib/vector-lib/src/lib.rs b/lib/vector-lib/src/lib.rs index 5bc3d84d7f3e6..ed8ef4af9b3e5 100644 --- a/lib/vector-lib/src/lib.rs +++ b/lib/vector-lib/src/lib.rs @@ -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; diff --git a/src/conditions/vrl.rs b/src/conditions/vrl.rs index a2ad30bcf68cc..adecd70d43cd0 100644 --- a/src/conditions/vrl.rs +++ b/src/conditions/vrl.rs @@ -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; @@ -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, }; diff --git a/src/config/mod.rs b/src/config/mod.rs index 4d39f5e1fd804..b7754bbf0078c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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 { diff --git a/src/config/unit_test/unit_test_components.rs b/src/config/unit_test/unit_test_components.rs index f99d7d5380f32..fcffaccea6ea0 100644 --- a/src/config/unit_test/unit_test_components.rs +++ b/src/config/unit_test/unit_test_components.rs @@ -16,7 +16,6 @@ use crate::{ config::{ AcknowledgementsConfig, SinkConfig, SinkContext, SourceConfig, SourceContext, SourceOutput, }, - impl_generate_config_from_default, sinks::Healthcheck, sources, }; diff --git a/src/internal_events/adaptive_concurrency.rs b/src/internal_events/adaptive_concurrency.rs index e0d7bb7c2cf7e..f40c05297ce61 100644 --- a/src/internal_events/adaptive_concurrency.rs +++ b/src/internal_events/adaptive_concurrency.rs @@ -1,7 +1,6 @@ use std::time::Duration; use metrics::{register_histogram, Histogram}; -use vector_lib::registered_event; #[derive(Clone, Copy)] pub struct AdaptiveConcurrencyLimitData { diff --git a/src/internal_events/aws_cloudwatch_logs.rs b/src/internal_events/aws_cloudwatch_logs.rs index 435342858848b..0d99c561785e7 100644 --- a/src/internal_events/aws_cloudwatch_logs.rs +++ b/src/internal_events/aws_cloudwatch_logs.rs @@ -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, diff --git a/src/internal_events/aws_ec2_metadata.rs b/src/internal_events/aws_ec2_metadata.rs index 6b9473aab17bd..0e60f5b96ba5f 100644 --- a/src/internal_events/aws_ec2_metadata.rs +++ b/src/internal_events/aws_ec2_metadata.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/internal_events/aws_ecs_metrics.rs b/src/internal_events/aws_ecs_metrics.rs index 1b5d051a893bb..8cff1ab405247 100644 --- a/src/internal_events/aws_ecs_metrics.rs +++ b/src/internal_events/aws_ecs_metrics.rs @@ -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, }; diff --git a/src/internal_events/aws_kinesis.rs b/src/internal_events/aws_kinesis.rs index bd0a156c5254b..43b75e769bd6d 100644 --- a/src/internal_events/aws_kinesis.rs +++ b/src/internal_events/aws_kinesis.rs @@ -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}; diff --git a/src/internal_events/aws_sqs.rs b/src/internal_events/aws_sqs.rs index 5af5b028072be..0033f37116ca3 100644 --- a/src/internal_events/aws_sqs.rs +++ b/src/internal_events/aws_sqs.rs @@ -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}; diff --git a/src/internal_events/batch.rs b/src/internal_events/batch.rs index e8a1c3e64d80b..f5091d9aa5eff 100644 --- a/src/internal_events/batch.rs +++ b/src/internal_events/batch.rs @@ -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)] diff --git a/src/internal_events/codecs.rs b/src/internal_events/codecs.rs index 5bba794b82667..b530dccdd4550 100644 --- a/src/internal_events/codecs.rs +++ b/src/internal_events/codecs.rs @@ -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)] diff --git a/src/internal_events/common.rs b/src/internal_events/common.rs index 661a96d2d074b..3f3bc6b158503 100644 --- a/src/internal_events/common.rs +++ b/src/internal_events/common.rs @@ -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)] diff --git a/src/internal_events/conditions.rs b/src/internal_events/conditions.rs index 92a8828e435b6..718cddc8d4e5d 100644 --- a/src/internal_events/conditions.rs +++ b/src/internal_events/conditions.rs @@ -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)] diff --git a/src/internal_events/datadog_metrics.rs b/src/internal_events/datadog_metrics.rs index 9d6d35c78d35d..af4255d70b184 100644 --- a/src/internal_events/datadog_metrics.rs +++ b/src/internal_events/datadog_metrics.rs @@ -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)] diff --git a/src/internal_events/datadog_traces.rs b/src/internal_events/datadog_traces.rs index 92df6f58e23f9..f20a660e3b806 100644 --- a/src/internal_events/datadog_traces.rs +++ b/src/internal_events/datadog_traces.rs @@ -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)] diff --git a/src/internal_events/dedupe.rs b/src/internal_events/dedupe.rs index e9bd7710ee8b6..d88930e0b6e49 100644 --- a/src/internal_events/dedupe.rs +++ b/src/internal_events/dedupe.rs @@ -1,4 +1,3 @@ -use crate::emit; use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL}; #[derive(Debug)] diff --git a/src/internal_events/dnstap.rs b/src/internal_events/dnstap.rs index 4631369c62153..5020f6322aebd 100644 --- a/src/internal_events/dnstap.rs +++ b/src/internal_events/dnstap.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/internal_events/eventstoredb_metrics.rs b/src/internal_events/eventstoredb_metrics.rs index 29a238b5eafef..7158b38e2fb63 100644 --- a/src/internal_events/eventstoredb_metrics.rs +++ b/src/internal_events/eventstoredb_metrics.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/internal_events/exec.rs b/src/internal_events/exec.rs index 3315734d56024..a2de45a6d2a2a 100644 --- a/src/internal_events/exec.rs +++ b/src/internal_events/exec.rs @@ -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; diff --git a/src/internal_events/file.rs b/src/internal_events/file.rs index 66a81b075edf4..9cbc1345b9508 100644 --- a/src/internal_events/file.rs +++ b/src/internal_events/file.rs @@ -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::*; @@ -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, diff --git a/src/internal_events/filter.rs b/src/internal_events/filter.rs index 867dbffa915da..cb54a3685284e 100644 --- a/src/internal_events/filter.rs +++ b/src/internal_events/filter.rs @@ -1,7 +1,5 @@ use vector_lib::internal_event::{ComponentEventsDropped, Count, Registered, INTENTIONAL}; -use crate::register; - vector_lib::registered_event! ( FilterEventsDropped => { events_dropped: Registered> diff --git a/src/internal_events/fluent.rs b/src/internal_events/fluent.rs index a27b6edbd2a27..6eb5d1d829ce1 100644 --- a/src/internal_events/fluent.rs +++ b/src/internal_events/fluent.rs @@ -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 { diff --git a/src/internal_events/gcp_pubsub.rs b/src/internal_events/gcp_pubsub.rs index 5d7754ad13403..686f2a6703c9c 100644 --- a/src/internal_events/gcp_pubsub.rs +++ b/src/internal_events/gcp_pubsub.rs @@ -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 { diff --git a/src/internal_events/host_metrics.rs b/src/internal_events/host_metrics.rs index 7c2b9c0ee2bfb..8b811aef56d35 100644 --- a/src/internal_events/host_metrics.rs +++ b/src/internal_events/host_metrics.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/internal_events/http.rs b/src/internal_events/http.rs index 45d560bb063eb..0ac345383bd83 100644 --- a/src/internal_events/http.rs +++ b/src/internal_events/http.rs @@ -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, diff --git a/src/internal_events/http_client.rs b/src/internal_events/http_client.rs index 43d2001b01c88..8fa1cdb918668 100644 --- a/src/internal_events/http_client.rs +++ b/src/internal_events/http_client.rs @@ -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)] diff --git a/src/internal_events/influxdb.rs b/src/internal_events/influxdb.rs index babe206896a72..075150b845f1e 100644 --- a/src/internal_events/influxdb.rs +++ b/src/internal_events/influxdb.rs @@ -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}; diff --git a/src/internal_events/journald.rs b/src/internal_events/journald.rs index 6536bafac6d28..0056b37d46a7d 100644 --- a/src/internal_events/journald.rs +++ b/src/internal_events/journald.rs @@ -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)] diff --git a/src/internal_events/kafka.rs b/src/internal_events/kafka.rs index 79785bb1b9f9d..bd09773843444 100644 --- a/src/internal_events/kafka.rs +++ b/src/internal_events/kafka.rs @@ -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> { diff --git a/src/internal_events/kubernetes_logs.rs b/src/internal_events/kubernetes_logs.rs index faae358774276..2829de42beffb 100644 --- a/src/internal_events/kubernetes_logs.rs +++ b/src/internal_events/kubernetes_logs.rs @@ -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, diff --git a/src/internal_events/log_to_metric.rs b/src/internal_events/log_to_metric.rs index dd6fa930a23c8..93e272b750611 100644 --- a/src/internal_events/log_to_metric.rs +++ b/src/internal_events/log_to_metric.rs @@ -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> { diff --git a/src/internal_events/loki.rs b/src/internal_events/loki.rs index 3290f8faf2761..c07b14ea450de 100644 --- a/src/internal_events/loki.rs +++ b/src/internal_events/loki.rs @@ -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}; diff --git a/src/internal_events/lua.rs b/src/internal_events/lua.rs index dba6dc0a529fe..4037344c3bc99 100644 --- a/src/internal_events/lua.rs +++ b/src/internal_events/lua.rs @@ -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 { diff --git a/src/internal_events/metric_to_log.rs b/src/internal_events/metric_to_log.rs index f3c34d249363e..66c146dfb84a3 100644 --- a/src/internal_events/metric_to_log.rs +++ b/src/internal_events/metric_to_log.rs @@ -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)] diff --git a/src/internal_events/mod.rs b/src/internal_events/mod.rs index 329d7a1d291a6..924215599c63e 100644 --- a/src/internal_events/mod.rs +++ b/src/internal_events/mod.rs @@ -263,42 +263,3 @@ pub use self::{ adaptive_concurrency::*, batch::*, common::*, conditions::*, encoding_transcode::*, heartbeat::*, http::*, open::*, process::*, socket::*, tcp::*, template::*, udp::*, }; - -// this version won't be needed once all `InternalEvent`s implement `name()` -#[cfg(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(test))] -#[macro_export] -macro_rules! emit { - ($event:expr) => { - vector_lib::internal_event::emit($event) - }; -} - -#[cfg(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(test))] -#[macro_export] -macro_rules! register { - ($event:expr) => { - vector_lib::internal_event::register($event) - }; -} diff --git a/src/internal_events/mongodb_metrics.rs b/src/internal_events/mongodb_metrics.rs index 43357274ef5e7..1112cb5ebe2fe 100644 --- a/src/internal_events/mongodb_metrics.rs +++ b/src/internal_events/mongodb_metrics.rs @@ -1,7 +1,6 @@ use metrics::counter; use mongodb::{bson, error::Error as MongoError}; use vector_lib::internal_event::InternalEvent; - use vector_lib::{ internal_event::{error_stage, error_type}, json_size::JsonSize, diff --git a/src/internal_events/nginx_metrics.rs b/src/internal_events/nginx_metrics.rs index 388910d764554..14928391b9aae 100644 --- a/src/internal_events/nginx_metrics.rs +++ b/src/internal_events/nginx_metrics.rs @@ -1,12 +1,12 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - -use crate::sources::nginx_metrics::parser::ParseError; use vector_lib::{ internal_event::{error_stage, error_type}, json_size::JsonSize, }; +use crate::sources::nginx_metrics::parser::ParseError; + #[derive(Debug)] pub struct NginxMetricsEventsReceived<'a> { pub byte_size: JsonSize, diff --git a/src/internal_events/parser.rs b/src/internal_events/parser.rs index ab1ffa466f8be..1eae63f470861 100644 --- a/src/internal_events/parser.rs +++ b/src/internal_events/parser.rs @@ -2,8 +2,6 @@ use std::borrow::Cow; use metrics::counter; use vector_lib::internal_event::InternalEvent; - -use crate::emit; use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; fn truncate_string_at(s: &str, maxlen: usize) -> Cow { diff --git a/src/internal_events/postgresql_metrics.rs b/src/internal_events/postgresql_metrics.rs index ebd6278ca258e..94a23bca78150 100644 --- a/src/internal_events/postgresql_metrics.rs +++ b/src/internal_events/postgresql_metrics.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/internal_events/process.rs b/src/internal_events/process.rs index 5b2aec0fdf6e5..acf2a1d6171f6 100644 --- a/src/internal_events/process.rs +++ b/src/internal_events/process.rs @@ -1,9 +1,9 @@ use metrics::counter; use metrics::gauge; use vector_lib::internal_event::InternalEvent; +use vector_lib::internal_event::{error_stage, error_type}; use crate::{built_info, config}; -use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] pub struct VectorStarted; diff --git a/src/internal_events/prometheus.rs b/src/internal_events/prometheus.rs index ef8ffceae6fda..c7a79314a970d 100644 --- a/src/internal_events/prometheus.rs +++ b/src/internal_events/prometheus.rs @@ -4,12 +4,10 @@ use std::borrow::Cow; use hyper::StatusCode; use metrics::counter; use vector_lib::internal_event::InternalEvent; +use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; #[cfg(feature = "sources-prometheus-scrape")] use vector_lib::prometheus::parser::ParserError; -use crate::emit; -use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; - #[cfg(feature = "sources-prometheus-scrape")] #[derive(Debug)] pub struct PrometheusParseError<'a> { diff --git a/src/internal_events/pulsar.rs b/src/internal_events/pulsar.rs index 66fd8704bbacf..46c45356e7f2c 100644 --- a/src/internal_events/pulsar.rs +++ b/src/internal_events/pulsar.rs @@ -1,7 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - -use crate::emit; use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; #[derive(Debug)] diff --git a/src/internal_events/redis.rs b/src/internal_events/redis.rs index 67ca84a59e886..c76dde5fb2e65 100644 --- a/src/internal_events/redis.rs +++ b/src/internal_events/redis.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/internal_events/remap.rs b/src/internal_events/remap.rs index 3727069ff40a1..211529e73c1d9 100644 --- a/src/internal_events/remap.rs +++ b/src/internal_events/remap.rs @@ -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, INTENTIONAL, UNINTENTIONAL, }; diff --git a/src/internal_events/sample.rs b/src/internal_events/sample.rs index 23cfc35633a9d..c113b2df545f7 100644 --- a/src/internal_events/sample.rs +++ b/src/internal_events/sample.rs @@ -1,4 +1,3 @@ -use crate::emit; use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL}; #[derive(Debug)] diff --git a/src/internal_events/sematext_metrics.rs b/src/internal_events/sematext_metrics.rs index 920f0cf963fe9..a0254220cf961 100644 --- a/src/internal_events/sematext_metrics.rs +++ b/src/internal_events/sematext_metrics.rs @@ -1,9 +1,9 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - -use crate::{emit, event::metric::Metric}; use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; +use crate::event::metric::Metric; + #[derive(Debug)] pub struct SematextMetricsInvalidMetricError<'a> { pub metric: &'a Metric, diff --git a/src/internal_events/socket.rs b/src/internal_events/socket.rs index c2e9904a9fb9d..157084d52f340 100644 --- a/src/internal_events/socket.rs +++ b/src/internal_events/socket.rs @@ -5,8 +5,6 @@ use vector_lib::{ json_size::JsonSize, }; -use crate::emit; - #[derive(Debug, Clone, Copy, Eq, PartialEq)] #[allow(dead_code)] // some features only use some variants pub enum SocketMode { diff --git a/src/internal_events/splunk_hec.rs b/src/internal_events/splunk_hec.rs index 905c0b9bad43f..70b498619c654 100644 --- a/src/internal_events/splunk_hec.rs +++ b/src/internal_events/splunk_hec.rs @@ -10,15 +10,14 @@ mod sink { use metrics::{counter, decrement_gauge, increment_gauge}; use serde_json::Error; use vector_lib::internal_event::InternalEvent; + use vector_lib::internal_event::{ + error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL, + }; use crate::{ - emit, event::metric::{MetricKind, MetricValue}, sinks::splunk_hec::common::acknowledgements::HecAckApiError, }; - use vector_lib::internal_event::{ - error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL, - }; #[derive(Debug)] pub struct SplunkEventEncodeError { diff --git a/src/internal_events/statsd_sink.rs b/src/internal_events/statsd_sink.rs index c7c1dbfc498dc..23911e16bcc0c 100644 --- a/src/internal_events/statsd_sink.rs +++ b/src/internal_events/statsd_sink.rs @@ -1,7 +1,6 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; -use crate::emit; use crate::event::metric::{MetricKind, MetricValue}; use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; diff --git a/src/internal_events/tag_cardinality_limit.rs b/src/internal_events/tag_cardinality_limit.rs index 6e5dd89029152..8a4cc0b69b466 100644 --- a/src/internal_events/tag_cardinality_limit.rs +++ b/src/internal_events/tag_cardinality_limit.rs @@ -1,4 +1,3 @@ -use crate::emit; use metrics::counter; use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL}; diff --git a/src/internal_events/tcp.rs b/src/internal_events/tcp.rs index 75b977b0c2858..8372e5fd45082 100644 --- a/src/internal_events/tcp.rs +++ b/src/internal_events/tcp.rs @@ -1,10 +1,9 @@ use std::net::SocketAddr; use metrics::counter; -use vector_lib::internal_event::InternalEvent; -use vector_lib::internal_event::{error_stage, error_type}; +use vector_lib::internal_event::{error_stage, error_type, InternalEvent}; -use crate::{emit, internal_events::SocketOutgoingConnectionError, tls::TlsError}; +use crate::{internal_events::SocketOutgoingConnectionError, tls::TlsError}; #[derive(Debug)] pub struct TcpSocketConnectionEstablished { diff --git a/src/internal_events/template.rs b/src/internal_events/template.rs index 433422d7dc58c..b1ee55f1b3c1b 100644 --- a/src/internal_events/template.rs +++ b/src/internal_events/template.rs @@ -1,8 +1,6 @@ -use crate::emit; use metrics::counter; -use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, UNINTENTIONAL}; - use vector_lib::internal_event::{error_stage, error_type}; +use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, UNINTENTIONAL}; pub struct TemplateRenderingError<'a> { pub field: Option<&'a str>, diff --git a/src/internal_events/throttle.rs b/src/internal_events/throttle.rs index d742ce5cc4a02..08321d194588f 100644 --- a/src/internal_events/throttle.rs +++ b/src/internal_events/throttle.rs @@ -1,4 +1,3 @@ -use crate::emit; use metrics::counter; use vector_lib::internal_event::{ComponentEventsDropped, InternalEvent, INTENTIONAL}; diff --git a/src/internal_events/udp.rs b/src/internal_events/udp.rs index 72a5e07ece5e6..6be04c017b9e7 100644 --- a/src/internal_events/udp.rs +++ b/src/internal_events/udp.rs @@ -1,8 +1,9 @@ use metrics::counter; -use vector_lib::internal_event::InternalEvent; -use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; +use vector_lib::internal_event::{ + error_stage, error_type, ComponentEventsDropped, InternalEvent, UNINTENTIONAL, +}; -use crate::{emit, internal_events::SocketOutgoingConnectionError}; +use crate::internal_events::SocketOutgoingConnectionError; // TODO: Get rid of this. UDP is connectionless, so there's no "successful" connect event, only // successfully binding a socket that can be used for receiving. diff --git a/src/internal_events/unix.rs b/src/internal_events/unix.rs index c6909dfa41213..f4730158fd5f4 100644 --- a/src/internal_events/unix.rs +++ b/src/internal_events/unix.rs @@ -1,10 +1,11 @@ use std::{io::Error, path::Path}; use metrics::counter; -use vector_lib::internal_event::InternalEvent; -use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL}; +use vector_lib::internal_event::{ + error_stage, error_type, ComponentEventsDropped, InternalEvent, UNINTENTIONAL, +}; -use crate::{emit, internal_events::SocketOutgoingConnectionError}; +use crate::internal_events::SocketOutgoingConnectionError; #[derive(Debug)] pub struct UnixSocketConnectionEstablished<'a> { diff --git a/src/internal_events/windows.rs b/src/internal_events/windows.rs index 2bd8158247cc2..2537ebca47c3e 100644 --- a/src/internal_events/windows.rs +++ b/src/internal_events/windows.rs @@ -1,6 +1,5 @@ use metrics::counter; use vector_lib::internal_event::InternalEvent; - use vector_lib::internal_event::{error_stage, error_type}; #[derive(Debug)] diff --git a/src/lib.rs b/src/lib.rs index 0657aeb65dccc..4465fa3e72390 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,8 @@ extern crate tracing; #[macro_use] extern crate derivative; +#[macro_use] +extern crate vector_lib; #[cfg(all(feature = "tikv-jemallocator", not(feature = "allocation-tracing")))] #[global_allocator] diff --git a/src/sinks/util/service/health.rs b/src/sinks/util/service/health.rs index a9b5e2b98abc0..c2f97c0cd296b 100644 --- a/src/sinks/util/service/health.rs +++ b/src/sinks/util/service/health.rs @@ -15,10 +15,9 @@ use serde_with::serde_as; use stream_cancel::{Trigger, Tripwire}; use tokio::time::{sleep, Duration}; use tower::Service; -use vector_lib::configurable::configurable_component; +use vector_lib::{configurable::configurable_component, emit}; use crate::{ - emit, internal_events::{EndpointsActive, OpenGauge, OpenToken}, sinks::util::retries::ExponentialBackoff, }; diff --git a/src/sinks/websocket/sink.rs b/src/sinks/websocket/sink.rs index 70c5bcffeeb45..7c59253c28c6f 100644 --- a/src/sinks/websocket/sink.rs +++ b/src/sinks/websocket/sink.rs @@ -25,6 +25,7 @@ use tokio_tungstenite::{ }; use tokio_util::codec::Encoder as _; use vector_lib::{ + emit, internal_event::{ ByteSize, BytesSent, CountByteSize, EventsSent, InternalEventHandle as _, Output, Protocol, }, @@ -33,7 +34,7 @@ use vector_lib::{ use crate::{ codecs::{Encoder, Transformer}, - dns, emit, + dns, event::{Event, EventStatus, Finalizable}, http::Auth, internal_events::{