Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benches/metrics_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn benchmark(c: &mut Criterion) {
group.finish();
}

#[allow(clippy::disallowed_macros)]
Comment thread
thomasqueirozb marked this conversation as resolved.
Outdated
fn prepare_metrics(cardinality: usize) -> &'static vector::metrics::Controller {
vector::metrics::init_test();
let controller = vector::metrics::Controller::get().unwrap();
Expand Down
6 changes: 6 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 `MetricName` variant instead of a raw string." },
{ path = "metrics::histogram", reason = "Use the `histogram!` macro from `vector_common` with a `MetricName` variant instead of a raw string." },
{ path = "metrics::gauge", reason = "Use the `gauge!` macro from `vector_common` with a `MetricName` 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." },
Expand Down
29 changes: 16 additions & 13 deletions lib/codecs/src/internal_events.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -24,7 +27,7 @@ impl<E: std::fmt::Display> InternalEvent for DecoderFramingError<E> {
stage = error_stage::PROCESSING,
);
counter!(
"component_errors_total",
CounterName::ComponentErrorsTotal,
"error_code" => "decoder_frame",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -137,7 +140,7 @@ impl<E: std::fmt::Display> InternalEvent for EncoderWriteError<'_, E> {
stage = error_stage::SENDING,
);
counter!(
"component_errors_total",
CounterName::ComponentErrorsTotal,
"error_type" => error_type::ENCODER_FAILED,
"stage" => error_stage::SENDING,
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -201,7 +204,7 @@ impl<E: std::fmt::Display> 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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
)
Expand Down
53 changes: 27 additions & 26 deletions lib/vector-buffers/src/internal_events.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -21,29 +22,29 @@ 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(),
)
.set(self.max_size_events as f64);
}
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,
)
Expand All @@ -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()
)
Expand All @@ -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()
)
Expand Down Expand Up @@ -200,41 +201,41 @@ 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,
)
.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()
)
Expand All @@ -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",
)
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/vector-buffers/src/topology/channel/limited_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/vector-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/vector-common/src/internal_event/bytes_received.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand Down
8 changes: 5 additions & 3 deletions lib/vector-common/src/internal_event/bytes_sent.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand Down
Loading
Loading