Skip to content

Commit 04f6685

Browse files
authored
ref(eap-outcomes): family friendly metric name (#7899)
1 parent 2d5b397 commit 04f6685

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

rust_snuba/src/strategies/accepted_outcomes/aggregator.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use sentry_arroyo::processing::strategies::{
1010
};
1111
use sentry_arroyo::types::{InnerMessage, Message, Partition};
1212
use sentry_arroyo::utils::timing::Deadline;
13-
use sentry_protos::snuba::v1::TraceItem;
13+
use sentry_protos::snuba::v1::{TraceItem, TraceItemType};
1414

1515
use sentry_options::options;
1616

17-
use crate::types::{AggregatedOutcomesBatch, BucketKey, ItemDedupKey};
17+
use crate::types::{item_type_name, AggregatedOutcomesBatch, BucketKey, ItemDedupKey};
1818

1919
#[derive(Debug, Default)]
2020
struct TraceItemOutcome {
@@ -88,7 +88,8 @@ impl<TNext> OutcomesAggregator<TNext> {
8888
fn is_duplicate(&mut self, trace_item: &TraceItem) -> bool {
8989
let org_id = trace_item.organization_id;
9090
let project_id = trace_item.project_id;
91-
let item_type = trace_item.item_type;
91+
let item_type =
92+
TraceItemType::try_from(trace_item.item_type).unwrap_or(TraceItemType::Unspecified);
9293

9394
if let Ok(item_id) = <[u8; 16]>::try_from(trace_item.item_id.as_slice()) {
9495
let dedup_key = ItemDedupKey {
@@ -129,7 +130,7 @@ impl<TNext> OutcomesAggregator<TNext> {
129130

130131
tracing::info!("flushed {} buckets after {} seconds", num_buckets, seconds);
131132
for (item_type, count) in duplicate_item_counts {
132-
let item_type_str = item_type.to_string();
133+
let item_type_str = item_type_name(item_type);
133134
counter!("accepted_outcomes.duplicate_items", count, "item_type" => item_type_str.as_str());
134135
}
135136
for (category, m) in category_metrics {
@@ -923,7 +924,7 @@ mod tests {
923924
aggregator
924925
.batch
925926
.duplicate_item_count
926-
.get(&TraceItemType::Span.into()),
927+
.get(&TraceItemType::Span),
927928
Some(&1)
928929
);
929930
}

rust_snuba/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl CogsData {
5757
}
5858

5959
/// Returns the friendly name for a TraceItemType, e.g. "span" instead of "TRACE_ITEM_TYPE_SPAN".
60-
fn item_type_name(item_type: TraceItemType) -> String {
60+
pub fn item_type_name(item_type: TraceItemType) -> String {
6161
item_type
6262
.as_str_name()
6363
.strip_prefix("TRACE_ITEM_TYPE_")
@@ -670,9 +670,9 @@ pub struct AggregatedOutcomesBatch {
670670
/// Per-category metrics for the current batch
671671
pub category_metrics: BTreeMap<u32, CategoryMetrics>,
672672
/// Set of items already processed in this batch, used for deduplication, keyed by item type
673-
pub seen_items: HashMap<i32, HashSet<ItemDedupKey>>,
673+
pub seen_items: HashMap<TraceItemType, HashSet<ItemDedupKey>>,
674674
/// Count of items skipped due to deduplication within this batch, keyed by item type
675-
pub duplicate_item_count: HashMap<i32, u64>,
675+
pub duplicate_item_count: HashMap<TraceItemType, u64>,
676676
}
677677

678678
impl Default for AggregatedOutcomesBatch {
@@ -696,7 +696,7 @@ impl AggregatedOutcomesBatch {
696696
}
697697
}
698698

699-
pub fn record_if_duplicate(&mut self, item_type: i32, key: ItemDedupKey) -> bool {
699+
pub fn record_if_duplicate(&mut self, item_type: TraceItemType, key: ItemDedupKey) -> bool {
700700
let is_dup = !self.seen_items.entry(item_type).or_default().insert(key);
701701
if is_dup {
702702
*self.duplicate_item_count.entry(item_type).or_insert(0) += 1;

0 commit comments

Comments
 (0)