Skip to content

Commit

Permalink
ref(store): Instrument store message handler (#3838)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde authored Jul 19, 2024
1 parent 28a0b5f commit 4e666e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
26 changes: 20 additions & 6 deletions relay-server/src/services/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::service::ServiceError;
use crate::services::global_config::GlobalConfigHandle;
use crate::services::outcome::{DiscardReason, Outcome, TrackOutcome};
use crate::services::processor::Processed;
use crate::statsd::RelayCounters;
use crate::statsd::{RelayCounters, RelayTimers};
use crate::utils::{is_rolled_out, FormDataIter, TypedEnvelope};

/// Fallback name used for attachment items without a `filename` header.
Expand Down Expand Up @@ -101,6 +101,17 @@ pub enum Store {
Cogs(StoreCogs),
}

impl Store {
/// Returns the name of the message variant.
fn variant(&self) -> &'static str {
match self {
Store::Envelope(_) => "envelope",
Store::Metrics(_) => "metrics",
Store::Cogs(_) => "cogs",
}
}
}

impl Interface for Store {}

impl FromMessage<StoreEnvelope> for Store {
Expand Down Expand Up @@ -154,11 +165,14 @@ impl StoreService {
}

fn handle_message(&self, message: Store) {
match message {
Store::Envelope(message) => self.handle_store_envelope(message),
Store::Metrics(message) => self.handle_store_metrics(message),
Store::Cogs(message) => self.handle_store_cogs(message),
}
let ty = message.variant();
relay_statsd::metric!(timer(RelayTimers::StoreServiceDuration), message = ty, {
match message {
Store::Envelope(message) => self.handle_store_envelope(message),
Store::Metrics(message) => self.handle_store_metrics(message),
Store::Cogs(message) => self.handle_store_cogs(message),
}
})
}

fn handle_store_envelope(&self, message: StoreEnvelope) {
Expand Down
8 changes: 8 additions & 0 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ pub enum RelayTimers {
/// This metric is tagged with:
/// - `message`: The type of message that was processed.
MetricRouterServiceDuration,
/// Timing in milliseconds for processing a message in the metric store service.
///
/// This metric is tagged with:
/// - `message`: The type of message that was processed.
#[cfg(feature = "processing")]
StoreServiceDuration,
}

impl TimerMetric for RelayTimers {
Expand Down Expand Up @@ -566,6 +572,8 @@ impl TimerMetric for RelayTimers {
RelayTimers::RateLimitBucketsDuration => "processor.rate_limit_buckets",
RelayTimers::AggregatorServiceDuration => "metrics.aggregator.message.duration",
RelayTimers::MetricRouterServiceDuration => "metrics.router.message.duration",
#[cfg(feature = "processing")]
RelayTimers::StoreServiceDuration => "store.message.duration",
}
}
}
Expand Down

0 comments on commit 4e666e1

Please sign in to comment.