diff --git a/Cargo.lock b/Cargo.lock index 9bab182e05373..2e217d2d24c4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12939,6 +12939,7 @@ dependencies = [ "sqlx", "stream-cancel", "strip-ansi-escapes", + "strum 0.28.0", "sysinfo", "syslog", "tempfile", @@ -13064,6 +13065,7 @@ dependencies = [ "serde_json", "smallvec", "stream-cancel", + "strum 0.28.0", "tokio", "tracing 0.1.44", "vector-common-macros", @@ -13191,6 +13193,7 @@ dependencies = [ "smallvec", "snafu 0.9.0", "socket2 0.5.10", + "strum 0.28.0", "tokio", "tokio-openssl", "tokio-stream", diff --git a/Cargo.toml b/Cargo.toml index 904f540cd26a5..e9cf7da0f400b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -479,6 +479,7 @@ openssl-src = { version = "300", default-features = false, features = ["force-en [dev-dependencies] approx = "0.5.1" +strum.workspace = true assert_cmd = { version = "2.0.17", default-features = false } aws-smithy-runtime = { version = "1.8.3", default-features = false, features = ["tls-rustls"] } base64 = "0.22.1" diff --git a/benches/metrics_snapshot.rs b/benches/metrics_snapshot.rs index 279911e5e65a4..4df220256f7b9 100644 --- a/benches/metrics_snapshot.rs +++ b/benches/metrics_snapshot.rs @@ -1,4 +1,7 @@ use criterion::{BenchmarkId, Criterion, criterion_group}; +use strum::IntoEnumIterator; +use vector_lib::counter; +use vector_lib::internal_event::CounterName; fn benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("metrics_snapshot"); @@ -22,8 +25,9 @@ fn prepare_metrics(cardinality: usize) -> &'static vector::metrics::Controller { let controller = vector::metrics::Controller::get().unwrap(); controller.reset(); + let name = CounterName::iter().next().unwrap(); for idx in 0..cardinality { - metrics::counter!("test", "idx" => idx.to_string()).increment(1); + counter!(name, "idx" => idx.to_string()).increment(1); } controller diff --git a/clippy.toml b/clippy.toml index cbd8c640fdb71..4aaa1eb15b360 100644 --- a/clippy.toml +++ b/clippy.toml @@ -8,6 +8,12 @@ disallowed-methods = [ { path = "vrl::stdlib::all", reason = "Use `vector_vrl_functions::all()` instead for consistency across all Vector VRL functions." }, ] +disallowed-macros = [ + { path = "metrics::counter", reason = "Use the `counter!` macro from `vector_common` with a `CounterName` variant instead of a raw string." }, + { path = "metrics::histogram", reason = "Use the `histogram!` macro from `vector_common` with a `HistogramName` variant instead of a raw string." }, + { path = "metrics::gauge", reason = "Use the `gauge!` macro from `vector_common` with a `GaugeName` variant instead of a raw string." }, +] + disallowed-types = [ { path = "once_cell::sync::OnceCell", reason = "Use `std::sync::OnceLock` instead." }, { path = "once_cell::unsync::OnceCell", reason = "Use `std::cell::OnceCell` instead." }, diff --git a/lib/codecs/src/internal_events.rs b/lib/codecs/src/internal_events.rs index d21119419887d..0518247e523a3 100644 --- a/lib/codecs/src/internal_events.rs +++ b/lib/codecs/src/internal_events.rs @@ -1,9 +1,12 @@ //! Internal events for codecs. -use metrics::counter; use tracing::error; -use vector_common::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, emit, error_stage, error_type, +use vector_common::{ + counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, emit, error_stage, + error_type, + }, }; use vector_common_macros::NamedInternalEvent; @@ -24,7 +27,7 @@ impl InternalEvent for DecoderFramingError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "decoder_frame", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -50,7 +53,7 @@ impl InternalEvent for DecoderDeserializeError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "decoder_deserialize", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -77,7 +80,7 @@ impl InternalEvent for EncoderFramingError<'_> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "encoder_frame", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, @@ -105,7 +108,7 @@ impl InternalEvent for EncoderSerializeError<'_> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "encoder_serialize", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, @@ -137,7 +140,7 @@ impl InternalEvent for EncoderWriteError<'_, E> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, ) @@ -170,7 +173,7 @@ impl InternalEvent for EncoderNullConstraintError<'_> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "encoding_null_constraint", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, @@ -201,7 +204,7 @@ impl InternalEvent for EncoderRecordBatchError<'_, E> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => self.error_code, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, @@ -228,7 +231,7 @@ impl InternalEvent for SchemaGenerationError<'_> { internal_log_rate_limit = false, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "parquet_schema_generation_failed", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, @@ -255,7 +258,7 @@ impl InternalEvent for ArrowWriterError<'_> { internal_log_rate_limit = false, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "parquet_arrow_writer_failed", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, @@ -281,7 +284,7 @@ impl InternalEvent for JsonSerializationError<'_> { internal_log_rate_limit = true, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::SENDING, ) diff --git a/lib/vector-buffers/src/internal_events.rs b/lib/vector-buffers/src/internal_events.rs index 6d2735c7bb75f..31a6089322d0c 100644 --- a/lib/vector-buffers/src/internal_events.rs +++ b/lib/vector-buffers/src/internal_events.rs @@ -1,9 +1,10 @@ use std::time::Duration; -use metrics::{Histogram, counter, gauge, histogram}; +use metrics::Histogram; use vector_common::NamedInternalEvent; use vector_common::{ - internal_event::{InternalEvent, error_type}, + counter, gauge, histogram, + internal_event::{CounterName, GaugeName, HistogramName, InternalEvent, error_type}, registered_event, }; @@ -21,14 +22,14 @@ impl InternalEvent for BufferCreated { let stage = self.idx.to_string(); if self.max_size_events != 0 { gauge!( - "buffer_max_size_events", + GaugeName::BufferMaxSizeEvents, "buffer_id" => self.buffer_id.clone(), "stage" => stage.clone(), ) .set(self.max_size_events as f64); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_max_event_size", + GaugeName::BufferMaxEventSize, "buffer_id" => self.buffer_id.clone(), "stage" => stage.clone(), ) @@ -36,14 +37,14 @@ impl InternalEvent for BufferCreated { } if self.max_size_bytes != 0 { gauge!( - "buffer_max_size_bytes", + GaugeName::BufferMaxSizeBytes, "buffer_id" => self.buffer_id.clone(), "stage" => stage.clone(), ) .set(self.max_size_bytes as f64); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_max_byte_size", + GaugeName::BufferMaxByteSize, "buffer_id" => self.buffer_id, "stage" => stage, ) @@ -66,40 +67,40 @@ impl InternalEvent for BufferEventsReceived { #[expect(clippy::cast_precision_loss)] fn emit(self) { counter!( - "buffer_received_events_total", + CounterName::BufferReceivedEventsTotal, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .increment(self.count); counter!( - "buffer_received_bytes_total", + CounterName::BufferReceivedBytesTotal, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .increment(self.byte_size); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_events", + GaugeName::BufferEvents, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_count as f64); gauge!( - "buffer_size_events", + GaugeName::BufferSizeEvents, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_count as f64); gauge!( - "buffer_size_bytes", + GaugeName::BufferSizeBytes, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_byte_size as f64); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_byte_size", + GaugeName::BufferByteSize, "buffer_id" => self.buffer_id, "stage" => self.idx.to_string() ) @@ -121,39 +122,39 @@ impl InternalEvent for BufferEventsSent { #[expect(clippy::cast_precision_loss)] fn emit(self) { counter!( - "buffer_sent_events_total", + CounterName::BufferSentEventsTotal, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .increment(self.count); counter!( - "buffer_sent_bytes_total", + CounterName::BufferSentBytesTotal, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .increment(self.byte_size); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_events", + GaugeName::BufferEvents, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_count as f64); gauge!( - "buffer_size_events", + GaugeName::BufferSizeEvents, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_count as f64); gauge!( - "buffer_size_bytes", + GaugeName::BufferSizeBytes, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_byte_size as f64); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_byte_size", + GaugeName::BufferByteSize, "buffer_id" => self.buffer_id, "stage" => self.idx.to_string() ) @@ -200,14 +201,14 @@ impl InternalEvent for BufferEventsDropped { } counter!( - "buffer_discarded_events_total", + CounterName::BufferDiscardedEventsTotal, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string(), "intentional" => intentional_str, ) .increment(self.count); counter!( - "buffer_discarded_bytes_total", + CounterName::BufferDiscardedBytesTotal, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string(), "intentional" => intentional_str, @@ -215,26 +216,26 @@ impl InternalEvent for BufferEventsDropped { .increment(self.byte_size); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_events", + GaugeName::BufferEvents, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_count as f64); gauge!( - "buffer_size_events", + GaugeName::BufferSizeEvents, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_count as f64); gauge!( - "buffer_size_bytes", + GaugeName::BufferSizeBytes, "buffer_id" => self.buffer_id.clone(), "stage" => self.idx.to_string() ) .set(self.total_byte_size as f64); // DEPRECATED: buffer-bytes-events-metrics gauge!( - "buffer_byte_size", + GaugeName::BufferByteSize, "buffer_id" => self.buffer_id, "stage" => self.idx.to_string() ) @@ -258,7 +259,7 @@ impl InternalEvent for BufferReadError { stage = "processing", ); counter!( - "buffer_errors_total", "error_code" => self.error_code, + CounterName::BufferErrorsTotal, "error_code" => self.error_code, "error_type" => "reader_failed", "stage" => "processing", ) @@ -270,7 +271,7 @@ registered_event! { BufferSendDuration { stage: usize, } => { - send_duration: Histogram = histogram!("buffer_send_duration_seconds", "stage" => self.stage.to_string()), + send_duration: Histogram = histogram!(HistogramName::BufferSendDurationSeconds, "stage" => self.stage.to_string()), } fn emit(&self, duration: Duration) { diff --git a/lib/vector-buffers/src/topology/channel/limited_queue.rs b/lib/vector-buffers/src/topology/channel/limited_queue.rs index a246aa9659812..3e1f3f7c98c93 100644 --- a/lib/vector-buffers/src/topology/channel/limited_queue.rs +++ b/lib/vector-buffers/src/topology/channel/limited_queue.rs @@ -127,6 +127,7 @@ struct Metrics { impl Metrics { #[expect(clippy::cast_precision_loss)] // We have to convert buffer sizes for a gauge, it's okay to lose precision here. + #[allow(clippy::disallowed_macros)] // Metric names are constructed dynamically from runtime prefixes. fn new( limit: MemoryBufferSize, metadata: ChannelMetricMetadata, diff --git a/lib/vector-common/Cargo.toml b/lib/vector-common/Cargo.toml index 95098f19b1bd3..a583641c68cec 100644 --- a/lib/vector-common/Cargo.toml +++ b/lib/vector-common/Cargo.toml @@ -48,6 +48,7 @@ pin-project.workspace = true serde.workspace = true serde_json.workspace = true smallvec = { version = "1", default-features = false } +strum.workspace = true stream-cancel = { version = "0.8.2", default-features = false } tokio = { workspace = true, features = ["macros", "time"] } tracing.workspace = true diff --git a/lib/vector-common/src/internal_event/bytes_received.rs b/lib/vector-common/src/internal_event/bytes_received.rs index 98044ecb84570..4264c3cbc365a 100644 --- a/lib/vector-common/src/internal_event/bytes_received.rs +++ b/lib/vector-common/src/internal_event/bytes_received.rs @@ -1,12 +1,14 @@ -use metrics::{Counter, counter}; +use metrics::Counter; -use super::{ByteSize, Protocol, SharedString}; +use crate::counter; + +use super::{ByteSize, CounterName, Protocol, SharedString}; crate::registered_event!( BytesReceived { protocol: SharedString, } => { - received_bytes: Counter = counter!("component_received_bytes_total", "protocol" => self.protocol.clone()), + received_bytes: Counter = counter!(CounterName::ComponentReceivedBytesTotal, "protocol" => self.protocol.clone()), protocol: SharedString = self.protocol, } diff --git a/lib/vector-common/src/internal_event/bytes_sent.rs b/lib/vector-common/src/internal_event/bytes_sent.rs index 0b2a88247f96c..b363893783f43 100644 --- a/lib/vector-common/src/internal_event/bytes_sent.rs +++ b/lib/vector-common/src/internal_event/bytes_sent.rs @@ -1,13 +1,15 @@ -use metrics::{Counter, counter}; +use metrics::Counter; + +use crate::counter; use tracing::trace; -use super::{ByteSize, Protocol, SharedString}; +use super::{ByteSize, CounterName, Protocol, SharedString}; crate::registered_event!( BytesSent { protocol: SharedString, } => { - bytes_sent: Counter = counter!("component_sent_bytes_total", "protocol" => self.protocol.clone()), + bytes_sent: Counter = counter!(CounterName::ComponentSentBytesTotal, "protocol" => self.protocol.clone()), protocol: SharedString = self.protocol, } diff --git a/lib/vector-common/src/internal_event/cached_event.rs b/lib/vector-common/src/internal_event/cached_event.rs index 782faeb5a1d01..ec3d492998ab4 100644 --- a/lib/vector-common/src/internal_event/cached_event.rs +++ b/lib/vector-common/src/internal_event/cached_event.rs @@ -91,34 +91,36 @@ where #[cfg(test)] mod tests { #![allow(unreachable_pub)] - use metrics::{Counter, counter}; + use metrics::Counter; + use strum::IntoEnumIterator; use super::*; - - crate::registered_event!( - TestEvent { - fixed: String, - dynamic: String, - } => { - event: Counter = { - counter!("test_event_total", "fixed" => self.fixed, "dynamic" => self.dynamic) - }, - } - - fn emit(&self, count: u64) { - self.event.increment(count); - } - - fn register(fixed: String, dynamic: String) { - crate::internal_event::register(TestEvent { - fixed, - dynamic, - }) - } - ); + use crate::internal_event::CounterName; #[test] fn test_fixed_tag() { + crate::registered_event!( + TestEvent { + fixed: String, + dynamic: String, + } => { + event: Counter = { + crate::counter!(CounterName::iter().next().unwrap(), "fixed" => self.fixed, "dynamic" => self.dynamic) + }, + } + + fn emit(&self, count: u64) { + self.event.increment(count); + } + + fn register(fixed: String, dynamic: String) { + crate::internal_event::register(TestEvent { + fixed, + dynamic, + }) + } + ); + let event: RegisteredEventCache = RegisteredEventCache::new("fixed".to_string()); diff --git a/lib/vector-common/src/internal_event/component_events_dropped.rs b/lib/vector-common/src/internal_event/component_events_dropped.rs index bf45c054e45e1..8421d1d0f49ae 100644 --- a/lib/vector-common/src/internal_event/component_events_dropped.rs +++ b/lib/vector-common/src/internal_event/component_events_dropped.rs @@ -1,6 +1,8 @@ -use metrics::{Counter, counter}; +use metrics::Counter; -use super::{Count, InternalEvent, InternalEventHandle, RegisterInternalEvent}; +use crate::counter; + +use super::{Count, CounterName, InternalEvent, InternalEventHandle, RegisterInternalEvent}; use crate::NamedInternalEvent; pub const INTENTIONAL: bool = true; @@ -32,7 +34,7 @@ impl<'a, const INTENTIONAL: bool> RegisterInternalEvent fn register(self) -> Self::Handle { Self::Handle { discarded_events: counter!( - "component_discarded_events_total", + CounterName::ComponentDiscardedEventsTotal, "intentional" => if INTENTIONAL { "true" } else { "false" }, ), reason: self.reason, diff --git a/lib/vector-common/src/internal_event/component_events_timed_out.rs b/lib/vector-common/src/internal_event/component_events_timed_out.rs index bf138dd1481c7..4662322fe9776 100644 --- a/lib/vector-common/src/internal_event/component_events_timed_out.rs +++ b/lib/vector-common/src/internal_event/component_events_timed_out.rs @@ -1,13 +1,15 @@ -use metrics::{Counter, counter}; +use metrics::Counter; -use super::Count; +use crate::counter; + +use super::{Count, CounterName}; crate::registered_event! { ComponentEventsTimedOut { reason: &'static str, } => { - timed_out_events: Counter = counter!("component_timed_out_events_total"), - timed_out_requests: Counter = counter!("component_timed_out_requests_total"), + timed_out_events: Counter = counter!(CounterName::ComponentTimedOutEventsTotal), + timed_out_requests: Counter = counter!(CounterName::ComponentTimedOutRequestsTotal), reason: &'static str = self.reason, } diff --git a/lib/vector-common/src/internal_event/events_received.rs b/lib/vector-common/src/internal_event/events_received.rs index 40ba999a8cfca..a08ebc6e8438b 100644 --- a/lib/vector-common/src/internal_event/events_received.rs +++ b/lib/vector-common/src/internal_event/events_received.rs @@ -1,13 +1,15 @@ -use metrics::{Counter, Histogram, counter, histogram}; +use metrics::{Counter, Histogram}; + +use crate::{counter, histogram}; use tracing::trace; -use super::CountByteSize; +use super::{CountByteSize, CounterName, HistogramName}; crate::registered_event!( EventsReceived => { - events_count: Histogram = histogram!("component_received_events_count"), - events: Counter = counter!("component_received_events_total"), - event_bytes: Counter = counter!("component_received_event_bytes_total"), + events_count: Histogram = histogram!(HistogramName::ComponentReceivedEventsCount), + events: Counter = counter!(CounterName::ComponentReceivedEventsTotal), + event_bytes: Counter = counter!(CounterName::ComponentReceivedEventBytesTotal), } fn emit(&self, data: CountByteSize) { diff --git a/lib/vector-common/src/internal_event/events_sent.rs b/lib/vector-common/src/internal_event/events_sent.rs index 21e11260b2d38..3ae63db761381 100644 --- a/lib/vector-common/src/internal_event/events_sent.rs +++ b/lib/vector-common/src/internal_event/events_sent.rs @@ -1,9 +1,11 @@ use std::sync::Arc; -use metrics::{Counter, counter}; +use metrics::Counter; + +use crate::counter; use tracing::trace; -use super::{CountByteSize, OptionalTag, Output, SharedString}; +use super::{CountByteSize, CounterName, OptionalTag, Output, SharedString}; use crate::config::ComponentKey; pub const DEFAULT_OUTPUT: &str = "_default"; @@ -13,14 +15,14 @@ crate::registered_event!( output: Option, } => { events: Counter = if let Some(output) = &self.output { - counter!("component_sent_events_total", "output" => output.clone()) + counter!(CounterName::ComponentSentEventsTotal, "output" => output.clone()) } else { - counter!("component_sent_events_total") + counter!(CounterName::ComponentSentEventsTotal) }, event_bytes: Counter = if let Some(output) = &self.output { - counter!("component_sent_event_bytes_total", "output" => output.clone()) + counter!(CounterName::ComponentSentEventBytesTotal, "output" => output.clone()) } else { - counter!("component_sent_event_bytes_total") + counter!(CounterName::ComponentSentEventBytesTotal) }, output: Option = self.output, } @@ -75,10 +77,10 @@ crate::registered_event!( service: OptionalTag, } => { events: Counter = { - counter!("component_sent_events_total", &make_tags(&self.source, &self.service)) + counter!(CounterName::ComponentSentEventsTotal, &make_tags(&self.source, &self.service)) }, event_bytes: Counter = { - counter!("component_sent_event_bytes_total", &make_tags(&self.source, &self.service)) + counter!(CounterName::ComponentSentEventBytesTotal, &make_tags(&self.source, &self.service)) }, } diff --git a/lib/vector-common/src/internal_event/metric_name.rs b/lib/vector-common/src/internal_event/metric_name.rs new file mode 100644 index 0000000000000..21314695a13bf --- /dev/null +++ b/lib/vector-common/src/internal_event/metric_name.rs @@ -0,0 +1,337 @@ +use strum::{AsRefStr, Display, EnumIter}; + +/// Canonical list of all per-component internal metric names emitted by Vector. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, AsRefStr, EnumIter)] +#[strum(serialize_all = "snake_case")] +pub enum CounterName { + ComponentReceivedEventsTotal, + ComponentReceivedEventBytesTotal, + ComponentReceivedBytesTotal, + ComponentSentEventsTotal, + ComponentSentEventBytesTotal, + ComponentSentBytesTotal, + ComponentDiscardedEventsTotal, + ComponentErrorsTotal, + ComponentTimedOutEventsTotal, + ComponentTimedOutRequestsTotal, + BufferReceivedEventsTotal, + BufferReceivedBytesTotal, + BufferSentEventsTotal, + BufferSentBytesTotal, + BufferDiscardedEventsTotal, + BufferDiscardedBytesTotal, + BufferErrorsTotal, + // Internal events from src/internal_events/ + AggregateEventsRecordedTotal, + AggregateFailedUpdates, + AggregateFlushesTotal, + ApiStartedTotal, + CheckpointsTotal, + ChecksumErrorsTotal, + CollectCompletedTotal, + CommandExecutedTotal, + ConnectionEstablishedTotal, + ConnectionSendErrorsTotal, + ConnectionShutdownTotal, + ContainerProcessedEventsTotal, + ContainersUnwatchedTotal, + ContainersWatchedTotal, + DecoderBomRemovalsTotal, + DecoderMalformedReplacementWarningsTotal, + DorisBytesLoadedTotal, + DorisRowsFilteredTotal, + DorisRowsLoadedTotal, + EncoderUnmappableReplacementWarningsTotal, + EventsDiscardedTotal, + FilesAddedTotal, + FilesDeletedTotal, + FilesResumedTotal, + FilesUnwatchedTotal, + GrpcServerMessagesReceivedTotal, + GrpcServerMessagesSentTotal, + HttpClientErrorsTotal, + HttpClientRequestsSentTotal, + HttpClientResponsesTotal, + HttpServerRequestsReceivedTotal, + HttpServerResponsesSentTotal, + KafkaConsumedMessagesBytesTotal, + KafkaConsumedMessagesTotal, + KafkaProducedMessagesBytesTotal, + KafkaProducedMessagesTotal, + KafkaRequestsBytesTotal, + KafkaRequestsTotal, + KafkaResponsesBytesTotal, + KafkaResponsesTotal, + MetadataRefreshFailedTotal, + MetadataRefreshSuccessfulTotal, + ParseErrorsTotal, + QuitTotal, + ReloadedTotal, + RewrittenTimestampEventsTotal, + SqsMessageDeferSucceededTotal, + SqsMessageDeleteSucceededTotal, + SqsMessageProcessingSucceededTotal, + SqsMessageReceiveSucceededTotal, + SqsMessageReceivedMessagesTotal, + StaleEventsFlushedTotal, + StartedTotal, + StoppedTotal, + TagValueLimitExceededTotal, + ValueLimitReachedTotal, + WebsocketBytesSentTotal, + WebsocketMessagesSentTotal, + WindowsServiceInstallTotal, + WindowsServiceRestartTotal, + WindowsServiceStartTotal, + WindowsServiceStopTotal, + WindowsServiceUninstallTotal, + K8sEventNamespaceAnnotationFailuresTotal, + K8sEventNodeAnnotationFailuresTotal, + K8sFormatPickerEdgeCasesTotal, + K8sDockerFormatParseFailuresTotal, + SqsS3EventRecordIgnoredTotal, + ComponentAllocatedBytesTotal, + ComponentDeallocatedBytesTotal, + MemoryEnrichmentTableFailedInsertions, + MemoryEnrichmentTableFailedReads, + MemoryEnrichmentTableFlushesTotal, + MemoryEnrichmentTableInsertionsTotal, + MemoryEnrichmentTableReadsTotal, + MemoryEnrichmentTableTtlExpirations, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, AsRefStr, EnumIter)] +#[strum(serialize_all = "snake_case")] +pub enum HistogramName { + ComponentReceivedEventsCount, + ComponentReceivedBytes, + BufferSendDurationSeconds, + ComponentLatencySeconds, + SourceLagTimeSeconds, + SourceSendLatencySeconds, + SourceSendBatchLatencySeconds, + AdaptiveConcurrencyAveragedRtt, + AdaptiveConcurrencyBackPressure, + AdaptiveConcurrencyInFlight, + AdaptiveConcurrencyLimit, + AdaptiveConcurrencyObservedRtt, + AdaptiveConcurrencyPastRttMean, + AdaptiveConcurrencyReachedLimit, + S3ObjectProcessingSucceededDurationSeconds, + S3ObjectProcessingFailedDurationSeconds, + CollectDurationSeconds, + CommandExecutionDurationSeconds, + GrpcServerHandlerDurationSeconds, + HttpServerHandlerDurationSeconds, + HttpClientRttSeconds, + HttpClientResponseRttSeconds, + HttpClientErrorRttSeconds, +} + +impl HistogramName { + #[must_use] + pub const fn as_str(self) -> &'static str { + match self { + Self::ComponentReceivedEventsCount => "component_received_events_count", + Self::ComponentReceivedBytes => "component_received_bytes", + Self::BufferSendDurationSeconds => "buffer_send_duration_seconds", + Self::ComponentLatencySeconds => "component_latency_seconds", + Self::SourceLagTimeSeconds => "source_lag_time_seconds", + Self::SourceSendLatencySeconds => "source_send_latency_seconds", + Self::SourceSendBatchLatencySeconds => "source_send_batch_latency_seconds", + Self::AdaptiveConcurrencyAveragedRtt => "adaptive_concurrency_averaged_rtt", + Self::AdaptiveConcurrencyBackPressure => "adaptive_concurrency_back_pressure", + Self::AdaptiveConcurrencyInFlight => "adaptive_concurrency_in_flight", + Self::AdaptiveConcurrencyLimit => "adaptive_concurrency_limit", + Self::AdaptiveConcurrencyObservedRtt => "adaptive_concurrency_observed_rtt", + Self::AdaptiveConcurrencyPastRttMean => "adaptive_concurrency_past_rtt_mean", + Self::AdaptiveConcurrencyReachedLimit => "adaptive_concurrency_reached_limit", + Self::S3ObjectProcessingSucceededDurationSeconds => { + "s3_object_processing_succeeded_duration_seconds" + } + Self::S3ObjectProcessingFailedDurationSeconds => { + "s3_object_processing_failed_duration_seconds" + } + Self::CollectDurationSeconds => "collect_duration_seconds", + Self::CommandExecutionDurationSeconds => "command_execution_duration_seconds", + Self::GrpcServerHandlerDurationSeconds => "grpc_server_handler_duration_seconds", + Self::HttpServerHandlerDurationSeconds => "http_server_handler_duration_seconds", + Self::HttpClientRttSeconds => "http_client_rtt_seconds", + Self::HttpClientResponseRttSeconds => "http_client_response_rtt_seconds", + Self::HttpClientErrorRttSeconds => "http_client_error_rtt_seconds", + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, AsRefStr, EnumIter)] +#[strum(serialize_all = "snake_case")] +pub enum GaugeName { + ComponentLatencyMeanSeconds, + BufferMaxSizeEvents, + BufferMaxEventSize, + BufferMaxSizeBytes, + BufferMaxByteSize, + BufferEvents, + BufferSizeEvents, + BufferSizeBytes, + BufferByteSize, + Utilization, + ComponentAllocatedBytes, + OpenFiles, + UptimeSeconds, + BuildInfo, + KafkaQueueMessages, + KafkaQueueMessagesBytes, + KafkaConsumerLag, + LuaMemoryUsedBytes, + OpenConnections, + ActiveEndpoints, + SplunkPendingAcks, + ActiveClients, + MemoryEnrichmentTableObjectsCount, + MemoryEnrichmentTableByteSize, +} + +impl GaugeName { + #[must_use] + pub const fn as_str(self) -> &'static str { + match self { + Self::ComponentLatencyMeanSeconds => "component_latency_mean_seconds", + Self::BufferMaxSizeEvents => "buffer_max_size_events", + Self::BufferMaxEventSize => "buffer_max_event_size", + Self::BufferMaxSizeBytes => "buffer_max_size_bytes", + Self::BufferMaxByteSize => "buffer_max_byte_size", + Self::BufferEvents => "buffer_events", + Self::BufferSizeEvents => "buffer_size_events", + Self::BufferSizeBytes => "buffer_size_bytes", + Self::BufferByteSize => "buffer_byte_size", + Self::Utilization => "utilization", + Self::ComponentAllocatedBytes => "component_allocated_bytes", + Self::OpenFiles => "open_files", + Self::UptimeSeconds => "uptime_seconds", + Self::BuildInfo => "build_info", + Self::KafkaQueueMessages => "kafka_queue_messages", + Self::KafkaQueueMessagesBytes => "kafka_queue_messages_bytes", + Self::KafkaConsumerLag => "kafka_consumer_lag", + Self::LuaMemoryUsedBytes => "lua_memory_used_bytes", + Self::OpenConnections => "open_connections", + Self::ActiveEndpoints => "active_endpoints", + Self::SplunkPendingAcks => "splunk_pending_acks", + Self::ActiveClients => "active_clients", + Self::MemoryEnrichmentTableObjectsCount => "memory_enrichment_table_objects_count", + Self::MemoryEnrichmentTableByteSize => "memory_enrichment_table_byte_size", + } + } +} + +impl CounterName { + #[allow(clippy::too_many_lines)] + #[must_use] + pub const fn as_str(self) -> &'static str { + match self { + Self::ComponentReceivedEventsTotal => "component_received_events_total", + Self::ComponentReceivedEventBytesTotal => "component_received_event_bytes_total", + Self::ComponentReceivedBytesTotal => "component_received_bytes_total", + Self::ComponentSentEventsTotal => "component_sent_events_total", + Self::ComponentSentEventBytesTotal => "component_sent_event_bytes_total", + Self::ComponentSentBytesTotal => "component_sent_bytes_total", + Self::ComponentDiscardedEventsTotal => "component_discarded_events_total", + Self::ComponentErrorsTotal => "component_errors_total", + Self::ComponentTimedOutEventsTotal => "component_timed_out_events_total", + Self::ComponentTimedOutRequestsTotal => "component_timed_out_requests_total", + Self::BufferReceivedEventsTotal => "buffer_received_events_total", + Self::BufferReceivedBytesTotal => "buffer_received_bytes_total", + Self::BufferSentEventsTotal => "buffer_sent_events_total", + Self::BufferSentBytesTotal => "buffer_sent_bytes_total", + Self::BufferDiscardedEventsTotal => "buffer_discarded_events_total", + Self::BufferDiscardedBytesTotal => "buffer_discarded_bytes_total", + Self::BufferErrorsTotal => "buffer_errors_total", + Self::AggregateEventsRecordedTotal => "aggregate_events_recorded_total", + Self::AggregateFailedUpdates => "aggregate_failed_updates", + Self::AggregateFlushesTotal => "aggregate_flushes_total", + Self::ApiStartedTotal => "api_started_total", + Self::CheckpointsTotal => "checkpoints_total", + Self::ChecksumErrorsTotal => "checksum_errors_total", + Self::CollectCompletedTotal => "collect_completed_total", + Self::CommandExecutedTotal => "command_executed_total", + Self::ConnectionEstablishedTotal => "connection_established_total", + Self::ConnectionSendErrorsTotal => "connection_send_errors_total", + Self::ConnectionShutdownTotal => "connection_shutdown_total", + Self::ContainerProcessedEventsTotal => "container_processed_events_total", + Self::ContainersUnwatchedTotal => "containers_unwatched_total", + Self::ContainersWatchedTotal => "containers_watched_total", + Self::DecoderBomRemovalsTotal => "decoder_bom_removals_total", + Self::DecoderMalformedReplacementWarningsTotal => { + "decoder_malformed_replacement_warnings_total" + } + Self::DorisBytesLoadedTotal => "doris_bytes_loaded_total", + Self::DorisRowsFilteredTotal => "doris_rows_filtered_total", + Self::DorisRowsLoadedTotal => "doris_rows_loaded_total", + Self::EncoderUnmappableReplacementWarningsTotal => { + "encoder_unmappable_replacement_warnings_total" + } + Self::EventsDiscardedTotal => "events_discarded_total", + Self::FilesAddedTotal => "files_added_total", + Self::FilesDeletedTotal => "files_deleted_total", + Self::FilesResumedTotal => "files_resumed_total", + Self::FilesUnwatchedTotal => "files_unwatched_total", + Self::GrpcServerMessagesReceivedTotal => "grpc_server_messages_received_total", + Self::GrpcServerMessagesSentTotal => "grpc_server_messages_sent_total", + Self::HttpClientErrorsTotal => "http_client_errors_total", + Self::HttpClientRequestsSentTotal => "http_client_requests_sent_total", + Self::HttpClientResponsesTotal => "http_client_responses_total", + Self::HttpServerRequestsReceivedTotal => "http_server_requests_received_total", + Self::HttpServerResponsesSentTotal => "http_server_responses_sent_total", + Self::KafkaConsumedMessagesBytesTotal => "kafka_consumed_messages_bytes_total", + Self::KafkaConsumedMessagesTotal => "kafka_consumed_messages_total", + Self::KafkaProducedMessagesBytesTotal => "kafka_produced_messages_bytes_total", + Self::KafkaProducedMessagesTotal => "kafka_produced_messages_total", + Self::KafkaRequestsBytesTotal => "kafka_requests_bytes_total", + Self::KafkaRequestsTotal => "kafka_requests_total", + Self::KafkaResponsesBytesTotal => "kafka_responses_bytes_total", + Self::KafkaResponsesTotal => "kafka_responses_total", + Self::MetadataRefreshFailedTotal => "metadata_refresh_failed_total", + Self::MetadataRefreshSuccessfulTotal => "metadata_refresh_successful_total", + Self::ParseErrorsTotal => "parse_errors_total", + Self::QuitTotal => "quit_total", + Self::ReloadedTotal => "reloaded_total", + Self::RewrittenTimestampEventsTotal => "rewritten_timestamp_events_total", + Self::SqsMessageDeferSucceededTotal => "sqs_message_defer_succeeded_total", + Self::SqsMessageDeleteSucceededTotal => "sqs_message_delete_succeeded_total", + Self::SqsMessageProcessingSucceededTotal => "sqs_message_processing_succeeded_total", + Self::SqsMessageReceiveSucceededTotal => "sqs_message_receive_succeeded_total", + Self::SqsMessageReceivedMessagesTotal => "sqs_message_received_messages_total", + Self::StaleEventsFlushedTotal => "stale_events_flushed_total", + Self::StartedTotal => "started_total", + Self::StoppedTotal => "stopped_total", + Self::TagValueLimitExceededTotal => "tag_value_limit_exceeded_total", + Self::ValueLimitReachedTotal => "value_limit_reached_total", + Self::WebsocketBytesSentTotal => "websocket_bytes_sent_total", + Self::WebsocketMessagesSentTotal => "websocket_messages_sent_total", + Self::WindowsServiceInstallTotal => "windows_service_install_total", + Self::WindowsServiceRestartTotal => "windows_service_restart_total", + Self::WindowsServiceStartTotal => "windows_service_start_total", + Self::WindowsServiceStopTotal => "windows_service_stop_total", + Self::WindowsServiceUninstallTotal => "windows_service_uninstall_total", + Self::K8sEventNamespaceAnnotationFailuresTotal => { + "k8s_event_namespace_annotation_failures_total" + } + Self::K8sEventNodeAnnotationFailuresTotal => "k8s_event_node_annotation_failures_total", + Self::K8sFormatPickerEdgeCasesTotal => "k8s_format_picker_edge_cases_total", + Self::K8sDockerFormatParseFailuresTotal => "k8s_docker_format_parse_failures_total", + Self::SqsS3EventRecordIgnoredTotal => "sqs_s3_event_record_ignored_total", + Self::ComponentAllocatedBytesTotal => "component_allocated_bytes_total", + Self::ComponentDeallocatedBytesTotal => "component_deallocated_bytes_total", + Self::MemoryEnrichmentTableFailedInsertions => { + "memory_enrichment_table_failed_insertions" + } + Self::MemoryEnrichmentTableFailedReads => "memory_enrichment_table_failed_reads", + Self::MemoryEnrichmentTableFlushesTotal => "memory_enrichment_table_flushes_total", + Self::MemoryEnrichmentTableInsertionsTotal => { + "memory_enrichment_table_insertions_total" + } + Self::MemoryEnrichmentTableReadsTotal => "memory_enrichment_table_reads_total", + Self::MemoryEnrichmentTableTtlExpirations => "memory_enrichment_table_ttl_expirations", + } + } +} diff --git a/lib/vector-common/src/internal_event/mod.rs b/lib/vector-common/src/internal_event/mod.rs index 272e2344900e3..e776e89553172 100644 --- a/lib/vector-common/src/internal_event/mod.rs +++ b/lib/vector-common/src/internal_event/mod.rs @@ -5,6 +5,7 @@ pub mod component_events_dropped; pub mod component_events_timed_out; mod events_received; mod events_sent; +pub mod metric_name; mod optional_tag; mod prelude; pub mod service; @@ -19,6 +20,7 @@ pub use component_events_dropped::{ComponentEventsDropped, INTENTIONAL, UNINTENT pub use component_events_timed_out::ComponentEventsTimedOut; pub use events_received::{EventsReceived, EventsReceivedHandle}; pub use events_sent::{DEFAULT_OUTPUT, EventsSent, TaggedEventsSent}; +pub use metric_name::{CounterName, GaugeName, HistogramName}; pub use metrics::SharedString; pub use optional_tag::OptionalTag; pub use prelude::{error_stage, error_type}; diff --git a/lib/vector-common/src/internal_event/service.rs b/lib/vector-common/src/internal_event/service.rs index 93a3c9b745722..60d615b3d61a0 100644 --- a/lib/vector-common/src/internal_event/service.rs +++ b/lib/vector-common/src/internal_event/service.rs @@ -1,4 +1,6 @@ -use metrics::counter; +use super::CounterName; + +use crate::counter; use super::{ComponentEventsDropped, InternalEvent, UNINTENTIONAL, emit, error_stage, error_type}; use crate::NamedInternalEvent; @@ -17,7 +19,7 @@ impl InternalEvent for PollReadyError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::SENDING, ) @@ -43,7 +45,7 @@ impl InternalEvent for CallError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::SENDING, ) diff --git a/lib/vector-common/src/lib.rs b/lib/vector-common/src/lib.rs index 099a068578090..75849aac75884 100644 --- a/lib/vector-common/src/lib.rs +++ b/lib/vector-common/src/lib.rs @@ -66,6 +66,63 @@ pub mod trigger; #[macro_use] extern crate tracing; +/// Typed wrapper around `metrics::counter!` that only accepts [`internal_event::CounterName`]. +#[macro_export] +macro_rules! counter { + ($name:expr) => {{ + let _name: $crate::internal_event::CounterName = $name; + #[allow(clippy::disallowed_macros)] + { + metrics::counter!(_name.as_str()) + } + }}; + ($name:expr, $($rest:tt)*) => {{ + let _name: $crate::internal_event::CounterName = $name; + #[allow(clippy::disallowed_macros)] + { + metrics::counter!(_name.as_str(), $($rest)*) + } + }}; +} + +/// Typed wrapper around `metrics::histogram!` that only accepts [`internal_event::HistogramName`]. +#[macro_export] +macro_rules! histogram { + ($name:expr) => {{ + let _name: $crate::internal_event::HistogramName = $name; + #[allow(clippy::disallowed_macros)] + { + metrics::histogram!(_name.as_str()) + } + }}; + ($name:expr, $($rest:tt)*) => {{ + let _name: $crate::internal_event::HistogramName = $name; + #[allow(clippy::disallowed_macros)] + { + metrics::histogram!(_name.as_str(), $($rest)*) + } + }}; +} + +/// Typed wrapper around `metrics::gauge!` that only accepts [`internal_event::GaugeName`]. +#[macro_export] +macro_rules! gauge { + ($name:expr) => {{ + let _name: $crate::internal_event::GaugeName = $name; + #[allow(clippy::disallowed_macros)] + { + metrics::gauge!(_name.as_str()) + } + }}; + ($name:expr, $($rest:tt)*) => {{ + let _name: $crate::internal_event::GaugeName = $name; + #[allow(clippy::disallowed_macros)] + { + metrics::gauge!(_name.as_str(), $($rest)*) + } + }}; +} + /// Vector's basic error type, dynamically dispatched and safe to send across /// threads. pub type Error = Box; diff --git a/lib/vector-core/Cargo.toml b/lib/vector-core/Cargo.toml index 5c3370ac1a526..edf7b43a4a74f 100644 --- a/lib/vector-core/Cargo.toml +++ b/lib/vector-core/Cargo.toml @@ -78,6 +78,7 @@ prost-build.workspace = true [dev-dependencies] base64 = "0.22.1" +strum.workspace = true chrono-tz.workspace = true criterion = { workspace = true, features = ["html_reports"] } env-test-util = "1.0.1" diff --git a/lib/vector-core/src/latency.rs b/lib/vector-core/src/latency.rs index 536a8ef532d0d..b25ca73427749 100644 --- a/lib/vector-core/src/latency.rs +++ b/lib/vector-core/src/latency.rs @@ -1,12 +1,14 @@ use std::time::Instant; -use metrics::{Histogram, gauge, histogram}; +use metrics::Histogram; use vector_common::stats::EwmaGauge; +use vector_common::{ + gauge, histogram, + internal_event::{GaugeName, HistogramName}, +}; use crate::event::EventArray; -const COMPONENT_LATENCY: &str = "component_latency_seconds"; -const COMPONENT_LATENCY_MEAN: &str = "component_latency_mean_seconds"; const DEFAULT_LATENCY_EWMA_ALPHA: f64 = 0.9; #[derive(Debug)] @@ -18,9 +20,9 @@ pub struct LatencyRecorder { impl LatencyRecorder { pub fn new(ewma_alpha: Option) -> Self { Self { - histogram: histogram!(COMPONENT_LATENCY), + histogram: histogram!(HistogramName::ComponentLatencySeconds), gauge: EwmaGauge::new( - gauge!(COMPONENT_LATENCY_MEAN), + gauge!(GaugeName::ComponentLatencyMeanSeconds), ewma_alpha.or(Some(DEFAULT_LATENCY_EWMA_ALPHA)), ), } diff --git a/lib/vector-core/src/metrics/mod.rs b/lib/vector-core/src/metrics/mod.rs index cd900d392f004..ea4c040163c7f 100644 --- a/lib/vector-core/src/metrics/mod.rs +++ b/lib/vector-core/src/metrics/mod.rs @@ -202,6 +202,12 @@ impl Controller { #[cfg(test)] mod tests { + use strum::IntoEnumIterator; + use vector_common::{ + counter, gauge, + internal_event::{CounterName, GaugeName}, + }; + use super::*; use crate::{ config::metrics_expiration::{ @@ -224,8 +230,9 @@ mod tests { let controller = Controller::get().unwrap(); controller.reset(); + let name = CounterName::iter().next().unwrap(); for idx in 0..cardinality { - metrics::counter!("test", "idx" => idx.to_string()).increment(1); + counter!(name, "idx" => idx.to_string()).increment(1); } let metrics = controller.capture_metrics(); @@ -253,11 +260,11 @@ mod tests { fn handles_registered_metrics() { let controller = init_metrics(); - let counter = metrics::counter!("test7"); + let counter = counter!(CounterName::iter().next().unwrap()); assert_eq!(controller.capture_metrics().len(), 3); counter.increment(1); assert_eq!(controller.capture_metrics().len(), 3); - let gauge = metrics::gauge!("test8"); + let gauge = gauge!(GaugeName::iter().next().unwrap()); assert_eq!(controller.capture_metrics().len(), 4); gauge.set(1.0); assert_eq!(controller.capture_metrics().len(), 4); @@ -270,12 +277,16 @@ mod tests { .set_expiry(Some(IDLE_TIMEOUT), Vec::new()) .unwrap(); - metrics::counter!("test2").increment(1); - metrics::counter!("test3").increment(2); + let mut names = CounterName::iter(); + let name_a = names.next().unwrap(); + let name_b = names.next().unwrap(); + + counter!(name_a).increment(1); + counter!(name_b).increment(2); assert_eq!(controller.capture_metrics().len(), 4); std::thread::sleep(Duration::from_secs_f64(IDLE_TIMEOUT * 2.0)); - metrics::counter!("test2").increment(3); + counter!(name_a).increment(3); assert_eq!(controller.capture_metrics().len(), 3); } @@ -286,12 +297,13 @@ mod tests { .set_expiry(Some(IDLE_TIMEOUT), Vec::new()) .unwrap(); - metrics::counter!("test4", "tag" => "value1").increment(1); - metrics::counter!("test4", "tag" => "value2").increment(2); + let name = CounterName::iter().next().unwrap(); + counter!(name, "tag" => "value1").increment(1); + counter!(name, "tag" => "value2").increment(2); assert_eq!(controller.capture_metrics().len(), 4); std::thread::sleep(Duration::from_secs_f64(IDLE_TIMEOUT * 2.0)); - metrics::counter!("test4", "tag" => "value1").increment(3); + counter!(name, "tag" => "value1").increment(3); assert_eq!(controller.capture_metrics().len(), 3); } @@ -302,8 +314,12 @@ mod tests { .set_expiry(Some(IDLE_TIMEOUT), Vec::new()) .unwrap(); - let a = metrics::counter!("test5"); - metrics::counter!("test6").increment(5); + let mut names = CounterName::iter(); + let name_a = names.next().unwrap(); + let name_b = names.next().unwrap(); + + let a = counter!(name_a); + counter!(name_b).increment(5); assert_eq!(controller.capture_metrics().len(), 4); a.increment(1); assert_eq!(controller.capture_metrics().len(), 4); @@ -316,7 +332,7 @@ mod tests { assert_eq!(metrics.len(), 3); let metric = metrics .into_iter() - .find(|metric| metric.name() == "test5") + .find(|metric| metric.name() == name_a.as_str()) .expect("Test metric is not present"); match metric.value() { MetricValue::Counter { value } => assert_eq!(*value, 2.0), @@ -327,12 +343,17 @@ mod tests { #[test] fn expires_metrics_per_set() { let controller = init_metrics(); + + let mut names = CounterName::iter(); + let name_a = names.next().unwrap(); + let name_b = names.next().unwrap(); + controller .set_expiry( None, vec![PerMetricSetExpiration { name: Some(MetricNameMatcherConfig::Exact { - value: "test3".to_string(), + value: name_b.as_str().to_string(), }), labels: None, expire_secs: IDLE_TIMEOUT, @@ -340,25 +361,32 @@ mod tests { ) .unwrap(); - metrics::counter!("test2").increment(1); - metrics::counter!("test3").increment(2); + counter!(name_a).increment(1); + counter!(name_b).increment(2); assert_eq!(controller.capture_metrics().len(), 4); std::thread::sleep(Duration::from_secs_f64(IDLE_TIMEOUT * 2.0)); - metrics::counter!("test2").increment(3); + counter!(name_a).increment(3); assert_eq!(controller.capture_metrics().len(), 3); } #[test] fn expires_metrics_multiple_different_sets() { let controller = init_metrics(); + + let mut names = CounterName::iter(); + let name_a = names.next().unwrap(); + let name_b = names.next().unwrap(); + let name_c = names.next().unwrap(); + let name_d = names.next().unwrap(); + controller .set_expiry( Some(IDLE_TIMEOUT * 3.0), vec![ PerMetricSetExpiration { name: Some(MetricNameMatcherConfig::Exact { - value: "test3".to_string(), + value: name_c.as_str().to_string(), }), labels: None, expire_secs: IDLE_TIMEOUT, @@ -377,22 +405,22 @@ mod tests { ) .unwrap(); - metrics::counter!("test1").increment(1); - metrics::counter!("test2").increment(1); - metrics::counter!("test3").increment(2); - metrics::counter!("test4", "tag" => "value1").increment(3); + counter!(name_a).increment(1); + counter!(name_b).increment(1); + counter!(name_c).increment(2); + counter!(name_d, "tag" => "value1").increment(3); assert_eq!(controller.capture_metrics().len(), 6); std::thread::sleep(Duration::from_secs_f64(IDLE_TIMEOUT * 1.5)); - metrics::counter!("test2").increment(3); + counter!(name_b).increment(3); assert_eq!(controller.capture_metrics().len(), 5); std::thread::sleep(Duration::from_secs_f64(IDLE_TIMEOUT)); - metrics::counter!("test2").increment(3); + counter!(name_b).increment(3); assert_eq!(controller.capture_metrics().len(), 4); std::thread::sleep(Duration::from_secs_f64(IDLE_TIMEOUT)); - metrics::counter!("test2").increment(3); + counter!(name_b).increment(3); assert_eq!(controller.capture_metrics().len(), 3); } } diff --git a/lib/vector-core/src/source_sender/builder.rs b/lib/vector-core/src/source_sender/builder.rs index f3051726a7f56..7f9f5d522497a 100644 --- a/lib/vector-core/src/source_sender/builder.rs +++ b/lib/vector-core/src/source_sender/builder.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, time::Duration}; -use metrics::histogram; use vector_buffers::topology::channel::LimitedReceiver; +use vector_common::histogram; use vector_common::internal_event::DEFAULT_OUTPUT; use super::{ diff --git a/lib/vector-core/src/source_sender/mod.rs b/lib/vector-core/src/source_sender/mod.rs index fc0cb417890a0..24eb23688c0a1 100644 --- a/lib/vector-core/src/source_sender/mod.rs +++ b/lib/vector-core/src/source_sender/mod.rs @@ -22,6 +22,8 @@ pub const CHUNK_SIZE: usize = 1000; #[cfg(any(test, feature = "test"))] const TEST_BUFFER_SIZE: usize = 100; -const LAG_TIME_NAME: &str = "source_lag_time_seconds"; -const SEND_LATENCY_NAME: &str = "source_send_latency_seconds"; -const SEND_BATCH_LATENCY_NAME: &str = "source_send_batch_latency_seconds"; +use vector_common::internal_event::HistogramName; + +const LAG_TIME_NAME: HistogramName = HistogramName::SourceLagTimeSeconds; +const SEND_LATENCY_NAME: HistogramName = HistogramName::SourceSendLatencySeconds; +const SEND_BATCH_LATENCY_NAME: HistogramName = HistogramName::SourceSendBatchLatencySeconds; diff --git a/lib/vector-core/src/source_sender/sender.rs b/lib/vector-core/src/source_sender/sender.rs index 6041dad3dad9f..d5834ab0edff5 100644 --- a/lib/vector-core/src/source_sender/sender.rs +++ b/lib/vector-core/src/source_sender/sender.rs @@ -5,12 +5,12 @@ use std::{collections::HashMap, time::Instant}; use futures::Stream; #[cfg(any(test, feature = "test"))] use futures::StreamExt as _; -#[cfg(any(test, feature = "test"))] -use metrics::histogram; use vector_buffers::EventCount; #[cfg(any(test, feature = "test"))] use vector_buffers::topology::channel::LimitedReceiver; #[cfg(any(test, feature = "test"))] +use vector_common::histogram; +#[cfg(any(test, feature = "test"))] use vector_common::internal_event::DEFAULT_OUTPUT; #[cfg(doc)] use vector_common::internal_event::{ComponentEventsDropped, EventsSent}; diff --git a/lib/vector-lib/src/lib.rs b/lib/vector-lib/src/lib.rs index 82bb67cf9afce..277d28df18e92 100644 --- a/lib/vector-lib/src/lib.rs +++ b/lib/vector-lib/src/lib.rs @@ -11,9 +11,9 @@ pub use vector_buffers as buffers; pub use vector_common::event_test_util; pub use vector_common::{ Error, NamedInternalEvent, Result, TimeZone, assert_event_data_eq, atomic, btreemap, - byte_size_of, byte_size_of::ByteSizeOf, conversion, encode_logfmt, finalization, finalizer, id, - impl_event_data_eq, internal_event, json_size, registered_event, request_metadata, - sensitive_string, shutdown, stats, trigger, + byte_size_of, byte_size_of::ByteSizeOf, conversion, counter, encode_logfmt, finalization, + finalizer, gauge, histogram, id, impl_event_data_eq, internal_event, json_size, + registered_event, request_metadata, sensitive_string, shutdown, stats, trigger, }; pub use vector_config as configurable; pub use vector_config::impl_generate_config_from_default; diff --git a/scripts/check-events b/scripts/check-events index 5d4411b601802..18a3c61b85418 100755 --- a/scripts/check-events +++ b/scripts/check-events @@ -78,11 +78,22 @@ class Event # Scan for counter names and tags def scan_metrics(block) + # Match string literal names: counter!("metric_name", ...) block.scan(/ (counter|gauge|histogram)!\((?:\n\s+)?"([^"]+)",?(.+?)\)[;\n]/ms) \ do |type, name, tags| tags = Hash[tags.scan(/"([^"]+)" => (.+?)(?:,|$)/)] add_metric(type, name, tags) end + # Match typed enum names: counter!(CounterName::VariantName, ...) + block.scan(/ (counter|gauge|histogram)!\((?:\n\s+)?\w+Name::(\w+),?(.+?)\)[;\n]/ms) \ + do |type, variant, tags| + # Convert CamelCase variant name to snake_case metric name + name = variant.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .downcase + tags = Hash[tags.scan(/"([^"]+)" => (.+?)(?:,|$)/)] + add_metric(type, name, tags) + end end # Scan the registered event macro block diff --git a/src/enrichment_tables/memory/internal_events.rs b/src/enrichment_tables/memory/internal_events.rs index 0799c6662a6af..dfd7b8d6f4c78 100644 --- a/src/enrichment_tables/memory/internal_events.rs +++ b/src/enrichment_tables/memory/internal_events.rs @@ -1,6 +1,8 @@ -use metrics::{counter, gauge}; use vector_lib::{ - NamedInternalEvent, configurable::configurable_component, internal_event::InternalEvent, + NamedInternalEvent, + configurable::configurable_component, + counter, gauge, + internal_event::{CounterName, GaugeName, InternalEvent}, }; /// Configuration of internal metrics for enrichment memory table. @@ -26,12 +28,12 @@ impl InternalEvent for MemoryEnrichmentTableRead<'_> { fn emit(self) { if self.include_key_metric_tag { counter!( - "memory_enrichment_table_reads_total", + CounterName::MemoryEnrichmentTableReadsTotal, "key" => self.key.to_owned() ) .increment(1); } else { - counter!("memory_enrichment_table_reads_total",).increment(1); + counter!(CounterName::MemoryEnrichmentTableReadsTotal,).increment(1); } } } @@ -46,12 +48,12 @@ impl InternalEvent for MemoryEnrichmentTableInserted<'_> { fn emit(self) { if self.include_key_metric_tag { counter!( - "memory_enrichment_table_insertions_total", + CounterName::MemoryEnrichmentTableInsertionsTotal, "key" => self.key.to_owned() ) .increment(1); } else { - counter!("memory_enrichment_table_insertions_total",).increment(1); + counter!(CounterName::MemoryEnrichmentTableInsertionsTotal,).increment(1); } } } @@ -64,9 +66,9 @@ pub(crate) struct MemoryEnrichmentTableFlushed { impl InternalEvent for MemoryEnrichmentTableFlushed { fn emit(self) { - counter!("memory_enrichment_table_flushes_total",).increment(1); - gauge!("memory_enrichment_table_objects_count",).set(self.new_objects_count as f64); - gauge!("memory_enrichment_table_byte_size",).set(self.new_byte_size as f64); + counter!(CounterName::MemoryEnrichmentTableFlushesTotal,).increment(1); + gauge!(GaugeName::MemoryEnrichmentTableObjectsCount,).set(self.new_objects_count as f64); + gauge!(GaugeName::MemoryEnrichmentTableByteSize,).set(self.new_byte_size as f64); } } @@ -80,12 +82,12 @@ impl InternalEvent for MemoryEnrichmentTableTtlExpired<'_> { fn emit(self) { if self.include_key_metric_tag { counter!( - "memory_enrichment_table_ttl_expirations", + CounterName::MemoryEnrichmentTableTtlExpirations, "key" => self.key.to_owned() ) .increment(1); } else { - counter!("memory_enrichment_table_ttl_expirations",).increment(1); + counter!(CounterName::MemoryEnrichmentTableTtlExpirations,).increment(1); } } } @@ -100,12 +102,12 @@ impl InternalEvent for MemoryEnrichmentTableReadFailed<'_> { fn emit(self) { if self.include_key_metric_tag { counter!( - "memory_enrichment_table_failed_reads", + CounterName::MemoryEnrichmentTableFailedReads, "key" => self.key.to_owned() ) .increment(1); } else { - counter!("memory_enrichment_table_failed_reads",).increment(1); + counter!(CounterName::MemoryEnrichmentTableFailedReads,).increment(1); } } } @@ -120,12 +122,12 @@ impl InternalEvent for MemoryEnrichmentTableInsertFailed<'_> { fn emit(self) { if self.include_key_metric_tag { counter!( - "memory_enrichment_table_failed_insertions", + CounterName::MemoryEnrichmentTableFailedInsertions, "key" => self.key.to_owned() ) .increment(1); } else { - counter!("memory_enrichment_table_failed_insertions",).increment(1); + counter!(CounterName::MemoryEnrichmentTableFailedInsertions,).increment(1); } } } diff --git a/src/internal_events/adaptive_concurrency.rs b/src/internal_events/adaptive_concurrency.rs index f815f7d4e2b4b..b43ec8452e20b 100644 --- a/src/internal_events/adaptive_concurrency.rs +++ b/src/internal_events/adaptive_concurrency.rs @@ -1,6 +1,7 @@ use std::time::Duration; -use metrics::{Histogram, histogram}; +use metrics::Histogram; +use vector_lib::{histogram, internal_event::HistogramName}; #[derive(Clone, Copy)] pub struct AdaptiveConcurrencyLimitData { @@ -17,10 +18,10 @@ registered_event! { // These are histograms, as they may have a number of different // values over each reporting interval, and each of those values // is valuable for diagnosis. - limit: Histogram = histogram!("adaptive_concurrency_limit"), - reached_limit: Histogram = histogram!("adaptive_concurrency_reached_limit"), - back_pressure: Histogram = histogram!("adaptive_concurrency_back_pressure"), - past_rtt_mean: Histogram = histogram!("adaptive_concurrency_past_rtt_mean"), + limit: Histogram = histogram!(HistogramName::AdaptiveConcurrencyLimit), + reached_limit: Histogram = histogram!(HistogramName::AdaptiveConcurrencyReachedLimit), + back_pressure: Histogram = histogram!(HistogramName::AdaptiveConcurrencyBackPressure), + past_rtt_mean: Histogram = histogram!(HistogramName::AdaptiveConcurrencyPastRttMean), } fn emit(&self, data: AdaptiveConcurrencyLimitData) { @@ -36,7 +37,7 @@ registered_event! { registered_event! { AdaptiveConcurrencyInFlight => { - in_flight: Histogram = histogram!("adaptive_concurrency_in_flight"), + in_flight: Histogram = histogram!(HistogramName::AdaptiveConcurrencyInFlight), } fn emit(&self, in_flight: u64) { @@ -46,7 +47,7 @@ registered_event! { registered_event! { AdaptiveConcurrencyObservedRtt => { - observed_rtt: Histogram = histogram!("adaptive_concurrency_observed_rtt"), + observed_rtt: Histogram = histogram!(HistogramName::AdaptiveConcurrencyObservedRtt), } fn emit(&self, rtt: Duration) { @@ -56,7 +57,7 @@ registered_event! { registered_event! { AdaptiveConcurrencyAveragedRtt => { - averaged_rtt: Histogram = histogram!("adaptive_concurrency_averaged_rtt"), + averaged_rtt: Histogram = histogram!(HistogramName::AdaptiveConcurrencyAveragedRtt), } fn emit(&self, rtt: Duration) { diff --git a/src/internal_events/aggregate.rs b/src/internal_events/aggregate.rs index 1b70c4350f614..96f48f5de013c 100644 --- a/src/internal_events/aggregate.rs +++ b/src/internal_events/aggregate.rs @@ -1,13 +1,14 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub struct AggregateEventRecorded; impl InternalEvent for AggregateEventRecorded { fn emit(self) { - counter!("aggregate_events_recorded_total").increment(1); + counter!(CounterName::AggregateEventsRecordedTotal).increment(1); } } @@ -16,7 +17,7 @@ pub struct AggregateFlushed; impl InternalEvent for AggregateFlushed { fn emit(self) { - counter!("aggregate_flushes_total").increment(1); + counter!(CounterName::AggregateFlushesTotal).increment(1); } } @@ -25,6 +26,6 @@ pub struct AggregateUpdateFailed; impl InternalEvent for AggregateUpdateFailed { fn emit(self) { - counter!("aggregate_failed_updates").increment(1); + counter!(CounterName::AggregateFailedUpdates).increment(1); } } diff --git a/src/internal_events/amqp.rs b/src/internal_events/amqp.rs index 45acdf201305a..e7864acc44e98 100644 --- a/src/internal_events/amqp.rs +++ b/src/internal_events/amqp.rs @@ -1,8 +1,9 @@ #[cfg(feature = "sources-amqp")] pub mod source { - use metrics::counter; - use vector_lib::NamedInternalEvent; - use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; + use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, + }; #[derive(Debug, NamedInternalEvent)] pub struct AmqpBytesReceived { @@ -18,7 +19,7 @@ pub mod source { protocol = %self.protocol, ); counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => self.protocol, ) .increment(self.byte_size as u64); @@ -38,7 +39,7 @@ pub mod source { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, ) @@ -59,7 +60,7 @@ pub mod source { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::RECEIVING, ) @@ -80,7 +81,7 @@ pub mod source { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::COMMAND_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/apache_metrics.rs b/src/internal_events/apache_metrics.rs index dd5e9c34e4cf5..544dda88ba5a6 100644 --- a/src/internal_events/apache_metrics.rs +++ b/src/internal_events/apache_metrics.rs @@ -1,7 +1,6 @@ -use metrics::counter; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -19,12 +18,12 @@ impl InternalEvent for ApacheMetricsEventsReceived<'_> { fn emit(self) { trace!(message = "Events received.", count = %self.count, byte_size = %self.byte_size, endpoint = %self.endpoint); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "endpoint" => self.endpoint.to_owned(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "endpoint" => self.endpoint.to_owned(), ) .increment(self.byte_size.get() as u64); @@ -47,7 +46,7 @@ impl InternalEvent for ApacheMetricsParseError<'_> { endpoint = %self.endpoint, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::PARSER_FAILED, "endpoint" => self.endpoint.to_owned(), diff --git a/src/internal_events/api.rs b/src/internal_events/api.rs index de2cb9588537d..b9196989471c8 100644 --- a/src/internal_events/api.rs +++ b/src/internal_events/api.rs @@ -1,8 +1,9 @@ use std::net::SocketAddr; -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub struct ApiStarted { @@ -15,6 +16,6 @@ impl InternalEvent for ApiStarted { message = "API server running.", address = %self.addr, ); - counter!("api_started_total").increment(1); + counter!(CounterName::ApiStartedTotal).increment(1); } } diff --git a/src/internal_events/aws.rs b/src/internal_events/aws.rs index ff4da6c01e56b..d4c91776d7d55 100644 --- a/src/internal_events/aws.rs +++ b/src/internal_events/aws.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent}, +}; #[derive(NamedInternalEvent)] pub struct AwsBytesSent { @@ -21,7 +22,7 @@ impl InternalEvent for AwsBytesSent { region = ?self.region, ); counter!( - "component_sent_bytes_total", + CounterName::ComponentSentBytesTotal, "protocol" => "https", "region" => region, ) diff --git a/src/internal_events/aws_cloudwatch_logs.rs b/src/internal_events/aws_cloudwatch_logs.rs index 6325d6c71b25d..b4964f25d84fe 100644 --- a/src/internal_events/aws_cloudwatch_logs.rs +++ b/src/internal_events/aws_cloudwatch_logs.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct AwsCloudwatchLogsMessageSizeError { @@ -22,7 +21,7 @@ impl InternalEvent for AwsCloudwatchLogsMessageSizeError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "message_too_long", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/aws_ec2_metadata.rs b/src/internal_events/aws_ec2_metadata.rs index 43c28aee61272..c59364c75348c 100644 --- a/src/internal_events/aws_ec2_metadata.rs +++ b/src/internal_events/aws_ec2_metadata.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct AwsEc2MetadataRefreshSuccessful; @@ -8,7 +9,7 @@ pub struct AwsEc2MetadataRefreshSuccessful; impl InternalEvent for AwsEc2MetadataRefreshSuccessful { fn emit(self) { debug!(message = "AWS EC2 metadata refreshed."); - counter!("metadata_refresh_successful_total").increment(1); + counter!(CounterName::MetadataRefreshSuccessfulTotal).increment(1); } } @@ -26,12 +27,12 @@ impl InternalEvent for AwsEc2MetadataRefreshError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::PROCESSING, ) .increment(1); // deprecated - counter!("metadata_refresh_failed_total").increment(1); + counter!(CounterName::MetadataRefreshFailedTotal).increment(1); } } diff --git a/src/internal_events/aws_ecs_metrics.rs b/src/internal_events/aws_ecs_metrics.rs index 86b0d32012713..59127134e2666 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::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -24,12 +23,12 @@ impl InternalEvent for AwsEcsMetricsEventsReceived<'_> { endpoint = %self.endpoint, ); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "endpoint" => self.endpoint.to_string(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "endpoint" => self.endpoint.to_string(), ) .increment(self.byte_size.get() as u64); @@ -57,9 +56,9 @@ impl InternalEvent for AwsEcsMetricsParseError<'_> { endpoint = %self.endpoint, "Failed to parse response.", ); - counter!("parse_errors_total").increment(1); + counter!(CounterName::ParseErrorsTotal).increment(1); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::PARSER_FAILED, "endpoint" => self.endpoint.to_string(), diff --git a/src/internal_events/aws_kinesis.rs b/src/internal_events/aws_kinesis.rs index 9fa2fb4315118..f8a7dcff49de2 100644 --- a/src/internal_events/aws_kinesis.rs +++ b/src/internal_events/aws_kinesis.rs @@ -1,8 +1,8 @@ -/// Used in both `aws_kinesis_streams` and `aws_kinesis_firehose` sinks -use metrics::counter; use vector_lib::NamedInternalEvent; +/// Used in both `aws_kinesis_streams` and `aws_kinesis_firehose` sinks +use vector_lib::counter; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; #[derive(Debug, NamedInternalEvent)] @@ -22,7 +22,7 @@ impl InternalEvent for AwsKinesisStreamNoPartitionKeyError<'_> { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/aws_kinesis_firehose.rs b/src/internal_events/aws_kinesis_firehose.rs index 6cb4ae43ea51f..58f976839debd 100644 --- a/src/internal_events/aws_kinesis_firehose.rs +++ b/src/internal_events/aws_kinesis_firehose.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; use super::prelude::{http_error_code, io_error_code}; use crate::sources::aws_kinesis_firehose::Compression; @@ -49,7 +50,7 @@ impl InternalEvent for AwsKinesisFirehoseRequestError<'_> { request_id = %self.request_id.unwrap_or(""), ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::RECEIVING, "error_type" => error_type::REQUEST_FAILED, "error_code" => self.error_code, @@ -75,7 +76,7 @@ impl InternalEvent for AwsKinesisFirehoseAutomaticRecordDecodeError { compression = %self.compression, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::PARSER_FAILED, "error_code" => io_error_code(&self.error), diff --git a/src/internal_events/aws_sqs.rs b/src/internal_events/aws_sqs.rs index 4bdcc8ef48e6c..51e8b78d23941 100644 --- a/src/internal_events/aws_sqs.rs +++ b/src/internal_events/aws_sqs.rs @@ -1,11 +1,13 @@ #![allow(dead_code)] // TODO requires optional feature compilation -use metrics::counter; #[cfg(feature = "sources-aws_s3")] pub use s3::*; +use vector_lib::counter; #[cfg(any(feature = "sources-aws_s3", feature = "sources-aws_sqs"))] -use vector_lib::internal_event::{error_stage, error_type}; -use vector_lib::{NamedInternalEvent, internal_event::InternalEvent}; +use vector_lib::{ + NamedInternalEvent, + internal_event::{CounterName, HistogramName, InternalEvent, error_stage, error_type}, +}; #[cfg(feature = "sources-aws_s3")] mod s3 { @@ -15,7 +17,7 @@ mod s3 { BatchResultErrorEntry, DeleteMessageBatchRequestEntry, DeleteMessageBatchResultEntry, SendMessageBatchRequestEntry, SendMessageBatchResultEntry, }; - use metrics::histogram; + use vector_lib::histogram; use super::*; use crate::sources::aws_s3::sqs::ProcessingError; @@ -34,7 +36,7 @@ mod s3 { duration_ms = %self.duration.as_millis(), ); histogram!( - "s3_object_processing_succeeded_duration_seconds", + HistogramName::S3ObjectProcessingSucceededDurationSeconds, "bucket" => self.bucket.to_owned(), ) .record(self.duration); @@ -55,7 +57,7 @@ mod s3 { duration_ms = %self.duration.as_millis(), ); histogram!( - "s3_object_processing_failed_duration_seconds", + HistogramName::S3ObjectProcessingFailedDurationSeconds, "bucket" => self.bucket.to_owned(), ) .record(self.duration); @@ -79,7 +81,7 @@ mod s3 { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_processing_sqs_message", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -100,7 +102,8 @@ mod s3 { .map(|x| x.id.as_str()) .collect::>() .join(", ")); - counter!("sqs_message_delete_succeeded_total").increment(self.message_ids.len() as u64); + counter!(CounterName::SqsMessageDeleteSucceededTotal) + .increment(self.message_ids.len() as u64); } } @@ -122,7 +125,7 @@ mod s3 { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_deleting_some_sqs_messages", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::PROCESSING, @@ -151,7 +154,7 @@ mod s3 { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_deleting_all_sqs_messages", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::PROCESSING, @@ -172,7 +175,8 @@ mod s3 { .map(|x| x.id.as_str()) .collect::>() .join(", ")); - counter!("sqs_message_defer_succeeded_total").increment(self.message_ids.len() as u64); + counter!(CounterName::SqsMessageDeferSucceededTotal) + .increment(self.message_ids.len() as u64); } } @@ -194,7 +198,7 @@ mod s3 { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_deferring_some_sqs_messages", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::PROCESSING, @@ -223,7 +227,7 @@ mod s3 { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_deferring_all_sqs_messages", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::PROCESSING, @@ -248,7 +252,7 @@ impl InternalEvent for SqsMessageReceiveError<'_, E> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_fetching_sqs_events", "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, @@ -265,8 +269,8 @@ pub struct SqsMessageReceiveSucceeded { impl InternalEvent for SqsMessageReceiveSucceeded { fn emit(self) { trace!(message = "Received SQS messages.", count = %self.count); - counter!("sqs_message_receive_succeeded_total").increment(1); - counter!("sqs_message_received_messages_total").increment(self.count as u64); + counter!(CounterName::SqsMessageReceiveSucceededTotal).increment(1); + counter!(CounterName::SqsMessageReceivedMessagesTotal).increment(self.count as u64); } } @@ -278,7 +282,7 @@ pub struct SqsMessageProcessingSucceeded<'a> { impl InternalEvent for SqsMessageProcessingSucceeded<'_> { fn emit(self) { trace!(message = "Processed SQS message successfully.", message_id = %self.message_id); - counter!("sqs_message_processing_succeeded_total").increment(1); + counter!(CounterName::SqsMessageProcessingSucceededTotal).increment(1); } } @@ -300,7 +304,7 @@ impl InternalEvent for SqsMessageDeleteError<'_, E> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::PROCESSING, ) @@ -322,7 +326,7 @@ impl InternalEvent for SqsS3EventRecordInvalidEventIgnored<'_> { fn emit(self) { warn!(message = "Ignored S3 record in SQS message for an event that was not ObjectCreated.", bucket = %self.bucket, key = %self.key, kind = %self.kind, name = %self.name); - counter!("sqs_s3_event_record_ignored_total", "ignore_type" => "invalid_event_kind") + counter!(CounterName::SqsS3EventRecordIgnoredTotal, "ignore_type" => "invalid_event_kind") .increment(1); } } diff --git a/src/internal_events/batch.rs b/src/internal_events/batch.rs index 8b7a4decfa770..bd553c1e9863d 100644 --- a/src/internal_events/batch.rs +++ b/src/internal_events/batch.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct LargeEventDroppedError { @@ -21,7 +20,7 @@ impl InternalEvent for LargeEventDroppedError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "oversized", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::SENDING, diff --git a/src/internal_events/common.rs b/src/internal_events/common.rs index 69877e3db9ef5..5a6f9c50ede93 100644 --- a/src/internal_events/common.rs +++ b/src/internal_events/common.rs @@ -1,11 +1,12 @@ use std::time::Instant; -use metrics::{counter, histogram}; use vector_lib::NamedInternalEvent; pub use vector_lib::internal_event::EventsReceived; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, HistogramName, InternalEvent, UNINTENTIONAL, error_stage, + error_type, }; +use vector_lib::{counter, histogram}; #[derive(Debug, NamedInternalEvent)] pub struct EndpointBytesReceived<'a> { @@ -23,7 +24,7 @@ impl InternalEvent for EndpointBytesReceived<'_> { endpoint = %self.endpoint, ); counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => self.protocol.to_owned(), "endpoint" => self.endpoint.to_owned(), ) @@ -47,7 +48,7 @@ impl InternalEvent for EndpointBytesSent<'_> { endpoint = %self.endpoint ); counter!( - "component_sent_bytes_total", + CounterName::ComponentSentBytesTotal, "protocol" => self.protocol.to_string(), "endpoint" => self.endpoint.to_string() ) @@ -70,7 +71,7 @@ impl InternalEvent for SocketOutgoingConnectionError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_connecting", "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::SENDING, @@ -95,7 +96,7 @@ impl InternalEvent for StreamClosedError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => STREAM_CLOSED, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, @@ -117,8 +118,8 @@ pub struct CollectionCompleted { impl InternalEvent for CollectionCompleted { fn emit(self) { debug!(message = "Collection completed."); - counter!("collect_completed_total").increment(1); - histogram!("collect_duration_seconds").record(self.end - self.start); + counter!(CounterName::CollectCompletedTotal).increment(1); + histogram!(HistogramName::CollectDurationSeconds).record(self.end - self.start); } } @@ -139,7 +140,7 @@ impl InternalEvent for SinkRequestBuildError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/conditions.rs b/src/internal_events/conditions.rs index 96f7ae0ae0d50..e89f63b6a9c54 100644 --- a/src/internal_events/conditions.rs +++ b/src/internal_events/conditions.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, Copy, Clone, NamedInternalEvent)] pub struct VrlConditionExecutionError<'a> { @@ -16,7 +17,7 @@ impl InternalEvent for VrlConditionExecutionError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::SCRIPT_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/datadog_agent.rs b/src/internal_events/datadog_agent.rs index 9ee5296407b24..84a4a8535c0c7 100644 --- a/src/internal_events/datadog_agent.rs +++ b/src/internal_events/datadog_agent.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct DatadogAgentJsonParseError<'a> { @@ -16,7 +17,7 @@ impl InternalEvent for DatadogAgentJsonParseError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/datadog_metrics.rs b/src/internal_events/datadog_metrics.rs index 5daa3ab87fa79..00e7d50a8a7d7 100644 --- a/src/internal_events/datadog_metrics.rs +++ b/src/internal_events/datadog_metrics.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct DatadogMetricsEncodingError<'a> { @@ -21,7 +20,7 @@ impl InternalEvent for DatadogMetricsEncodingError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => self.error_code, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/datadog_traces.rs b/src/internal_events/datadog_traces.rs index 06b48552fb840..016002681f81b 100644 --- a/src/internal_events/datadog_traces.rs +++ b/src/internal_events/datadog_traces.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct DatadogTracesEncodingError { @@ -22,7 +21,7 @@ impl InternalEvent for DatadogTracesEncodingError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, ) @@ -51,7 +50,7 @@ impl InternalEvent for DatadogTracesAPMStatsError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, ) diff --git a/src/internal_events/dedupe.rs b/src/internal_events/dedupe.rs index eb7511578cdd7..a1c36a3c4fa2b 100644 --- a/src/internal_events/dedupe.rs +++ b/src/internal_events/dedupe.rs @@ -1,5 +1,7 @@ -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent}; +use vector_lib::{ + NamedInternalEvent, + internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub struct DedupeEventsDropped { diff --git a/src/internal_events/demo_logs.rs b/src/internal_events/demo_logs.rs index 406a9856fe6e9..3958f41421ca7 100644 --- a/src/internal_events/demo_logs.rs +++ b/src/internal_events/demo_logs.rs @@ -1,5 +1,4 @@ -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{NamedInternalEvent, internal_event::InternalEvent}; #[derive(Debug, NamedInternalEvent)] pub struct DemoLogsEventProcessed; diff --git a/src/internal_events/dnstap.rs b/src/internal_events/dnstap.rs index 2fc20b95848d1..1ef67ee3001e0 100644 --- a/src/internal_events/dnstap.rs +++ b/src/internal_events/dnstap.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub(crate) struct DnstapParseError { @@ -16,7 +17,7 @@ impl InternalEvent for DnstapParseError { error_type = error_type::PARSER_FAILED, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::PARSER_FAILED, ) diff --git a/src/internal_events/docker_logs.rs b/src/internal_events/docker_logs.rs index bb44e112e05b8..fe24d41b6350b 100644 --- a/src/internal_events/docker_logs.rs +++ b/src/internal_events/docker_logs.rs @@ -1,9 +1,8 @@ use bollard::errors::Error; use chrono::ParseError; -use metrics::counter; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -23,11 +22,11 @@ impl InternalEvent for DockerLogsEventsReceived<'_> { container_id = %self.container_id ); counter!( - "component_received_events_total", "container_name" => self.container_name.to_owned() + CounterName::ComponentReceivedEventsTotal, "container_name" => self.container_name.to_owned() ) .increment(1); counter!( - "component_received_event_bytes_total", "container_name" => self.container_name.to_owned() + CounterName::ComponentReceivedEventBytesTotal, "container_name" => self.container_name.to_owned() ).increment(self.byte_size.get() as u64); } } @@ -45,7 +44,7 @@ impl InternalEvent for DockerLogsContainerEventReceived<'_> { container_id = %self.container_id, action = %self.action, ); - counter!("container_processed_events_total").increment(1); + counter!(CounterName::ContainerProcessedEventsTotal).increment(1); } } @@ -60,7 +59,7 @@ impl InternalEvent for DockerLogsContainerWatch<'_> { message = "Started watching for container logs.", container_id = %self.container_id, ); - counter!("containers_watched_total").increment(1); + counter!(CounterName::ContainersWatchedTotal).increment(1); } } @@ -75,7 +74,7 @@ impl InternalEvent for DockerLogsContainerUnwatch<'_> { message = "Stopped watching for container logs.", container_id = %self.container_id, ); - counter!("containers_unwatched_total").increment(1); + counter!(CounterName::ContainersUnwatchedTotal).increment(1); } } @@ -95,7 +94,7 @@ impl InternalEvent for DockerLogsCommunicationError<'_> { container_id = ?self.container_id ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::RECEIVING, ) @@ -119,7 +118,7 @@ impl InternalEvent for DockerLogsContainerMetadataFetchError<'_> { container_id = ?self.container_id ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, "container_id" => self.container_id.to_owned(), @@ -144,7 +143,7 @@ impl InternalEvent for DockerLogsTimestampParseError<'_> { container_id = ?self.container_id ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, "container_id" => self.container_id.to_owned(), @@ -169,7 +168,7 @@ impl InternalEvent for DockerLogsLoggingDriverUnsupportedError<'_> { container_id = ?self.container_id, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONFIGURATION_FAILED, "stage" => error_stage::RECEIVING, "container_id" => self.container_id.to_owned(), diff --git a/src/internal_events/doris.rs b/src/internal_events/doris.rs index 0a2430869b7c5..15dffd26418b4 100644 --- a/src/internal_events/doris.rs +++ b/src/internal_events/doris.rs @@ -1,5 +1,7 @@ -use metrics::counter; -use vector_lib::{NamedInternalEvent, internal_event::InternalEvent}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent}, +}; /// Emitted when rows are successfully loaded into Doris. #[derive(Debug, NamedInternalEvent)] @@ -17,10 +19,10 @@ impl InternalEvent for DorisRowsLoaded { ); // Record the number of rows loaded - counter!("doris_rows_loaded_total").increment(self.loaded_rows as u64); + counter!(CounterName::DorisRowsLoadedTotal).increment(self.loaded_rows as u64); // Record the number of bytes loaded - counter!("doris_bytes_loaded_total").increment(self.load_bytes as u64); + counter!(CounterName::DorisBytesLoadedTotal).increment(self.load_bytes as u64); } } @@ -37,6 +39,6 @@ impl InternalEvent for DorisRowsFiltered { filtered_rows = %self.filtered_rows ); - counter!("doris_rows_filtered_total").increment(self.filtered_rows as u64); + counter!(CounterName::DorisRowsFilteredTotal).increment(self.filtered_rows as u64); } } diff --git a/src/internal_events/encoding_transcode.rs b/src/internal_events/encoding_transcode.rs index 76ad81792a63a..ec6280f1c703d 100644 --- a/src/internal_events/encoding_transcode.rs +++ b/src/internal_events/encoding_transcode.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub struct DecoderBomRemoval { @@ -13,7 +14,7 @@ impl InternalEvent for DecoderBomRemoval { message = "Removing initial BOM bytes from the final output while decoding to utf8.", from_encoding = %self.from_encoding ); - counter!("decoder_bom_removals_total").increment(1); + counter!(CounterName::DecoderBomRemovalsTotal).increment(1); } } @@ -30,7 +31,7 @@ impl InternalEvent for DecoderMalformedReplacement { ); // NOT the actual number of replacements in the output: there's no easy // way to get that from the lib we use here (encoding_rs) - counter!("decoder_malformed_replacement_warnings_total").increment(1); + counter!(CounterName::DecoderMalformedReplacementWarningsTotal).increment(1); } } @@ -47,6 +48,6 @@ impl InternalEvent for EncoderUnmappableReplacement { ); // NOT the actual number of replacements in the output: there's no easy // way to get that from the lib we use here (encoding_rs) - counter!("encoder_unmappable_replacement_warnings_total").increment(1); + counter!(CounterName::EncoderUnmappableReplacementWarningsTotal).increment(1); } } diff --git a/src/internal_events/eventstoredb_metrics.rs b/src/internal_events/eventstoredb_metrics.rs index c72b9c7dbeb7c..c7db7fad354a5 100644 --- a/src/internal_events/eventstoredb_metrics.rs +++ b/src/internal_events/eventstoredb_metrics.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct EventStoreDbMetricsHttpError { @@ -16,7 +17,7 @@ impl InternalEvent for EventStoreDbMetricsHttpError { error_type = error_type::REQUEST_FAILED, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::RECEIVING, "error_type" => error_type::REQUEST_FAILED, ) @@ -38,7 +39,7 @@ impl InternalEvent for EventStoreDbStatsParsingError { error_type = error_type::PARSER_FAILED, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::PARSER_FAILED, ) diff --git a/src/internal_events/exec.rs b/src/internal_events/exec.rs index abe226897d5d3..21edc68f9df2a 100644 --- a/src/internal_events/exec.rs +++ b/src/internal_events/exec.rs @@ -1,11 +1,11 @@ use std::time::Duration; -use metrics::{counter, histogram}; use tokio::time::error::Elapsed; use vector_lib::{ - NamedInternalEvent, + NamedInternalEvent, counter, histogram, internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, HistogramName, InternalEvent, UNINTENTIONAL, + error_stage, error_type, }, json_size::JsonSize, }; @@ -28,12 +28,12 @@ impl InternalEvent for ExecEventsReceived<'_> { command = %self.command, ); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "command" => self.command.to_owned(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "command" => self.command.to_owned(), ) .increment(self.byte_size.get() as u64); @@ -57,7 +57,7 @@ impl InternalEvent for ExecFailedError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "command" => self.command.to_owned(), "error_type" => error_type::COMMAND_FAILED, "error_code" => io_error_code(&self.error), @@ -85,7 +85,7 @@ impl InternalEvent for ExecTimeoutError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "command" => self.command.to_owned(), "error_type" => error_type::TIMED_OUT, "stage" => error_stage::RECEIVING, @@ -120,14 +120,14 @@ impl InternalEvent for ExecCommandExecuted<'_> { elapsed_millis = %self.exec_duration.as_millis(), ); counter!( - "command_executed_total", + CounterName::CommandExecutedTotal, "command" => self.command.to_owned(), "exit_status" => exit_status.clone(), ) .increment(1); histogram!( - "command_execution_duration_seconds", + HistogramName::CommandExecutionDurationSeconds, "exit_status" => exit_status, "command" => self.command.to_owned(), ) @@ -196,7 +196,7 @@ impl InternalEvent for ExecFailedToSignalChildError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "command" => format!("{:?}", self.command.as_std()), "error_code" => self.error.to_error_code(), "error_type" => error_type::COMMAND_FAILED, @@ -218,7 +218,7 @@ impl InternalEvent for ExecChannelClosedError { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::COMMAND_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/expansion.rs b/src/internal_events/expansion.rs index 7b2633dd64f97..7f5b48914c69c 100644 --- a/src/internal_events/expansion.rs +++ b/src/internal_events/expansion.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(NamedInternalEvent)] pub struct PairExpansionError<'a> { @@ -25,7 +24,7 @@ impl InternalEvent for PairExpansionError<'_> { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/file.rs b/src/internal_events/file.rs index 0e85c67150621..f1299ae751694 100644 --- a/src/internal_events/file.rs +++ b/src/internal_events/file.rs @@ -2,12 +2,13 @@ use std::borrow::Cow; -use metrics::{counter, gauge}; use vector_lib::{ NamedInternalEvent, configurable::configurable_component, + counter, gauge, internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, GaugeName, InternalEvent, UNINTENTIONAL, error_stage, + error_type, }, }; @@ -34,7 +35,7 @@ pub struct FileOpen { impl InternalEvent for FileOpen { fn emit(self) { - gauge!("open_files").set(self.count as f64); + gauge!(GaugeName::OpenFiles).set(self.count as f64); } } @@ -55,13 +56,13 @@ impl InternalEvent for FileBytesSent<'_> { ); if self.include_file_metric_tag { counter!( - "component_sent_bytes_total", + CounterName::ComponentSentBytesTotal, "protocol" => "file", "file" => self.file.clone().into_owned(), ) } else { counter!( - "component_sent_bytes_total", + CounterName::ComponentSentBytesTotal, "protocol" => "file", ) } @@ -89,7 +90,7 @@ impl InternalEvent for FileIoError<'_, P> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => self.code, "error_type" => error_type::IO_FAILED, "stage" => error_stage::SENDING, @@ -110,11 +111,12 @@ mod source { use std::{io::Error, path::Path, time::Duration}; use bytes::BytesMut; - use metrics::counter; use vector_lib::{ - NamedInternalEvent, emit, + NamedInternalEvent, counter, emit, file_source_common::internal_events::FileSourceInternalEvents, - internal_event::{ComponentEventsDropped, INTENTIONAL, error_stage, error_type}, + internal_event::{ + ComponentEventsDropped, CounterName, INTENTIONAL, error_stage, error_type, + }, json_size::JsonSize, }; @@ -137,13 +139,13 @@ mod source { ); if self.include_file_metric_tag { counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => "file", "file" => self.file.to_owned() ) } else { counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => "file", ) } @@ -169,18 +171,18 @@ mod source { ); if self.include_file_metric_tag { counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "file" => self.file.to_owned(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "file" => self.file.to_owned(), ) .increment(self.byte_size.get() as u64); } else { - counter!("component_received_events_total").increment(self.count as u64); - counter!("component_received_event_bytes_total") + counter!(CounterName::ComponentReceivedEventsTotal).increment(self.count as u64); + counter!(CounterName::ComponentReceivedEventBytesTotal) .increment(self.byte_size.get() as u64); } } @@ -200,11 +202,11 @@ mod source { ); if self.include_file_metric_tag { counter!( - "checksum_errors_total", + CounterName::ChecksumErrorsTotal, "file" => self.file.to_string_lossy().into_owned(), ) } else { - counter!("checksum_errors_total") + counter!(CounterName::ChecksumErrorsTotal) } .increment(1); } @@ -229,7 +231,7 @@ mod source { ); if self.include_file_metric_tag { counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reading_fingerprint", "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, @@ -237,7 +239,7 @@ mod source { ) } else { counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reading_fingerprint", "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, @@ -268,7 +270,7 @@ mod source { ); if self.include_file_metric_tag { counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "file" => self.file.to_string_lossy().into_owned(), "error_code" => DELETION_FAILED, "error_type" => error_type::COMMAND_FAILED, @@ -276,7 +278,7 @@ mod source { ) } else { counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => DELETION_FAILED, "error_type" => error_type::COMMAND_FAILED, "stage" => error_stage::RECEIVING, @@ -300,11 +302,11 @@ mod source { ); if self.include_file_metric_tag { counter!( - "files_deleted_total", + CounterName::FilesDeletedTotal, "file" => self.file.to_string_lossy().into_owned(), ) } else { - counter!("files_deleted_total") + counter!(CounterName::FilesDeletedTotal) } .increment(1); } @@ -327,13 +329,13 @@ mod source { ); if self.include_file_metric_tag { counter!( - "files_unwatched_total", + CounterName::FilesUnwatchedTotal, "file" => self.file.to_string_lossy().into_owned(), "reached_eof" => reached_eof, ) } else { counter!( - "files_unwatched_total", + CounterName::FilesUnwatchedTotal, "reached_eof" => reached_eof, ) } @@ -360,7 +362,7 @@ mod source { ); if self.include_file_metric_tag { counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "watching", "error_type" => error_type::COMMAND_FAILED, "stage" => error_stage::RECEIVING, @@ -368,7 +370,7 @@ mod source { ) } else { counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "watching", "error_type" => error_type::COMMAND_FAILED, "stage" => error_stage::RECEIVING, @@ -394,11 +396,11 @@ mod source { ); if self.include_file_metric_tag { counter!( - "files_resumed_total", + CounterName::FilesResumedTotal, "file" => self.file.to_string_lossy().into_owned(), ) } else { - counter!("files_resumed_total") + counter!(CounterName::FilesResumedTotal) } .increment(1); } @@ -418,11 +420,11 @@ mod source { ); if self.include_file_metric_tag { counter!( - "files_added_total", + CounterName::FilesAddedTotal, "file" => self.file.to_string_lossy().into_owned(), ) } else { - counter!("files_added_total") + counter!(CounterName::FilesAddedTotal) } .increment(1); } @@ -441,7 +443,7 @@ mod source { count = %self.count, duration_ms = self.duration.as_millis() as u64, ); - counter!("checkpoints_total").increment(self.count as u64); + counter!(CounterName::CheckpointsTotal).increment(self.count as u64); } } @@ -460,7 +462,7 @@ mod source { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "writing_checkpoints", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::RECEIVING, @@ -486,7 +488,7 @@ mod source { path = %self.path.display(), ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "globbing", "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, @@ -513,7 +515,7 @@ mod source { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reading_line_from_file", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/file_descriptor.rs b/src/internal_events/file_descriptor.rs index 7882ed4d95b12..8db4e7895729e 100644 --- a/src/internal_events/file_descriptor.rs +++ b/src/internal_events/file_descriptor.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct FileDescriptorReadError { @@ -19,7 +20,7 @@ where stage = error_stage::RECEIVING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/fluent.rs b/src/internal_events/fluent.rs index 6d6bb408edc5f..f47b927d5cbe2 100644 --- a/src/internal_events/fluent.rs +++ b/src/internal_events/fluent.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; use crate::sources::fluent::DecodeError; @@ -31,7 +32,7 @@ impl InternalEvent for FluentMessageDecodeError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/gcp_pubsub.rs b/src/internal_events/gcp_pubsub.rs index 4066d71936529..752546cfa7d09 100644 --- a/src/internal_events/gcp_pubsub.rs +++ b/src/internal_events/gcp_pubsub.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(NamedInternalEvent)] pub struct GcpPubsubConnectError { @@ -18,7 +19,7 @@ impl InternalEvent for GcpPubsubConnectError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_connecting", "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::RECEIVING, @@ -43,7 +44,7 @@ impl InternalEvent for GcpPubsubStreamingPullError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_streaming_pull", "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, @@ -68,7 +69,7 @@ impl InternalEvent for GcpPubsubReceiveError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_fetching_events", "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/grpc.rs b/src/internal_events/grpc.rs index 882b1dbfaf33b..66da41e10b797 100644 --- a/src/internal_events/grpc.rs +++ b/src/internal_events/grpc.rs @@ -1,10 +1,11 @@ use std::time::Duration; use http::response::Response; -use metrics::{counter, histogram}; use tonic::Code; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, histogram, + internal_event::{CounterName, HistogramName, InternalEvent, error_stage, error_type}, +}; const GRPC_STATUS_LABEL: &str = "grpc_status"; @@ -13,7 +14,7 @@ pub struct GrpcServerRequestReceived; impl InternalEvent for GrpcServerRequestReceived { fn emit(self) { - counter!("grpc_server_messages_received_total").increment(1); + counter!(CounterName::GrpcServerMessagesReceivedTotal).increment(1); } } @@ -34,8 +35,8 @@ impl InternalEvent for GrpcServerResponseSent<'_, B> { let grpc_code = grpc_code_to_name(grpc_code); let labels = &[(GRPC_STATUS_LABEL, grpc_code)]; - counter!("grpc_server_messages_sent_total", labels).increment(1); - histogram!("grpc_server_handler_duration_seconds", labels).record(self.latency); + counter!(CounterName::GrpcServerMessagesSentTotal, labels).increment(1); + histogram!(HistogramName::GrpcServerHandlerDurationSeconds, labels).record(self.latency); } } @@ -53,7 +54,7 @@ impl InternalEvent for GrpcInvalidCompressionSchemeError<'_> { stage = error_stage::RECEIVING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, ) @@ -78,7 +79,7 @@ where stage = error_stage::RECEIVING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/heartbeat.rs b/src/internal_events/heartbeat.rs index 658a24fcb8762..16191669e7317 100644 --- a/src/internal_events/heartbeat.rs +++ b/src/internal_events/heartbeat.rs @@ -1,8 +1,9 @@ use std::time::Instant; -use metrics::gauge; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, gauge, + internal_event::{GaugeName, InternalEvent}, +}; use crate::built_info; @@ -14,9 +15,9 @@ pub struct Heartbeat { impl InternalEvent for Heartbeat { fn emit(self) { trace!(target: "vector", message = "Beep."); - gauge!("uptime_seconds").set(self.since.elapsed().as_secs() as f64); + gauge!(GaugeName::UptimeSeconds).set(self.since.elapsed().as_secs() as f64); gauge!( - "build_info", + GaugeName::BuildInfo, "debug" => built_info::DEBUG, "version" => built_info::PKG_VERSION, "rust_version" => built_info::RUST_VERSION, diff --git a/src/internal_events/host_metrics.rs b/src/internal_events/host_metrics.rs index d60771644571e..7662ca5e808a4 100644 --- a/src/internal_events/host_metrics.rs +++ b/src/internal_events/host_metrics.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct HostMetricsScrapeError { @@ -16,7 +17,7 @@ impl InternalEvent for HostMetricsScrapeError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, ) @@ -40,7 +41,7 @@ impl InternalEvent for HostMetricsScrapeDetailError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, ) @@ -66,7 +67,7 @@ impl InternalEvent for HostMetricsScrapeFilesystemError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/http.rs b/src/internal_events/http.rs index a0d8f5d2a92d3..4aad267d7683b 100644 --- a/src/internal_events/http.rs +++ b/src/internal_events/http.rs @@ -1,10 +1,9 @@ use std::{error::Error, time::Duration}; use http::Response; -use metrics::{counter, histogram}; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, histogram, + internal_event::{CounterName, HistogramName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -16,7 +15,7 @@ pub struct HttpServerRequestReceived; impl InternalEvent for HttpServerRequestReceived { fn emit(self) { debug!(message = "Received HTTP request."); - counter!("http_server_requests_received_total").increment(1); + counter!(CounterName::HttpServerRequestsReceivedTotal).increment(1); } } @@ -32,8 +31,8 @@ impl InternalEvent for HttpServerResponseSent<'_, B> { HTTP_STATUS_LABEL, self.response.status().as_u16().to_string(), )]; - counter!("http_server_responses_sent_total", labels).increment(1); - histogram!("http_server_handler_duration_seconds", labels).record(self.latency); + counter!(CounterName::HttpServerResponsesSentTotal, labels).increment(1); + histogram!(HistogramName::HttpServerHandlerDurationSeconds, labels).record(self.latency); } } @@ -53,7 +52,7 @@ impl InternalEvent for HttpBytesReceived<'_> { protocol = %self.protocol ); counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "http_path" => self.http_path.to_string(), "protocol" => self.protocol, ) @@ -79,15 +78,15 @@ impl InternalEvent for HttpEventsReceived<'_> { protocol = %self.protocol, ); - histogram!("component_received_events_count").record(self.count as f64); + histogram!(HistogramName::ComponentReceivedEventsCount).record(self.count as f64); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "http_path" => self.http_path.to_string(), "protocol" => self.protocol, ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "http_path" => self.http_path.to_string(), "protocol" => self.protocol, ) @@ -126,7 +125,7 @@ impl InternalEvent for HttpBadRequest<'_> { http_code = %self.code, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => self.error_code, "error_type" => error_type::REQUEST_FAILED, "error_stage" => error_stage::RECEIVING, @@ -152,7 +151,7 @@ impl InternalEvent for HttpDecompressError<'_> { encoding = %self.encoding ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_decompressing_payload", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::RECEIVING, @@ -174,7 +173,7 @@ impl InternalEvent for HttpInternalError<'_> { stage = error_stage::RECEIVING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/http_client.rs b/src/internal_events/http_client.rs index d1e4c7549d15a..346192dfca141 100644 --- a/src/internal_events/http_client.rs +++ b/src/internal_events/http_client.rs @@ -5,9 +5,10 @@ use http::{ header::{self, HeaderMap, HeaderValue}, }; use hyper::{Error, body::HttpBody}; -use metrics::{counter, histogram}; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, histogram, + internal_event::{CounterName, HistogramName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct AboutToSendHttpRequest<'a, T> { @@ -39,7 +40,7 @@ impl InternalEvent for AboutToSendHttpRequest<'_, T> { headers = ?remove_sensitive(self.request.headers()), body = %FormatBody(self.request.body()), ); - counter!("http_client_requests_sent_total", "method" => self.request.method().to_string()) + counter!(CounterName::HttpClientRequestsSentTotal, "method" => self.request.method().to_string()) .increment(1); } } @@ -60,13 +61,13 @@ impl InternalEvent for GotHttpResponse<'_, T> { body = %FormatBody(self.response.body()), ); counter!( - "http_client_responses_total", + CounterName::HttpClientResponsesTotal, "status" => self.response.status().as_u16().to_string(), ) .increment(1); - histogram!("http_client_rtt_seconds").record(self.roundtrip); + histogram!(HistogramName::HttpClientRttSeconds).record(self.roundtrip); histogram!( - "http_client_response_rtt_seconds", + HistogramName::HttpClientResponseRttSeconds, "status" => self.response.status().as_u16().to_string(), ) .record(self.roundtrip); @@ -87,9 +88,10 @@ impl InternalEvent for GotHttpWarning<'_> { error_type = error_type::REQUEST_FAILED, stage = error_stage::PROCESSING, ); - counter!("http_client_errors_total", "error_kind" => self.error.to_string()).increment(1); - histogram!("http_client_rtt_seconds").record(self.roundtrip); - histogram!("http_client_error_rtt_seconds", "error_kind" => self.error.to_string()) + counter!(CounterName::HttpClientErrorsTotal, "error_kind" => self.error.to_string()) + .increment(1); + histogram!(HistogramName::HttpClientRttSeconds).record(self.roundtrip); + histogram!(HistogramName::HttpClientErrorRttSeconds, "error_kind" => self.error.to_string()) .record(self.roundtrip); } } diff --git a/src/internal_events/http_client_source.rs b/src/internal_events/http_client_source.rs index ff67535c0c14b..0ba52d722dfee 100644 --- a/src/internal_events/http_client_source.rs +++ b/src/internal_events/http_client_source.rs @@ -1,9 +1,8 @@ #![allow(dead_code)] // TODO requires optional feature compilation -use metrics::counter; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -25,12 +24,12 @@ impl InternalEvent for HttpClientEventsReceived { url = %self.url, ); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "uri" => self.url.clone(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "uri" => self.url.clone(), ) .increment(self.byte_size.get() as u64); @@ -53,7 +52,7 @@ impl InternalEvent for HttpClientHttpResponseError { error_code = %http_error_code(self.code.as_u16()), ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "url" => self.url, "stage" => error_stage::RECEIVING, "error_type" => error_type::REQUEST_FAILED, @@ -79,7 +78,7 @@ impl InternalEvent for HttpClientHttpError { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "url" => self.url, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/influxdb.rs b/src/internal_events/influxdb.rs index 22b34c3dc532c..a142642140f6f 100644 --- a/src/internal_events/influxdb.rs +++ b/src/internal_events/influxdb.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct InfluxdbEncodingError { @@ -20,7 +19,7 @@ impl InternalEvent for InfluxdbEncodingError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/internal_logs.rs b/src/internal_events/internal_logs.rs index 63c520723c9c7..2f0674d380edd 100644 --- a/src/internal_events/internal_logs.rs +++ b/src/internal_events/internal_logs.rs @@ -1,5 +1,8 @@ -use metrics::counter; -use vector_lib::{NamedInternalEvent, internal_event::InternalEvent, json_size::JsonSize}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent}, + json_size::JsonSize, +}; #[derive(Debug, NamedInternalEvent)] pub struct InternalLogsBytesReceived { @@ -10,7 +13,7 @@ impl InternalEvent for InternalLogsBytesReceived { fn emit(self) { // MUST NOT emit logs here to avoid an infinite log loop counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => "internal", ) .increment(self.byte_size as u64); @@ -26,7 +29,8 @@ pub struct InternalLogsEventsReceived { impl InternalEvent for InternalLogsEventsReceived { fn emit(self) { // MUST NOT emit logs here to avoid an infinite log loop - counter!("component_received_events_total").increment(self.count as u64); - counter!("component_received_event_bytes_total").increment(self.byte_size.get() as u64); + counter!(CounterName::ComponentReceivedEventsTotal).increment(self.count as u64); + counter!(CounterName::ComponentReceivedEventBytesTotal) + .increment(self.byte_size.get() as u64); } } diff --git a/src/internal_events/journald.rs b/src/internal_events/journald.rs index 0debba0de5d29..02f6300cb6905 100644 --- a/src/internal_events/journald.rs +++ b/src/internal_events/journald.rs @@ -1,8 +1,8 @@ -use metrics::counter; use vector_lib::{ NamedInternalEvent, codecs::decoding::BoxedFramingError, - internal_event::{InternalEvent, error_stage, error_type}, + counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, }; #[derive(Debug, NamedInternalEvent)] @@ -21,7 +21,7 @@ impl InternalEvent for JournaldInvalidRecordError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::PARSER_FAILED, ) @@ -43,7 +43,7 @@ impl InternalEvent for JournaldStartJournalctlError { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::RECEIVING, "error_type" => error_type::COMMAND_FAILED, ) @@ -65,7 +65,7 @@ impl InternalEvent for JournaldReadError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::READER_FAILED, ) @@ -89,7 +89,7 @@ impl InternalEvent for JournaldCheckpointSetError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::PROCESSING, "error_type" => error_type::IO_FAILED, ) @@ -113,7 +113,7 @@ impl InternalEvent for JournaldCheckpointFileOpenError { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "stage" => error_stage::RECEIVING, "error_type" => error_type::IO_FAILED, ) diff --git a/src/internal_events/kafka.rs b/src/internal_events/kafka.rs index 87ad581e1c453..1cbd2ba3ce8cb 100644 --- a/src/internal_events/kafka.rs +++ b/src/internal_events/kafka.rs @@ -1,9 +1,8 @@ #![allow(dead_code)] // TODO requires optional feature compilation -use metrics::{counter, gauge}; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, gauge, + internal_event::{CounterName, GaugeName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; use vrl::path::OwnedTargetPath; @@ -26,7 +25,7 @@ impl InternalEvent for KafkaBytesReceived<'_> { partition = %self.partition, ); counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => self.protocol, "topic" => self.topic.to_string(), "partition" => self.partition.to_string(), @@ -53,13 +52,13 @@ impl InternalEvent for KafkaEventsReceived<'_> { partition = %self.partition, ); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "topic" => self.topic.to_string(), "partition" => self.partition.to_string(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "topic" => self.topic.to_string(), "partition" => self.partition.to_string(), ) @@ -82,7 +81,7 @@ impl InternalEvent for KafkaOffsetUpdateError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "kafka_offset_update", "error_type" => error_type::READER_FAILED, "stage" => error_stage::SENDING, @@ -106,7 +105,7 @@ impl InternalEvent for KafkaReadError { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reading_message", "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, @@ -123,24 +122,24 @@ pub struct KafkaStatisticsReceived<'a> { impl InternalEvent for KafkaStatisticsReceived<'_> { fn emit(self) { - gauge!("kafka_queue_messages").set(self.statistics.msg_cnt as f64); - gauge!("kafka_queue_messages_bytes").set(self.statistics.msg_size as f64); - counter!("kafka_requests_total").absolute(self.statistics.tx as u64); - counter!("kafka_requests_bytes_total").absolute(self.statistics.tx_bytes as u64); - counter!("kafka_responses_total").absolute(self.statistics.rx as u64); - counter!("kafka_responses_bytes_total").absolute(self.statistics.rx_bytes as u64); - counter!("kafka_produced_messages_total").absolute(self.statistics.txmsgs as u64); - counter!("kafka_produced_messages_bytes_total") + gauge!(GaugeName::KafkaQueueMessages).set(self.statistics.msg_cnt as f64); + gauge!(GaugeName::KafkaQueueMessagesBytes).set(self.statistics.msg_size as f64); + counter!(CounterName::KafkaRequestsTotal).absolute(self.statistics.tx as u64); + counter!(CounterName::KafkaRequestsBytesTotal).absolute(self.statistics.tx_bytes as u64); + counter!(CounterName::KafkaResponsesTotal).absolute(self.statistics.rx as u64); + counter!(CounterName::KafkaResponsesBytesTotal).absolute(self.statistics.rx_bytes as u64); + counter!(CounterName::KafkaProducedMessagesTotal).absolute(self.statistics.txmsgs as u64); + counter!(CounterName::KafkaProducedMessagesBytesTotal) .absolute(self.statistics.txmsg_bytes as u64); - counter!("kafka_consumed_messages_total").absolute(self.statistics.rxmsgs as u64); - counter!("kafka_consumed_messages_bytes_total") + counter!(CounterName::KafkaConsumedMessagesTotal).absolute(self.statistics.rxmsgs as u64); + counter!(CounterName::KafkaConsumedMessagesBytesTotal) .absolute(self.statistics.rxmsg_bytes as u64); if self.expose_lag_metrics { for (topic_id, topic) in &self.statistics.topics { for (partition_id, partition) in &topic.partitions { gauge!( - "kafka_consumer_lag", + GaugeName::KafkaConsumerLag, "topic_id" => topic_id.clone(), "partition_id" => partition_id.to_string(), ) @@ -166,7 +165,7 @@ impl InternalEvent for KafkaHeaderExtractionError<'_> { header_field = self.header_field.to_string(), ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "extracting_header", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/kubernetes_logs.rs b/src/internal_events/kubernetes_logs.rs index c6edb03724169..15b4ca4e61ee0 100644 --- a/src/internal_events/kubernetes_logs.rs +++ b/src/internal_events/kubernetes_logs.rs @@ -1,8 +1,8 @@ -use metrics::counter; use vector_lib::{ - NamedInternalEvent, + NamedInternalEvent, counter, internal_event::{ - ComponentEventsDropped, INTENTIONAL, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, INTENTIONAL, InternalEvent, UNINTENTIONAL, + error_stage, error_type, }, json_size::JsonSize, }; @@ -37,21 +37,21 @@ impl InternalEvent for KubernetesLogsEventsReceived<'_> { let pod_namespace = pod_info.namespace; counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "pod_name" => pod_name.clone(), "pod_namespace" => pod_namespace.clone(), ) .increment(1); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "pod_name" => pod_name, "pod_namespace" => pod_namespace, ) .increment(self.byte_size.get() as u64); } None => { - counter!("component_received_events_total").increment(1); - counter!("component_received_event_bytes_total") + counter!(CounterName::ComponentReceivedEventsTotal).increment(1); + counter!(CounterName::ComponentReceivedEventBytesTotal) .increment(self.byte_size.get() as u64); } } @@ -75,7 +75,7 @@ impl InternalEvent for KubernetesLogsEventAnnotationError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => ANNOTATION_FAILED, "error_type" => error_type::READER_FAILED, "stage" => error_stage::PROCESSING, @@ -99,13 +99,13 @@ impl InternalEvent for KubernetesLogsEventNamespaceAnnotationError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => ANNOTATION_FAILED, "error_type" => error_type::READER_FAILED, "stage" => error_stage::PROCESSING, ) .increment(1); - counter!("k8s_event_namespace_annotation_failures_total").increment(1); + counter!(CounterName::K8sEventNamespaceAnnotationFailuresTotal).increment(1); } } @@ -124,13 +124,13 @@ impl InternalEvent for KubernetesLogsEventNodeAnnotationError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => ANNOTATION_FAILED, "error_type" => error_type::READER_FAILED, "stage" => error_stage::PROCESSING, ) .increment(1); - counter!("k8s_event_node_annotation_failures_total").increment(1); + counter!(CounterName::K8sEventNodeAnnotationFailuresTotal).increment(1); } } @@ -145,7 +145,7 @@ impl InternalEvent for KubernetesLogsFormatPickerEdgeCase { message = "Encountered format picker edge case.", what = %self.what, ); - counter!("k8s_format_picker_edge_cases_total").increment(1); + counter!(CounterName::K8sFormatPickerEdgeCasesTotal).increment(1); } } @@ -163,12 +163,12 @@ impl InternalEvent for KubernetesLogsDockerFormatParseError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) .increment(1); - counter!("k8s_docker_format_parse_failures_total").increment(1); + counter!(CounterName::K8sDockerFormatParseFailuresTotal).increment(1); } } @@ -191,7 +191,7 @@ impl InternalEvent for KubernetesLifecycleError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => KUBERNETES_LIFECYCLE, "error_type" => error_type::READER_FAILED, "stage" => error_stage::PROCESSING, @@ -222,7 +222,7 @@ impl InternalEvent for KubernetesMergedLineTooBigError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reading_line_from_kubernetes_log", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/log_to_metric.rs b/src/internal_events/log_to_metric.rs index 9fbb64dba0622..e8e3da5b898b7 100644 --- a/src/internal_events/log_to_metric.rs +++ b/src/internal_events/log_to_metric.rs @@ -1,9 +1,10 @@ use std::num::ParseFloatError; -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, + }, }; #[derive(NamedInternalEvent)] @@ -22,7 +23,7 @@ impl InternalEvent for LogToMetricFieldNullError<'_> { null_field = %self.field ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "field_null", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, @@ -52,7 +53,7 @@ impl InternalEvent for LogToMetricParseFloatError<'_> { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "failed_parsing_float", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -83,7 +84,7 @@ impl InternalEvent for MetricMetadataInvalidFieldValueError<'_> { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "invalid_field_value", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -112,7 +113,7 @@ impl InternalEvent for MetricMetadataParseError<'_> { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => format!("failed_parsing_{}", self.kind), "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -137,7 +138,7 @@ impl InternalEvent for MetricMetadataMetricDetailsNotFoundError { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "missing_metric_details", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/logplex.rs b/src/internal_events/logplex.rs index b28588c5c2d1e..4a45df6349b65 100644 --- a/src/internal_events/logplex.rs +++ b/src/internal_events/logplex.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; use super::prelude::io_error_code; @@ -37,7 +38,7 @@ impl InternalEvent for HerokuLogplexRequestReadError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::READER_FAILED, "error_code" => io_error_code(&self.error), "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/loki.rs b/src/internal_events/loki.rs index 523efd7e4f59b..3a5935e1a372a 100644 --- a/src/internal_events/loki.rs +++ b/src/internal_events/loki.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, INTENTIONAL, InternalEvent, error_stage, error_type, + ComponentEventsDropped, CounterName, INTENTIONAL, InternalEvent, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct LokiEventUnlabeledError; @@ -17,7 +16,7 @@ impl InternalEvent for LokiEventUnlabeledError { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "unlabeled_event", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, @@ -48,7 +47,7 @@ impl InternalEvent for LokiOutOfOrderEventDroppedError { }); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "out_of_order", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, @@ -69,7 +68,7 @@ impl InternalEvent for LokiOutOfOrderEventRewritten { count = self.count, reason = "out_of_order", ); - counter!("rewritten_timestamp_events_total").increment(self.count as u64); + counter!(CounterName::RewrittenTimestampEventsTotal).increment(self.count as u64); } } @@ -90,7 +89,7 @@ impl InternalEvent for LokiTimestampNonParsableEventsDropped { emit!(ComponentEventsDropped:: { count: 1, reason }); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "non-parsable_timestamp", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/lua.rs b/src/internal_events/lua.rs index feb9d04212b88..3a8779d9cd4b1 100644 --- a/src/internal_events/lua.rs +++ b/src/internal_events/lua.rs @@ -1,8 +1,9 @@ -use metrics::{counter, gauge}; use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, GaugeName, InternalEvent, UNINTENTIONAL, error_stage, + error_type, }; +use vector_lib::{counter, gauge}; use crate::transforms::lua::v2::BuildError; @@ -13,7 +14,7 @@ pub struct LuaGcTriggered { impl InternalEvent for LuaGcTriggered { fn emit(self) { - gauge!("lua_memory_used_bytes").set(self.used_memory as f64); + gauge!(GaugeName::LuaMemoryUsedBytes).set(self.used_memory as f64); } } @@ -32,7 +33,7 @@ impl InternalEvent for LuaScriptError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => mlua_error_code(&self.error), "error_type" => error_type::SCRIPT_FAILED, "stage" => error_stage::PROCESSING, @@ -62,7 +63,7 @@ impl InternalEvent for LuaBuildError { internal_log_rate_limit = false, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => lua_build_error_code(&self.error), "error_type" => error_type::SCRIPT_FAILED, "stage" => error_stage:: PROCESSING, diff --git a/src/internal_events/metric_to_log.rs b/src/internal_events/metric_to_log.rs index a536a1b24df24..a11ed286be17a 100644 --- a/src/internal_events/metric_to_log.rs +++ b/src/internal_events/metric_to_log.rs @@ -1,9 +1,8 @@ -use metrics::counter; use serde_json::Error; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct MetricToLogSerializeError { @@ -20,7 +19,7 @@ impl InternalEvent for MetricToLogSerializeError { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/mongodb_metrics.rs b/src/internal_events/mongodb_metrics.rs index 3cad1e4ef97f9..b0023085f025f 100644 --- a/src/internal_events/mongodb_metrics.rs +++ b/src/internal_events/mongodb_metrics.rs @@ -1,8 +1,7 @@ -use metrics::counter; use mongodb::{bson, error::Error as MongoError}; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -23,12 +22,12 @@ impl InternalEvent for MongoDbMetricsEventsReceived<'_> { endpoint = self.endpoint, ); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "endpoint" => self.endpoint.to_owned(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "endpoint" => self.endpoint.to_owned(), ) .increment(self.byte_size.get() as u64); @@ -51,7 +50,7 @@ impl InternalEvent for MongoDbMetricsRequestError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, ) @@ -75,7 +74,7 @@ impl InternalEvent for MongoDbMetricsBsonParseError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::RECEIVING, "endpoint" => self.endpoint.to_owned(), diff --git a/src/internal_events/mqtt.rs b/src/internal_events/mqtt.rs index 1e406a9494f1f..8d416c4c748ee 100644 --- a/src/internal_events/mqtt.rs +++ b/src/internal_events/mqtt.rs @@ -1,9 +1,10 @@ use std::fmt::Debug; -use metrics::counter; use rumqttc::ConnectionError; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct MqttConnectionError { @@ -20,7 +21,7 @@ impl InternalEvent for MqttConnectionError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "mqtt_connection_error", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, diff --git a/src/internal_events/nginx_metrics.rs b/src/internal_events/nginx_metrics.rs index a3384d4ef0faf..82cd7ea3878b7 100644 --- a/src/internal_events/nginx_metrics.rs +++ b/src/internal_events/nginx_metrics.rs @@ -1,7 +1,6 @@ -use metrics::counter; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, json_size::JsonSize, }; @@ -23,12 +22,12 @@ impl InternalEvent for NginxMetricsEventsReceived<'_> { endpoint = self.endpoint, ); counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "endpoint" => self.endpoint.to_owned(), ) .increment(self.count as u64); counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "endpoint" => self.endpoint.to_owned(), ) .increment(self.byte_size.get() as u64); @@ -51,7 +50,7 @@ impl InternalEvent for NginxMetricsRequestError<'_> { stage = error_stage::RECEIVING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "endpoint" => self.endpoint.to_owned(), "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, @@ -76,7 +75,7 @@ impl InternalEvent for NginxMetricsStubStatusParseError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "endpoint" => self.endpoint.to_owned(), "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/open.rs b/src/internal_events/open.rs index e48e0ac337820..58e9c9d40b3f8 100644 --- a/src/internal_events/open.rs +++ b/src/internal_events/open.rs @@ -6,9 +6,10 @@ use std::{ }, }; -use metrics::gauge; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, gauge, + internal_event::{GaugeName, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub struct ConnectionOpen { @@ -17,7 +18,7 @@ pub struct ConnectionOpen { impl InternalEvent for ConnectionOpen { fn emit(self) { - gauge!("open_connections").set(self.count as f64); + gauge!(GaugeName::OpenConnections).set(self.count as f64); } } @@ -28,7 +29,7 @@ pub struct EndpointsActive { impl InternalEvent for EndpointsActive { fn emit(self) { - gauge!("active_endpoints").set(self.count as f64); + gauge!(GaugeName::ActiveEndpoints).set(self.count as f64); } } diff --git a/src/internal_events/parser.rs b/src/internal_events/parser.rs index 85a3e1383afa3..2610ae5458958 100644 --- a/src/internal_events/parser.rs +++ b/src/internal_events/parser.rs @@ -2,10 +2,11 @@ use std::borrow::Cow; -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, + }, }; fn truncate_string_at(s: &str, maxlen: usize) -> Cow<'_, str> { @@ -36,7 +37,7 @@ impl InternalEvent for ParserMatchError<'_> { field = &truncate_string_at(&String::from_utf8_lossy(self.value), 60)[..] ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "no_match_found", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, @@ -66,7 +67,7 @@ impl InternalEvent for ParserMissingFieldError<'_, DROP_ stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "field_not_found", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, @@ -97,7 +98,7 @@ impl InternalEvent for ParserConversionError<'_> { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "type_conversion", "error_type" => error_type::CONVERSION_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/postgresql_metrics.rs b/src/internal_events/postgresql_metrics.rs index d6a58f968ab7f..62fa4d18a722d 100644 --- a/src/internal_events/postgresql_metrics.rs +++ b/src/internal_events/postgresql_metrics.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct PostgresqlMetricsCollectError<'a> { @@ -18,7 +19,7 @@ impl InternalEvent for PostgresqlMetricsCollectError<'_> { endpoint = %self.endpoint, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/process.rs b/src/internal_events/process.rs index 987724c2da18d..19701c6feaca8 100644 --- a/src/internal_events/process.rs +++ b/src/internal_events/process.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; use crate::{built_info, config}; @@ -17,7 +18,7 @@ impl InternalEvent for VectorStarted { arch = built_info::TARGET_ARCH, revision = built_info::VECTOR_BUILD_DESC.unwrap_or(""), ); - counter!("started_total").increment(1); + counter!(CounterName::StartedTotal).increment(1); } } @@ -34,7 +35,7 @@ impl InternalEvent for VectorReloaded<'_> { path = ?self.config_paths, internal_log_rate_limit = false, ); - counter!("reloaded_total").increment(1); + counter!(CounterName::ReloadedTotal).increment(1); } } @@ -59,7 +60,7 @@ impl InternalEvent for VectorStopped { target: "vector", message = "Vector has stopped.", ); - counter!("stopped_total").increment(1); + counter!(CounterName::StoppedTotal).increment(1); } } @@ -72,7 +73,7 @@ impl InternalEvent for VectorQuit { target: "vector", message = "Vector has quit.", ); - counter!("quit_total").increment(1); + counter!(CounterName::QuitTotal).increment(1); } } @@ -92,7 +93,7 @@ impl InternalEvent for VectorReloadError { internal_log_rate_limit = false, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reload", "error_type" => error_type::CONFIGURATION_FAILED, "stage" => error_stage::PROCESSING, @@ -115,7 +116,7 @@ impl InternalEvent for VectorConfigLoadError { internal_log_rate_limit = false, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "config_load", "error_type" => error_type::CONFIGURATION_FAILED, "stage" => error_stage::PROCESSING, @@ -137,7 +138,7 @@ impl InternalEvent for VectorRecoveryError { internal_log_rate_limit = false, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "recovery", "error_type" => error_type::CONFIGURATION_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/prometheus.rs b/src/internal_events/prometheus.rs index 27b28fb5ffafa..3ddd3c555f728 100644 --- a/src/internal_events/prometheus.rs +++ b/src/internal_events/prometheus.rs @@ -3,13 +3,14 @@ #[cfg(feature = "sources-prometheus-scrape")] use std::borrow::Cow; -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, -}; #[cfg(feature = "sources-prometheus-scrape")] use vector_lib::prometheus::parser::ParserError; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, + }, +}; #[cfg(feature = "sources-prometheus-scrape")] #[derive(Debug, NamedInternalEvent)] @@ -34,7 +35,7 @@ impl InternalEvent for PrometheusParseError<'_> { url = %self.url ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, "url" => self.url.to_string(), @@ -57,7 +58,7 @@ impl InternalEvent for PrometheusRemoteWriteParseError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) @@ -77,7 +78,7 @@ impl InternalEvent for PrometheusNormalizationError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONVERSION_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/pulsar.rs b/src/internal_events/pulsar.rs index a2212ef0d5971..0e2e11b061f3e 100644 --- a/src/internal_events/pulsar.rs +++ b/src/internal_events/pulsar.rs @@ -2,11 +2,10 @@ #[cfg(feature = "sources-pulsar")] use metrics::Counter; -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct PulsarSendingError { @@ -24,7 +23,7 @@ impl InternalEvent for PulsarSendingError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::SENDING, ) @@ -51,7 +50,7 @@ impl InternalEvent for PulsarPropertyExtractionError { property_field = %self.property_field, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "extracting_property", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -77,21 +76,21 @@ pub struct PulsarErrorEventData { registered_event!( PulsarErrorEvent => { ack_errors: Counter = counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "acknowledge_message", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::RECEIVING, ), nack_errors: Counter = counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "negative_acknowledge_message", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::RECEIVING, ), read_errors: Counter = counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "reading_message", "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/redis.rs b/src/internal_events/redis.rs index 45d76f3670dcd..87b9bc6d7b2f8 100644 --- a/src/internal_events/redis.rs +++ b/src/internal_events/redis.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct RedisReceiveEventError { @@ -25,7 +26,7 @@ impl InternalEvent for RedisReceiveEventError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => self.error_code, "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, diff --git a/src/internal_events/reduce.rs b/src/internal_events/reduce.rs index 8917c5aad0a5a..0962c6332a439 100644 --- a/src/internal_events/reduce.rs +++ b/src/internal_events/reduce.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; use vrl::{path::PathParseError, value::KeyString}; #[derive(Debug, NamedInternalEvent)] @@ -8,7 +9,7 @@ pub struct ReduceStaleEventFlushed; impl InternalEvent for ReduceStaleEventFlushed { fn emit(self) { - counter!("stale_events_flushed_total").increment(1); + counter!(CounterName::StaleEventsFlushedTotal).increment(1); } } @@ -28,7 +29,7 @@ impl InternalEvent for ReduceAddEventError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/remap.rs b/src/internal_events/remap.rs index 989a6aa064065..d0e6500d69341 100644 --- a/src/internal_events/remap.rs +++ b/src/internal_events/remap.rs @@ -1,8 +1,8 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, INTENTIONAL, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, INTENTIONAL, InternalEvent, UNINTENTIONAL, error_stage, + error_type, }; +use vector_lib::{NamedInternalEvent, counter}; #[derive(Debug, NamedInternalEvent)] pub struct RemapMappingError { @@ -21,7 +21,7 @@ impl InternalEvent for RemapMappingError { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONVERSION_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/sample.rs b/src/internal_events/sample.rs index 3722f9530b668..825175dc42555 100644 --- a/src/internal_events/sample.rs +++ b/src/internal_events/sample.rs @@ -1,5 +1,7 @@ -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent}; +use vector_lib::{ + NamedInternalEvent, + internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub struct SampleEventDiscarded; diff --git a/src/internal_events/sematext_metrics.rs b/src/internal_events/sematext_metrics.rs index 65d23c53e00ef..cb03742a5d3d1 100644 --- a/src/internal_events/sematext_metrics.rs +++ b/src/internal_events/sematext_metrics.rs @@ -1,7 +1,8 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, + }, }; use crate::event::metric::Metric; @@ -23,7 +24,7 @@ impl InternalEvent for SematextMetricsInvalidMetricError<'_> { kind = ?self.metric.kind(), ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "invalid_metric", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, @@ -49,7 +50,7 @@ impl InternalEvent for SematextMetricsEncodeEventError stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/socket.rs b/src/internal_events/socket.rs index f0b58ce33bbd7..d38788f46767c 100644 --- a/src/internal_events/socket.rs +++ b/src/internal_events/socket.rs @@ -1,10 +1,10 @@ use std::net::Ipv4Addr; -use metrics::{counter, histogram}; use vector_lib::{ - NamedInternalEvent, + NamedInternalEvent, counter, histogram, internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, HistogramName, InternalEvent, UNINTENTIONAL, + error_stage, error_type, }, json_size::JsonSize, }; @@ -42,11 +42,11 @@ impl InternalEvent for SocketBytesReceived { %protocol, ); counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "protocol" => protocol, ) .increment(self.byte_size as u64); - histogram!("component_received_bytes").record(self.byte_size as f64); + histogram!(HistogramName::ComponentReceivedBytes).record(self.byte_size as f64); } } @@ -66,10 +66,12 @@ impl InternalEvent for SocketEventsReceived { byte_size = self.byte_size.get(), %mode, ); - counter!("component_received_events_total", "mode" => mode).increment(self.count as u64); - counter!("component_received_event_bytes_total", "mode" => mode) + counter!(CounterName::ComponentReceivedEventsTotal, "mode" => mode) + .increment(self.count as u64); + counter!(CounterName::ComponentReceivedEventBytesTotal, "mode" => mode) .increment(self.byte_size.get() as u64); - histogram!("component_received_bytes", "mode" => mode).record(self.byte_size.get() as f64); + histogram!(HistogramName::ComponentReceivedBytes, "mode" => mode) + .record(self.byte_size.get() as f64); } } @@ -88,7 +90,7 @@ impl InternalEvent for SocketBytesSent { %protocol, ); counter!( - "component_sent_bytes_total", + CounterName::ComponentSentBytesTotal, "protocol" => protocol, ) .increment(self.byte_size as u64); @@ -105,8 +107,9 @@ pub struct SocketEventsSent { impl InternalEvent for SocketEventsSent { fn emit(self) { trace!(message = "Events sent.", count = %self.count, byte_size = %self.byte_size.get()); - counter!("component_sent_events_total", "mode" => self.mode.as_str()).increment(self.count); - counter!("component_sent_event_bytes_total", "mode" => self.mode.as_str()) + counter!(CounterName::ComponentSentEventsTotal, "mode" => self.mode.as_str()) + .increment(self.count); + counter!(CounterName::ComponentSentEventBytesTotal, "mode" => self.mode.as_str()) .increment(self.byte_size.get() as u64); } } @@ -129,7 +132,7 @@ impl InternalEvent for SocketBindError { %mode, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "socket_bind", "error_type" => error_type::IO_FAILED, "stage" => error_stage::INITIALIZING, @@ -164,7 +167,7 @@ impl InternalEvent for SocketMulticastGroupJoinError { %interface, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "socket_multicast_group_join", "error_type" => error_type::IO_FAILED, "stage" => error_stage::INITIALIZING, @@ -194,7 +197,7 @@ impl InternalEvent for SocketReceiveError { %mode, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "socket_receive", "error_type" => error_type::READER_FAILED, "stage" => error_stage::RECEIVING, @@ -223,7 +226,7 @@ impl InternalEvent for SocketSendError { %mode, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "socket_send", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, diff --git a/src/internal_events/splunk_hec.rs b/src/internal_events/splunk_hec.rs index 6dcd63084d8e6..bd3fde83c2318 100644 --- a/src/internal_events/splunk_hec.rs +++ b/src/internal_events/splunk_hec.rs @@ -7,11 +7,13 @@ pub use self::source::*; #[cfg(feature = "sinks-splunk_hec")] mod sink { - use metrics::{counter, gauge}; use serde_json::Error; - use vector_lib::NamedInternalEvent; - use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + use vector_lib::{ + NamedInternalEvent, counter, gauge, + internal_event::{ + ComponentEventsDropped, CounterName, GaugeName, InternalEvent, UNINTENTIONAL, + error_stage, error_type, + }, }; use crate::{ @@ -35,7 +37,7 @@ mod sink { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "serializing_json", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, @@ -63,13 +65,13 @@ mod sink { kind = ?self.kind, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::INVALID_METRIC, "stage" => error_stage::PROCESSING, ) .increment(1); counter!( - "component_discarded_events_total", + CounterName::ComponentDiscardedEventsTotal, "error_type" => error_type::INVALID_METRIC, "stage" => error_stage::PROCESSING, ) @@ -92,7 +94,7 @@ mod sink { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "invalid_response", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::SENDING, @@ -117,7 +119,7 @@ mod sink { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "indexer_ack_failed", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::SENDING, @@ -141,7 +143,7 @@ mod sink { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "indexer_ack_unavailable", "error_type" => error_type::ACKNOWLEDGMENT_FAILED, "stage" => error_stage::SENDING, @@ -155,7 +157,7 @@ mod sink { impl InternalEvent for SplunkIndexerAcknowledgementAckAdded { fn emit(self) { - gauge!("splunk_pending_acks").increment(1.0); + gauge!(GaugeName::SplunkPendingAcks).increment(1.0); } } @@ -166,7 +168,7 @@ mod sink { impl InternalEvent for SplunkIndexerAcknowledgementAcksRemoved { fn emit(self) { - gauge!("splunk_pending_acks").decrement(self.count); + gauge!(GaugeName::SplunkPendingAcks).decrement(self.count); } } @@ -197,9 +199,10 @@ mod sink { #[cfg(feature = "sources-splunk_hec")] mod source { - use metrics::counter; - use vector_lib::NamedInternalEvent; - use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; + use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, + }; use crate::sources::splunk_hec::ApiError; @@ -218,7 +221,7 @@ mod source { stage = error_stage::PROCESSING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "invalid_request_body", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -243,7 +246,7 @@ mod source { stage = error_stage::RECEIVING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::AUTHENTICATION_FAILED, "stage" => error_stage::RECEIVING, ) @@ -257,7 +260,7 @@ mod source { stage = error_stage::RECEIVING ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, ) diff --git a/src/internal_events/statsd_sink.rs b/src/internal_events/statsd_sink.rs index 7f0ee81f48ddc..858084124b562 100644 --- a/src/internal_events/statsd_sink.rs +++ b/src/internal_events/statsd_sink.rs @@ -1,8 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; use crate::event::metric::{MetricKind, MetricValue}; @@ -24,7 +23,7 @@ impl InternalEvent for StatsdInvalidMetricError<'_> { kind = ?self.kind, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "invalid_metric", "error_type" => error_type::ENCODER_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/tag_cardinality_limit.rs b/src/internal_events/tag_cardinality_limit.rs index 83a82acd342ae..9906f5c320f6b 100644 --- a/src/internal_events/tag_cardinality_limit.rs +++ b/src/internal_events/tag_cardinality_limit.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ComponentEventsDropped, CounterName, INTENTIONAL, InternalEvent}, +}; #[derive(NamedInternalEvent)] pub struct TagCardinalityLimitRejectingEvent<'a> { @@ -20,13 +21,13 @@ impl InternalEvent for TagCardinalityLimitRejectingEvent<'_> { ); if self.include_extended_tags { counter!( - "tag_value_limit_exceeded_total", + CounterName::TagValueLimitExceededTotal, "metric_name" => self.metric_name.to_string(), "tag_key" => self.tag_key.to_string(), ) .increment(1); } else { - counter!("tag_value_limit_exceeded_total").increment(1); + counter!(CounterName::TagValueLimitExceededTotal).increment(1); } emit!(ComponentEventsDropped:: { @@ -54,13 +55,13 @@ impl InternalEvent for TagCardinalityLimitRejectingTag<'_> { ); if self.include_extended_tags { counter!( - "tag_value_limit_exceeded_total", + CounterName::TagValueLimitExceededTotal, "metric_name" => self.metric_name.to_string(), "tag_key" => self.tag_key.to_string(), ) .increment(1); } else { - counter!("tag_value_limit_exceeded_total").increment(1); + counter!(CounterName::TagValueLimitExceededTotal).increment(1); } } } @@ -76,6 +77,6 @@ impl InternalEvent for TagCardinalityValueLimitReached<'_> { message = "Value_limit reached for key. New values for this key will be rejected.", key = %self.key, ); - counter!("value_limit_reached_total").increment(1); + counter!(CounterName::ValueLimitReachedTotal).increment(1); } } diff --git a/src/internal_events/tcp.rs b/src/internal_events/tcp.rs index a121eef1e0327..1ec0cfb6322e5 100644 --- a/src/internal_events/tcp.rs +++ b/src/internal_events/tcp.rs @@ -1,8 +1,9 @@ use std::net::SocketAddr; -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; use crate::{internal_events::SocketOutgoingConnectionError, tls::TlsError}; @@ -18,7 +19,7 @@ impl InternalEvent for TcpSocketConnectionEstablished { } else { debug!(message = "Connected.", peer_addr = "unknown"); } - counter!("connection_established_total", "mode" => "tcp").increment(1); + counter!(CounterName::ConnectionEstablishedTotal, "mode" => "tcp").increment(1); } } @@ -41,7 +42,7 @@ pub struct TcpSocketConnectionShutdown; impl InternalEvent for TcpSocketConnectionShutdown { fn emit(self) { warn!(message = "Received EOF from the server, shutdown."); - counter!("connection_shutdown_total", "mode" => "tcp").increment(1); + counter!(CounterName::ConnectionShutdownTotal, "mode" => "tcp").increment(1); } } @@ -63,7 +64,7 @@ impl InternalEvent for TcpSocketError<'_, E> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::PROCESSING, ) @@ -100,7 +101,7 @@ impl InternalEvent for TcpSocketTlsConnectionError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "connection_failed", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, @@ -127,7 +128,7 @@ impl InternalEvent for TcpSendAckError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "ack_failed", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, @@ -152,7 +153,7 @@ impl InternalEvent for TcpBytesReceived { peer_addr = %self.peer_addr, ); counter!( - "component_received_bytes_total", "protocol" => "tcp" + CounterName::ComponentReceivedBytesTotal, "protocol" => "tcp" ) .increment(self.byte_size as u64); } diff --git a/src/internal_events/template.rs b/src/internal_events/template.rs index 147418042a0c6..db43081e2a22a 100644 --- a/src/internal_events/template.rs +++ b/src/internal_events/template.rs @@ -1,7 +1,8 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, + }, }; #[derive(NamedInternalEvent)] @@ -29,7 +30,7 @@ impl InternalEvent for TemplateRenderingError<'_> { ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::TEMPLATE_FAILED, "stage" => error_stage::PROCESSING, ) diff --git a/src/internal_events/throttle.rs b/src/internal_events/throttle.rs index 274fedd7741b9..3757bbae40535 100644 --- a/src/internal_events/throttle.rs +++ b/src/internal_events/throttle.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ComponentEventsDropped, INTENTIONAL, InternalEvent}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ComponentEventsDropped, CounterName, INTENTIONAL, InternalEvent}, +}; #[derive(Debug, NamedInternalEvent)] pub(crate) struct ThrottleEventDiscarded { @@ -23,7 +24,7 @@ impl InternalEvent for ThrottleEventDiscarded { // if we should change the specification wording? Sort of a similar situation to the // `error_code` tag for the component errors metric, where it's meant to be optional and // only specified when relevant. - counter!("events_discarded_total", "key" => self.key).increment(1); // Deprecated. + counter!(CounterName::EventsDiscardedTotal, "key" => self.key).increment(1); // Deprecated. } emit!(ComponentEventsDropped:: { diff --git a/src/internal_events/udp.rs b/src/internal_events/udp.rs index 0602d4fdb3329..31e5f5c6533a4 100644 --- a/src/internal_events/udp.rs +++ b/src/internal_events/udp.rs @@ -1,7 +1,8 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{ + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, + }, }; use crate::internal_events::SocketOutgoingConnectionError; @@ -14,7 +15,7 @@ pub struct UdpSocketConnectionEstablished; impl InternalEvent for UdpSocketConnectionEstablished { fn emit(self) { debug!(message = "Connected."); - counter!("connection_established_total", "mode" => "udp").increment(1); + counter!(CounterName::ConnectionEstablishedTotal, "mode" => "udp").increment(1); } } @@ -51,13 +52,13 @@ impl InternalEvent for UdpSendIncompleteError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, ) .increment(1); // deprecated - counter!("connection_send_errors_total", "mode" => "udp").increment(1); + counter!(CounterName::ConnectionSendErrorsTotal, "mode" => "udp").increment(1); emit!(ComponentEventsDropped:: { count: 1, reason }); } @@ -80,7 +81,7 @@ impl InternalEvent for UdpChunkingError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, ) diff --git a/src/internal_events/unix.rs b/src/internal_events/unix.rs index 6fab3348dc4d7..fc98ff7feacbd 100644 --- a/src/internal_events/unix.rs +++ b/src/internal_events/unix.rs @@ -2,11 +2,10 @@ use std::{io::Error, path::Path}; -use metrics::counter; -use vector_lib::NamedInternalEvent; use vector_lib::internal_event::{ - ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type, + ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type, }; +use vector_lib::{NamedInternalEvent, counter}; use crate::internal_events::SocketOutgoingConnectionError; @@ -18,7 +17,7 @@ pub struct UnixSocketConnectionEstablished<'a> { impl InternalEvent for UnixSocketConnectionEstablished<'_> { fn emit(self) { debug!(message = "Connected.", path = ?self.path); - counter!("connection_established_total", "mode" => "unix").increment(1); + counter!(CounterName::ConnectionEstablishedTotal, "mode" => "unix").increment(1); } } @@ -59,7 +58,7 @@ impl InternalEvent for UnixSocketError<'_, E> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::CONNECTION_FAILED, "stage" => error_stage::PROCESSING, ) @@ -84,7 +83,7 @@ impl InternalEvent for UnixSocketSendError<'_, E> { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, ) @@ -112,7 +111,7 @@ impl InternalEvent for UnixSendIncompleteError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, ) @@ -139,7 +138,7 @@ impl InternalEvent for UnixSocketFileDeleteError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "delete_socket_file", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/websocket.rs b/src/internal_events/websocket.rs index 960aec1916133..b842407ee0313 100644 --- a/src/internal_events/websocket.rs +++ b/src/internal_events/websocket.rs @@ -5,14 +5,15 @@ use std::{ fmt::{Debug, Display, Formatter, Result}, }; -use metrics::{counter, histogram}; use tokio_tungstenite::tungstenite::error::Error as TungsteniteError; use vector_common::{ internal_event::{error_stage, error_type}, json_size::JsonSize, }; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::InternalEvent; +use vector_lib::{ + NamedInternalEvent, counter, histogram, + internal_event::{CounterName, HistogramName, InternalEvent}, +}; pub const PROTOCOL: &str = "websocket"; @@ -22,7 +23,7 @@ pub struct WebSocketConnectionEstablished; impl InternalEvent for WebSocketConnectionEstablished { fn emit(self) { debug!(message = "Connected."); - counter!("connection_established_total").increment(1); + counter!(CounterName::ConnectionEstablishedTotal).increment(1); } } @@ -41,7 +42,7 @@ impl InternalEvent for WebSocketConnectionFailedError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "protocol" => PROTOCOL, "error_code" => "websocket_connection_failed", "error_type" => error_type::CONNECTION_FAILED, @@ -57,7 +58,7 @@ pub struct WebSocketConnectionShutdown; impl InternalEvent for WebSocketConnectionShutdown { fn emit(self) { warn!(message = "Closed by the server."); - counter!("connection_shutdown_total").increment(1); + counter!(CounterName::ConnectionShutdownTotal).increment(1); } } @@ -76,7 +77,7 @@ impl InternalEvent for WebSocketConnectionError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "protocol" => PROTOCOL, "error_code" => "websocket_connection_error", "error_type" => error_type::WRITER_FAILED, @@ -121,7 +122,7 @@ impl InternalEvent for WebSocketBytesReceived<'_> { kind = %self.kind ); let counter = counter!( - "component_received_bytes_total", + CounterName::ComponentReceivedBytesTotal, "url" => self.url.to_string(), "protocol" => self.protocol, "kind" => self.kind.to_string() @@ -150,17 +151,17 @@ impl InternalEvent for WebSocketMessageReceived<'_> { kind = %self.kind ); - let histogram = histogram!("component_received_events_count"); + let histogram = histogram!(HistogramName::ComponentReceivedEventsCount); histogram.record(self.count as f64); let counter = counter!( - "component_received_events_total", + CounterName::ComponentReceivedEventsTotal, "uri" => self.url.to_string(), "protocol" => PROTOCOL, "kind" => self.kind.to_string() ); counter.increment(self.count as u64); let counter = counter!( - "component_received_event_bytes_total", + CounterName::ComponentReceivedEventBytesTotal, "url" => self.url.to_string(), "protocol" => PROTOCOL, "kind" => self.kind.to_string() @@ -184,7 +185,7 @@ impl InternalEvent for WebSocketReceiveError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "protocol" => PROTOCOL, "error_code" => "websocket_receive_error", "error_type" => error_type::CONNECTION_FAILED, @@ -209,7 +210,7 @@ impl InternalEvent for WebSocketSendError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "protocol" => PROTOCOL, "error_code" => "websocket_send_error", "error_type" => error_type::CONNECTION_FAILED, diff --git a/src/internal_events/websocket_server.rs b/src/internal_events/websocket_server.rs index fd064c41f2f8a..bdace6b079da5 100644 --- a/src/internal_events/websocket_server.rs +++ b/src/internal_events/websocket_server.rs @@ -1,8 +1,9 @@ use std::{error::Error, fmt::Debug}; -use metrics::{counter, gauge}; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, gauge, + internal_event::{CounterName, GaugeName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct WebSocketListenerConnectionEstablished { @@ -18,8 +19,8 @@ impl InternalEvent for WebSocketListenerConnectionEstablished { self.client_count ) ); - counter!("connection_established_total", &self.extra_tags).increment(1); - gauge!("active_clients", &self.extra_tags).set(self.client_count as f64); + counter!(CounterName::ConnectionEstablishedTotal, &self.extra_tags).increment(1); + gauge!(GaugeName::ActiveClients, &self.extra_tags).set(self.client_count as f64); } } @@ -49,7 +50,7 @@ impl InternalEvent for WebSocketListenerConnectionFailedError { ]); // Tags required by `component_errors_total` are dynamically added above. // ## skip check-validity-events ## - counter!("component_errors_total", &all_tags).increment(1); + counter!(CounterName::ComponentErrorsTotal, &all_tags).increment(1); } } @@ -67,8 +68,8 @@ impl InternalEvent for WebSocketListenerConnectionShutdown { self.client_count ) ); - counter!("connection_shutdown_total", &self.extra_tags).increment(1); - gauge!("active_clients", &self.extra_tags).set(self.client_count as f64); + counter!(CounterName::ConnectionShutdownTotal, &self.extra_tags).increment(1); + gauge!(GaugeName::ActiveClients, &self.extra_tags).set(self.client_count as f64); } } @@ -87,7 +88,7 @@ impl InternalEvent for WebSocketListenerSendError { stage = error_stage::SENDING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "ws_server_connection_error", "error_type" => error_type::WRITER_FAILED, "stage" => error_stage::SENDING, @@ -104,8 +105,8 @@ pub struct WebSocketListenerMessageSent { impl InternalEvent for WebSocketListenerMessageSent { fn emit(self) { - counter!("websocket_messages_sent_total", &self.extra_tags).increment(1); - counter!("websocket_bytes_sent_total", &self.extra_tags) + counter!(CounterName::WebsocketMessagesSentTotal, &self.extra_tags).increment(1); + counter!(CounterName::WebsocketBytesSentTotal, &self.extra_tags) .increment(self.message_size as u64); } } diff --git a/src/internal_events/windows.rs b/src/internal_events/windows.rs index 7b36e2fa62466..5ea6bae62aa25 100644 --- a/src/internal_events/windows.rs +++ b/src/internal_events/windows.rs @@ -1,6 +1,7 @@ -use metrics::counter; -use vector_lib::NamedInternalEvent; -use vector_lib::internal_event::{InternalEvent, error_stage, error_type}; +use vector_lib::{ + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, +}; #[derive(Debug, NamedInternalEvent)] pub struct WindowsServiceStart<'a> { @@ -16,7 +17,7 @@ impl InternalEvent for WindowsServiceStart<'_> { "Started Windows Service.", ); counter!( - "windows_service_start_total", + CounterName::WindowsServiceStartTotal, "already_started" => self.already_started.to_string(), ) .increment(1); @@ -37,7 +38,7 @@ impl InternalEvent for WindowsServiceStop<'_> { "Stopped Windows Service.", ); counter!( - "windows_service_stop_total", + CounterName::WindowsServiceStopTotal, "already_stopped" => self.already_stopped.to_string(), ) .increment(1); @@ -55,7 +56,7 @@ impl InternalEvent for WindowsServiceRestart<'_> { name = ?self.name, "Restarted Windows Service." ); - counter!("windows_service_restart_total").increment(1) + counter!(CounterName::WindowsServiceRestartTotal).increment(1) } } @@ -70,7 +71,7 @@ impl InternalEvent for WindowsServiceInstall<'_> { name = ?self.name, "Installed Windows Service.", ); - counter!("windows_service_install_total").increment(1); + counter!(CounterName::WindowsServiceInstallTotal).increment(1); } } @@ -85,7 +86,7 @@ impl InternalEvent for WindowsServiceUninstall<'_> { name = ?self.name, "Uninstalled Windows Service.", ); - counter!("windows_service_uninstall_total").increment(1); + counter!(CounterName::WindowsServiceUninstallTotal).increment(1); } } @@ -104,7 +105,7 @@ impl InternalEvent for WindowsServiceDoesNotExistError<'_> { stage = error_stage::PROCESSING, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "service_missing", "error_type" => error_type::CONDITION_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_events/windows_event_log.rs b/src/internal_events/windows_event_log.rs index ae5363e2c52be..7ec356ba253ff 100644 --- a/src/internal_events/windows_event_log.rs +++ b/src/internal_events/windows_event_log.rs @@ -1,8 +1,7 @@ -use metrics::counter; use tracing::error; use vector_lib::{ - NamedInternalEvent, - internal_event::{InternalEvent, error_stage, error_type}, + NamedInternalEvent, counter, + internal_event::{CounterName, InternalEvent, error_stage, error_type}, }; #[derive(Debug, NamedInternalEvent)] @@ -25,7 +24,7 @@ impl InternalEvent for WindowsEventLogParseError { internal_log_rate_limit = true, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "parse_failed", "error_type" => error_type::PARSER_FAILED, "stage" => error_stage::PROCESSING, @@ -54,7 +53,7 @@ impl InternalEvent for WindowsEventLogQueryError { internal_log_rate_limit = true, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "query_failed", "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::RECEIVING, @@ -81,7 +80,7 @@ impl InternalEvent for WindowsEventLogBookmarkError { internal_log_rate_limit = true, ); counter!( - "component_errors_total", + CounterName::ComponentErrorsTotal, "error_code" => "bookmark_failed", "error_type" => error_type::REQUEST_FAILED, "stage" => error_stage::PROCESSING, diff --git a/src/internal_telemetry/allocations/mod.rs b/src/internal_telemetry/allocations/mod.rs index a2680256ec167..15ad82b3665fa 100644 --- a/src/internal_telemetry/allocations/mod.rs +++ b/src/internal_telemetry/allocations/mod.rs @@ -11,8 +11,11 @@ use std::{ }; use arr_macro::arr; -use metrics::{counter, gauge}; use rand_distr::num_traits::ToPrimitive; +use vector_common::{ + counter, gauge, + internal_event::{CounterName, GaugeName}, +}; use self::allocator::Tracer; pub(crate) use self::allocator::{ @@ -144,26 +147,26 @@ pub fn init_allocation_tracing() { let group_info = group.lock().unwrap(); if allocations_diff > 0 { counter!( - "component_allocated_bytes_total", "component_kind" => group_info.component_kind.clone(), + CounterName::ComponentAllocatedBytesTotal, "component_kind" => group_info.component_kind.clone(), "component_type" => group_info.component_type.clone(), "component_id" => group_info.component_id.clone()).increment(allocations_diff); } if deallocations_diff > 0 { counter!( - "component_deallocated_bytes_total", "component_kind" => group_info.component_kind.clone(), + CounterName::ComponentDeallocatedBytesTotal, "component_kind" => group_info.component_kind.clone(), "component_type" => group_info.component_type.clone(), "component_id" => group_info.component_id.clone()).increment(deallocations_diff); } if mem_used_diff > 0 { gauge!( - "component_allocated_bytes", "component_type" => group_info.component_type.clone(), + GaugeName::ComponentAllocatedBytes, "component_type" => group_info.component_type.clone(), "component_id" => group_info.component_id.clone(), "component_kind" => group_info.component_kind.clone()) .increment(mem_used_diff.to_f64().expect("failed to convert mem_used from int to float")); } if mem_used_diff < 0 { gauge!( - "component_allocated_bytes", "component_type" => group_info.component_type.clone(), + GaugeName::ComponentAllocatedBytes, "component_type" => group_info.component_type.clone(), "component_id" => group_info.component_id.clone(), "component_kind" => group_info.component_kind.clone()) .decrement(-mem_used_diff.to_f64().expect("failed to convert mem_used from int to float")); diff --git a/src/sources/internal_metrics.rs b/src/sources/internal_metrics.rs index f576efa2a71a1..76dfab8849997 100644 --- a/src/sources/internal_metrics.rs +++ b/src/sources/internal_metrics.rs @@ -196,8 +196,13 @@ impl InternalMetrics<'_> { mod tests { use std::collections::BTreeMap; - use metrics::{counter, gauge, histogram}; - use vector_lib::{metric_tags, metrics::Controller}; + use strum::IntoEnumIterator; + use vector_lib::{ + counter, gauge, histogram, + internal_event::{CounterName, GaugeName, HistogramName}, + metric_tags, + metrics::Controller, + }; use super::*; use crate::{ @@ -223,14 +228,20 @@ mod tests { // There *seems* to be a race condition here (CI was flaky), so add a slight delay. std::thread::sleep(std::time::Duration::from_millis(300)); - gauge!("foo").set(1.0); - gauge!("foo").set(2.0); - counter!("bar").increment(3); - counter!("bar").increment(4); - histogram!("baz").record(5.0); - histogram!("baz").record(6.0); - histogram!("quux", "host" => "foo").record(8.0); - histogram!("quux", "host" => "foo").record(8.1); + let gauge_name = GaugeName::iter().next().unwrap(); + let counter_name = CounterName::iter().next().unwrap(); + let mut histogram_iter = HistogramName::iter(); + let histogram_name = histogram_iter.next().unwrap(); + let histogram_tagged_name = histogram_iter.next().unwrap(); + + gauge!(gauge_name).set(1.0); + gauge!(gauge_name).set(2.0); + counter!(counter_name).increment(3); + counter!(counter_name).increment(4); + histogram!(histogram_name).record(5.0); + histogram!(histogram_name).record(6.0); + histogram!(histogram_tagged_name, "host" => "foo").record(8.0); + histogram!(histogram_tagged_name, "host" => "foo").record(8.1); let controller = Controller::get().expect("no controller"); @@ -243,10 +254,16 @@ mod tests { .map(|metric| (metric.name().to_string(), metric)) .collect::>(); - assert_eq!(&MetricValue::Gauge { value: 2.0 }, output["foo"].value()); - assert_eq!(&MetricValue::Counter { value: 7.0 }, output["bar"].value()); + assert_eq!( + &MetricValue::Gauge { value: 2.0 }, + output[gauge_name.as_str()].value() + ); + assert_eq!( + &MetricValue::Counter { value: 7.0 }, + output[counter_name.as_str()].value() + ); - match &output["baz"].value() { + match &output[histogram_name.as_str()].value() { MetricValue::AggregatedHistogram { buckets, count, @@ -263,7 +280,7 @@ mod tests { _ => panic!("wrong type"), } - match &output["quux"].value() { + match &output[histogram_tagged_name.as_str()].value() { MetricValue::AggregatedHistogram { buckets, count, @@ -282,7 +299,7 @@ mod tests { } let labels = metric_tags!("host" => "foo"); - assert_eq!(Some(&labels), output["quux"].tags()); + assert_eq!(Some(&labels), output[histogram_tagged_name.as_str()].tags()); } async fn event_from_config(config: InternalMetricsConfig) -> Event { diff --git a/src/topology/builder.rs b/src/topology/builder.rs index 8948109fa7fb7..a25a99d337a26 100644 --- a/src/topology/builder.rs +++ b/src/topology/builder.rs @@ -8,7 +8,6 @@ use std::{ use futures::{FutureExt, StreamExt, TryStreamExt, stream::FuturesOrdered}; use futures_util::stream::FuturesUnordered; -use metrics::gauge; use stream_cancel::{StreamExt as StreamCancelExt, Trigger, Tripwire}; use tokio::{ select, @@ -31,6 +30,7 @@ use vector_lib::{ source_sender::{CHUNK_SIZE, SourceSenderItem}, transform::update_runtime_schema_definition, }; +use vector_lib::{gauge, internal_event::GaugeName}; use vector_vrl_metrics::MetricsStorage; use super::{ @@ -627,7 +627,7 @@ impl<'a> Builder<'a> { let utilization_sender = self .utilization_registry - .add_component(key.clone(), gauge!("utilization")); + .add_component(key.clone(), gauge!(GaugeName::Utilization)); let component_key = key.clone(); let sink = async move { debug!("Sink starting."); @@ -747,7 +747,7 @@ impl<'a> Builder<'a> { let sender = self .utilization_registry - .add_component(node.key.clone(), gauge!("utilization")); + .add_component(node.key.clone(), gauge!(GaugeName::Utilization)); let runner = Runner::new( t, input_rx, @@ -803,7 +803,7 @@ impl<'a> Builder<'a> { let sender = self .utilization_registry - .add_component(key.clone(), gauge!("utilization")); + .add_component(key.clone(), gauge!(GaugeName::Utilization)); let output_sender = sender.clone(); let input_rx = Utilization::new(sender, key.clone(), input_rx.into_stream()); diff --git a/src/utilization.rs b/src/utilization.rs index b3496b998f1c5..21d5f670bf1d9 100644 --- a/src/utilization.rs +++ b/src/utilization.rs @@ -344,6 +344,9 @@ impl OutputUtilization { mod tests { use mock_instant::global::MockClock; use serial_test::serial; + use strum::IntoEnumIterator; + use vector_lib::gauge; + use vector_lib::internal_event::GaugeName; use super::*; @@ -353,7 +356,7 @@ mod tests { MockClock::set_time(Duration::from_secs(100)); Timer::new( - metrics::gauge!("test_utilization"), + gauge!(GaugeName::iter().next().unwrap()), #[cfg(debug_assertions)] "test_component".into(), ) @@ -522,7 +525,7 @@ mod tests { let (mut emitter, registry) = UtilizationEmitter::new(); let key = ComponentKey::from("test_transform"); - let sender = registry.add_component(key.clone(), metrics::gauge!("utilization")); + let sender = registry.add_component(key.clone(), gauge!(GaugeName::Utilization)); let output_sender = sender.clone(); // Upstream channel carrying EventArrays.