Skip to content

Commit

Permalink
instr(buffer): Fewer metrics (#4329)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer authored Dec 3, 2024
1 parent b7f5912 commit 52d3f6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 55 deletions.
14 changes: 1 addition & 13 deletions relay-server/src/services/buffer/envelope_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::services::buffer::envelope_store::sqlite::SqliteEnvelopeStoreError;
use crate::services::buffer::stack_provider::memory::MemoryStackProvider;
use crate::services::buffer::stack_provider::sqlite::SqliteStackProvider;
use crate::services::buffer::stack_provider::{StackCreationType, StackProvider};
use crate::statsd::{RelayCounters, RelayGauges, RelayHistograms, RelayTimers};
use crate::statsd::{RelayGauges, RelayHistograms, RelayTimers};
use crate::utils::MemoryChecker;

/// Polymorphic envelope buffering interface.
Expand Down Expand Up @@ -97,10 +97,6 @@ impl PolymorphicEnvelopeBuffer {
}?;
}
);
relay_statsd::metric!(
counter(RelayCounters::BufferEnvelopesWritten) += 1,
partition_id = self.partition_tag()
);
Ok(())
}

Expand Down Expand Up @@ -130,10 +126,6 @@ impl PolymorphicEnvelopeBuffer {
}?
}
);
relay_statsd::metric!(
counter(RelayCounters::BufferEnvelopesRead) += 1,
partition_id = self.partition_tag()
);
Ok(envelope)
}

Expand Down Expand Up @@ -377,10 +369,6 @@ where

match last_received_at {
None => {
relay_statsd::metric!(
counter(RelayCounters::BufferEnvelopeStacksPopped) += 1,
partition_id = &self.partition_tag
);
self.pop_stack(project_key_pair);
}
Some(last_received_at) => {
Expand Down
36 changes: 7 additions & 29 deletions relay-server/src/services/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,43 +243,16 @@ impl EnvelopeBufferService {
/// Wait for the configured amount of time and make sure the project cache is ready to receive.
async fn ready_to_pop(
&mut self,
partition_tag: &str,
buffer: &PolymorphicEnvelopeBuffer,
dequeue: bool,
) -> Option<Permit<legacy::DequeuedEnvelope>> {
relay_statsd::metric!(
counter(RelayCounters::BufferReadyToPop) += 1,
status = "checking",
partition_id = partition_tag
);

self.system_ready(buffer, dequeue).await;

relay_statsd::metric!(
counter(RelayCounters::BufferReadyToPop) += 1,
status = "system_ready",
partition_id = partition_tag
);

if self.sleep > Duration::ZERO {
tokio::time::sleep(self.sleep).await;
}

relay_statsd::metric!(
counter(RelayCounters::BufferReadyToPop) += 1,
status = "slept",
partition_id = partition_tag
);

let permit = self.services.envelopes_tx.reserve().await.ok();

relay_statsd::metric!(
counter(RelayCounters::BufferReadyToPop) += 1,
status = "checked",
partition_id = partition_tag
);

permit
self.services.envelopes_tx.reserve().await.ok()
}

/// Waits until preconditions for unspooling are met.
Expand Down Expand Up @@ -328,6 +301,11 @@ impl EnvelopeBufferService {
| Peek::NotReady {
last_received_at, ..
} if is_expired(last_received_at, config) => {
relay_statsd::metric!(
counter(RelayCounters::BufferTryPop) += 1,
peek_result = "expired",
partition_id = partition_tag
);
let envelope = buffer
.pop()
.await?
Expand Down Expand Up @@ -530,7 +508,7 @@ impl Service for EnvelopeBufferService {
// On the one hand, we might want to prioritize dequeuing over enqueuing
// so we do not exceed the buffer capacity by starving the dequeue.
// on the other hand, prioritizing old messages violates the LIFO design.
Some(permit) = self.ready_to_pop(&partition_tag, &buffer, dequeue.load(Ordering::Relaxed)) => {
Some(permit) = self.ready_to_pop(&buffer, dequeue.load(Ordering::Relaxed)) => {
relay_statsd::metric!(timer(RelayTimers::BufferIdle) = start.elapsed(), input = "pop", partition_id = &partition_tag);
relay_statsd::metric!(timer(RelayTimers::BufferBusy), input = "pop", partition_id = &partition_tag, {
match Self::try_pop(&partition_tag, &config, &mut buffer, &services, permit).await {
Expand Down
13 changes: 0 additions & 13 deletions relay-server/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,22 +649,13 @@ pub enum RelayCounters {
/// - `handling`: Either `"success"` if the envelope was handled correctly, or `"failure"` if
/// there was an error or bug.
EnvelopeRejected,
/// Number of _envelopes_ the envelope buffer ingests.
BufferEnvelopesWritten,
/// Number of _envelopes_ the envelope buffer produces.
BufferEnvelopesRead,
/// Number of envelopes that were returned to the envelope buffer by the project cache.
///
/// This happens when the envelope buffer falsely assumes that the envelope's projects are loaded
/// in the cache and sends the envelope onward, even though the project cache cannot handle it.
BufferEnvelopesReturned,
/// Number of times an envelope stack is popped from the priority queue of stacks in the
/// envelope buffer.
BufferEnvelopeStacksPopped,
/// Number of times an envelope from the buffer is trying to be popped.
BufferTryPop,
/// Number of times the readiness check of the buffer is polled.
BufferReadyToPop,
/// Number of envelopes spool to disk.
BufferSpooledEnvelopes,
/// Number of envelopes unspooled from disk.
Expand Down Expand Up @@ -852,12 +843,8 @@ impl CounterMetric for RelayCounters {
RelayCounters::EventCorrupted => "event.corrupted",
RelayCounters::EnvelopeAccepted => "event.accepted",
RelayCounters::EnvelopeRejected => "event.rejected",
RelayCounters::BufferEnvelopesWritten => "buffer.envelopes_written",
RelayCounters::BufferEnvelopesRead => "buffer.envelopes_read",
RelayCounters::BufferEnvelopesReturned => "buffer.envelopes_returned",
RelayCounters::BufferEnvelopeStacksPopped => "buffer.envelope_stacks_popped",
RelayCounters::BufferTryPop => "buffer.try_pop",
RelayCounters::BufferReadyToPop => "buffer.ready_to_pop",
RelayCounters::BufferSpooledEnvelopes => "buffer.spooled_envelopes",
RelayCounters::BufferUnspooledEnvelopes => "buffer.unspooled_envelopes",
RelayCounters::Outcomes => "events.outcomes",
Expand Down

0 comments on commit 52d3f6c

Please sign in to comment.