Skip to content

Commit 1543057

Browse files
authored
Remove high cardinality ASN labels from metrics (#1277)
1 parent 611979d commit 1543057

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

src/metrics.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub const DIRECTION_LABEL: &str = "event";
2929

3030
pub(crate) const READ: Direction = Direction::Read;
3131
pub(crate) const WRITE: Direction = Direction::Write;
32+
#[allow(dead_code)]
3233
pub(crate) const ASN_LABEL: &str = "asn";
3334

3435
/// Label value for [`DIRECTION_LABEL`] for `read` events
@@ -523,88 +524,88 @@ pub(crate) fn processing_time(direction: Direction) -> Histogram {
523524
PROCESSING_TIME.with_label_values(&[direction.label()])
524525
}
525526

526-
pub(crate) fn bytes_total(direction: Direction, asn: &AsnInfo<'_>) -> IntCounter {
527+
pub(crate) fn bytes_total(direction: Direction, _asn: &AsnInfo<'_>) -> IntCounter {
527528
static BYTES_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
528529
prometheus::register_int_counter_vec_with_registry! {
529530
prometheus::opts! {
530531
"bytes_total",
531532
"total number of bytes",
532533
},
533-
&[Direction::LABEL, ASN_LABEL],
534+
&[Direction::LABEL],
534535
registry(),
535536
}
536537
.unwrap()
537538
});
538539

539-
BYTES_TOTAL.with_label_values(&[direction.label(), asn.asn])
540+
BYTES_TOTAL.with_label_values(&[direction.label()])
540541
}
541542

542-
pub(crate) fn errors_total(direction: Direction, display: &str, asn: &AsnInfo<'_>) -> IntCounter {
543+
pub(crate) fn errors_total(direction: Direction, display: &str, _asn: &AsnInfo<'_>) -> IntCounter {
543544
static ERRORS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
544545
prometheus::register_int_counter_vec_with_registry! {
545546
prometheus::opts! {
546547
"errors_total",
547548
"total number of errors sending packets",
548549
},
549-
&[Direction::LABEL, "display", ASN_LABEL],
550+
&[Direction::LABEL, "display"],
550551
registry(),
551552
}
552553
.unwrap()
553554
});
554555

555-
ERRORS_TOTAL.with_label_values(&[direction.label(), display, asn.asn])
556+
ERRORS_TOTAL.with_label_values(&[direction.label(), display])
556557
}
557558

558-
pub(crate) fn packet_jitter(direction: Direction, asn: &AsnInfo<'_>) -> IntGauge {
559+
pub(crate) fn packet_jitter(direction: Direction, _asn: &AsnInfo<'_>) -> IntGauge {
559560
static PACKET_JITTER: Lazy<IntGaugeVec> = Lazy::new(|| {
560561
prometheus::register_int_gauge_vec_with_registry! {
561562
prometheus::opts! {
562563
"packet_jitter",
563564
"The time between new packets",
564565
},
565-
&[Direction::LABEL, ASN_LABEL],
566+
&[Direction::LABEL],
566567
registry(),
567568
}
568569
.unwrap()
569570
});
570571

571-
PACKET_JITTER.with_label_values(&[direction.label(), asn.asn])
572+
PACKET_JITTER.with_label_values(&[direction.label()])
572573
}
573574

574-
pub(crate) fn packets_total(direction: Direction, asn: &AsnInfo<'_>) -> IntCounter {
575+
pub(crate) fn packets_total(direction: Direction, _asn: &AsnInfo<'_>) -> IntCounter {
575576
static PACKETS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
576577
prometheus::register_int_counter_vec_with_registry! {
577578
prometheus::opts! {
578579
"packets_total",
579580
"Total number of packets",
580581
},
581-
&[Direction::LABEL, ASN_LABEL],
582+
&[Direction::LABEL],
582583
registry(),
583584
}
584585
.unwrap()
585586
});
586587

587-
PACKETS_TOTAL.with_label_values(&[direction.label(), asn.asn])
588+
PACKETS_TOTAL.with_label_values(&[direction.label()])
588589
}
589590

590591
pub(crate) fn packets_dropped_total(
591592
direction: Direction,
592593
source: &str,
593-
asn: &AsnInfo<'_>,
594+
_asn: &AsnInfo<'_>,
594595
) -> IntCounter {
595596
static PACKETS_DROPPED: Lazy<IntCounterVec> = Lazy::new(|| {
596597
prometheus::register_int_counter_vec_with_registry! {
597598
prometheus::opts! {
598599
"packets_dropped_total",
599600
"Total number of dropped packets",
600601
},
601-
&[Direction::LABEL, "source", ASN_LABEL],
602+
&[Direction::LABEL, "source"],
602603
registry(),
603604
}
604605
.unwrap()
605606
});
606607

607-
PACKETS_DROPPED.with_label_values(&[direction.label(), source, asn.asn])
608+
PACKETS_DROPPED.with_label_values(&[direction.label(), source])
608609
}
609610

610611
pub(crate) fn provider_task_failures_total(provider_task: &str) -> IntCounter {

src/net/sessions/inner_metrics.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,28 @@ use prometheus::{Histogram, IntCounter, IntGauge, IntGaugeVec, Opts};
2020
use crate::metrics::{histogram_opts, register};
2121

2222
const SUBSYSTEM: &str = "session";
23+
#[allow(dead_code)]
2324
const AS_NAME_LABEL: &str = "organization";
2425
const COUNTRY_CODE_LABEL: &str = "country_code";
26+
#[allow(dead_code)]
2527
const PREFIX_ENTITY_LABEL: &str = "prefix_entity";
28+
#[allow(dead_code)]
2629
const PREFIX_NAME_LABEL: &str = "prefix_name";
27-
use crate::metrics::ASN_LABEL;
2830

2931
pub(crate) fn active_sessions(asn: Option<&crate::net::maxmind_db::IpNetEntry>) -> IntGauge {
3032
static ACTIVE_SESSIONS: Lazy<IntGaugeVec> = Lazy::new(|| {
3133
prometheus::register_int_gauge_vec_with_registry! {
3234
Opts::new("active", "number of sessions currently active").subsystem(SUBSYSTEM),
33-
&[ASN_LABEL, AS_NAME_LABEL, COUNTRY_CODE_LABEL, PREFIX_ENTITY_LABEL, PREFIX_NAME_LABEL],
35+
&[COUNTRY_CODE_LABEL],
3436
crate::metrics::registry(),
3537
}
3638
.unwrap()
3739
});
3840

3941
if let Some(asnfo) = asn {
40-
let mut asn = [0u8; 10];
41-
let len = crate::net::maxmind_db::itoa(asnfo.id, &mut asn);
42-
43-
ACTIVE_SESSIONS.with_label_values(&[
44-
// SAFETY: itoa only writes ASCII
45-
unsafe { std::str::from_utf8_unchecked(&asn[..len as _]) },
46-
&asnfo.as_name,
47-
&asnfo.as_cc,
48-
&asnfo.prefix_entity,
49-
&asnfo.prefix_name,
50-
])
42+
ACTIVE_SESSIONS.with_label_values(&[&asnfo.as_cc])
5143
} else {
52-
ACTIVE_SESSIONS.with_label_values(&["", "", "", "", ""])
44+
ACTIVE_SESSIONS.with_label_values(&[""])
5345
}
5446
}
5547

0 commit comments

Comments
 (0)