Skip to content

Commit 8fcff0b

Browse files
authored
feat(statsd): Measure number of project config attempts (#1281)
Track a metric for how often project configs are re-attempted, either because they received a "pending" response or an error response.
1 parent 984717e commit 8fcff0b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

relay-server/src/actors/project_upstream.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct ProjectStateChannel {
9090
receiver: Shared<oneshot::Receiver<Arc<ProjectState>>>,
9191
deadline: Instant,
9292
no_cache: bool,
93+
attempts: u64,
9394
}
9495

9596
impl ProjectStateChannel {
@@ -101,6 +102,7 @@ impl ProjectStateChannel {
101102
receiver: receiver.shared(),
102103
deadline: Instant::now() + timeout,
103104
no_cache: false,
105+
attempts: 0,
104106
}
105107
}
106108

@@ -196,7 +198,10 @@ impl UpstreamProjectSource {
196198
let requests: Vec<_> = (cache_batches.into_iter())
197199
.chain(nocache_batches.into_iter())
198200
.map(|channels_batch| {
199-
let channels_batch: BTreeMap<_, _> = channels_batch.collect();
201+
let mut channels_batch: BTreeMap<_, _> = channels_batch.collect();
202+
for channel in channels_batch.values_mut() {
203+
channel.attempts += 1;
204+
}
200205
relay_log::debug!("sending request of size {}", channels_batch.len());
201206
metric!(
202207
histogram(RelayHistograms::ProjectStateRequestBatchSize) =
@@ -261,7 +266,10 @@ impl UpstreamProjectSource {
261266
Some(ProjectState::err())
262267
})
263268
.unwrap_or_else(ProjectState::missing);
264-
269+
metric!(
270+
histogram(RelayHistograms::ProjectStateAttempts) =
271+
channel.attempts
272+
);
265273
channel.send(state.sanitize());
266274
}
267275
}

relay-server/src/statsd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub enum RelayHistograms {
8989
///
9090
/// See `project_cache.size` for more description of the project cache.
9191
ProjectStateReceived,
92+
/// Number of attempts required to fetch the config for a given project key.
93+
ProjectStateAttempts,
9294
/// Number of project states currently held in the in-memory project cache.
9395
///
9496
/// The cache duration for project states can be configured with the following options:
@@ -150,6 +152,7 @@ impl HistogramMetric for RelayHistograms {
150152
RelayHistograms::RequestSizeBytesRaw => "event.size_bytes.raw",
151153
RelayHistograms::RequestSizeBytesUncompressed => "event.size_bytes.uncompressed",
152154
RelayHistograms::ProjectStatePending => "project_state.pending",
155+
RelayHistograms::ProjectStateAttempts => "project_state.attempts",
153156
RelayHistograms::ProjectStateRequestBatchSize => "project_state.request.batch_size",
154157
RelayHistograms::ProjectStateReceived => "project_state.received",
155158
RelayHistograms::ProjectStateCacheSize => "project_cache.size",

0 commit comments

Comments
 (0)