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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Renamed the memory enrichment table failure and TTL-expiration internal metrics to end in `_total`, matching Vector's counter naming convention:

- `memory_enrichment_table_failed_insertions_total`
- `memory_enrichment_table_failed_reads_total`
- `memory_enrichment_table_ttl_expirations_total`

This replaces the previous non-`_total` metric names.

authors: nanookclaw
45 changes: 45 additions & 0 deletions lib/vector-common/src/internal_event/metric_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ pub enum CounterName {
ComponentAllocatedBytesTotal,
ComponentDeallocatedBytesTotal,
MemoryEnrichmentTableFailedInsertions,
MemoryEnrichmentTableFailedInsertionsTotal,
MemoryEnrichmentTableFailedReads,
MemoryEnrichmentTableFailedReadsTotal,
MemoryEnrichmentTableFlushesTotal,
MemoryEnrichmentTableInsertionsTotal,
MemoryEnrichmentTableReadsTotal,
MemoryEnrichmentTableTtlExpirations,
MemoryEnrichmentTableTtlExpirationsTotal,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, AsRefStr, EnumIter)]
Expand Down Expand Up @@ -357,13 +360,55 @@ impl CounterName {
Self::MemoryEnrichmentTableFailedInsertions => {
"memory_enrichment_table_failed_insertions"
}
Self::MemoryEnrichmentTableFailedInsertionsTotal => {
"memory_enrichment_table_failed_insertions_total"
}
Self::MemoryEnrichmentTableFailedReads => "memory_enrichment_table_failed_reads",
Self::MemoryEnrichmentTableFailedReadsTotal => {
"memory_enrichment_table_failed_reads_total"
}
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",
Self::MemoryEnrichmentTableTtlExpirationsTotal => {
"memory_enrichment_table_ttl_expirations_total"
}
}
}
}

#[cfg(test)]
mod tests {
use super::CounterName;

#[test]
fn memory_enrichment_table_counter_names_include_total_and_legacy() {
assert_eq!(
CounterName::MemoryEnrichmentTableFailedInsertionsTotal.as_str(),
"memory_enrichment_table_failed_insertions_total"
);
assert_eq!(
CounterName::MemoryEnrichmentTableFailedInsertions.as_str(),
"memory_enrichment_table_failed_insertions"
);
assert_eq!(
CounterName::MemoryEnrichmentTableFailedReadsTotal.as_str(),
"memory_enrichment_table_failed_reads_total"
);
assert_eq!(
CounterName::MemoryEnrichmentTableFailedReads.as_str(),
"memory_enrichment_table_failed_reads"
);
assert_eq!(
CounterName::MemoryEnrichmentTableTtlExpirationsTotal.as_str(),
"memory_enrichment_table_ttl_expirations_total"
);
assert_eq!(
CounterName::MemoryEnrichmentTableTtlExpirations.as_str(),
"memory_enrichment_table_ttl_expirations"
);
}
}
100 changes: 100 additions & 0 deletions src/enrichment_tables/memory/internal_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ pub(crate) struct MemoryEnrichmentTableTtlExpired<'a> {
impl InternalEvent for MemoryEnrichmentTableTtlExpired<'_> {
fn emit(self) {
if self.include_key_metric_tag {
counter!(
CounterName::MemoryEnrichmentTableTtlExpirationsTotal,
"key" => self.key.to_owned()
)
.increment(1);
counter!(
CounterName::MemoryEnrichmentTableTtlExpirations,
"key" => self.key.to_owned()
)
.increment(1);
} else {
counter!(CounterName::MemoryEnrichmentTableTtlExpirationsTotal,).increment(1);
counter!(CounterName::MemoryEnrichmentTableTtlExpirations,).increment(1);
}
}
Expand All @@ -101,12 +107,18 @@ pub(crate) struct MemoryEnrichmentTableReadFailed<'a> {
impl InternalEvent for MemoryEnrichmentTableReadFailed<'_> {
fn emit(self) {
if self.include_key_metric_tag {
counter!(
CounterName::MemoryEnrichmentTableFailedReadsTotal,
"key" => self.key.to_owned()
)
.increment(1);
counter!(
CounterName::MemoryEnrichmentTableFailedReads,
"key" => self.key.to_owned()
)
.increment(1);
} else {
counter!(CounterName::MemoryEnrichmentTableFailedReadsTotal,).increment(1);
counter!(CounterName::MemoryEnrichmentTableFailedReads,).increment(1);
}
}
Expand All @@ -121,13 +133,101 @@ pub(crate) struct MemoryEnrichmentTableInsertFailed<'a> {
impl InternalEvent for MemoryEnrichmentTableInsertFailed<'_> {
fn emit(self) {
if self.include_key_metric_tag {
counter!(
CounterName::MemoryEnrichmentTableFailedInsertionsTotal,
"key" => self.key.to_owned()
)
.increment(1);
counter!(
CounterName::MemoryEnrichmentTableFailedInsertions,
"key" => self.key.to_owned()
)
.increment(1);
} else {
counter!(CounterName::MemoryEnrichmentTableFailedInsertionsTotal,).increment(1);
counter!(CounterName::MemoryEnrichmentTableFailedInsertions,).increment(1);
}
}
}

#[cfg(test)]
mod tests {
use vector_lib::{
event::{Metric, MetricValue},
metrics::Controller,
};

use super::*;

const KEY: &str = "test_key";

fn emit_compatibility_events(include_key_metric_tag: bool) {
MemoryEnrichmentTableTtlExpired {
key: KEY,
include_key_metric_tag,
}
.emit();
MemoryEnrichmentTableReadFailed {
key: KEY,
include_key_metric_tag,
}
.emit();
MemoryEnrichmentTableInsertFailed {
key: KEY,
include_key_metric_tag,
}
.emit();
}

fn assert_counter(metrics: &[Metric], name: &str, key: Option<&str>) {
let metric = metrics
.iter()
.find(|metric| {
matches!(metric.value(), MetricValue::Counter { value } if *value == 1.0)
&& metric.name() == name
&& metric.tag_value("key").as_deref() == key
})
.unwrap_or_else(|| panic!("missing counter {name} with key {key:?}"));

if key.is_none() {
assert!(metric.tag_value("key").is_none());
}
}

fn assert_compatibility_counter_names(metrics: &[Metric], key: Option<&str>) {
for name in [
"memory_enrichment_table_ttl_expirations_total",
"memory_enrichment_table_ttl_expirations",
"memory_enrichment_table_failed_reads_total",
"memory_enrichment_table_failed_reads",
"memory_enrichment_table_failed_insertions_total",
"memory_enrichment_table_failed_insertions",
] {
assert_counter(metrics, name, key);
}
}

#[test]
fn compatibility_counters_emit_total_and_legacy_names_without_key() {
vector_lib::metrics::init_test();
let controller = Controller::get().unwrap();
controller.reset();

emit_compatibility_events(false);

let metrics = controller.capture_metrics();
assert_compatibility_counter_names(&metrics, None);
}

#[test]
fn compatibility_counters_emit_total_and_legacy_names_with_key() {
vector_lib::metrics::init_test();
let controller = Controller::get().unwrap();
controller.reset();

emit_compatibility_events(true);

let metrics = controller.capture_metrics();
assert_compatibility_counter_names(&metrics, Some(KEY));
}
}
Loading