Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(metrics): Tag backdated bucket creations in statsd [INGEST-954] #1200

Merged
merged 3 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Internal**:

- Spread out metric aggregation over the aggregation window to avoid concentrated waves of metrics requests to the upstream every 10 seconds. Relay now applies jitter to `initial_delay` to spread out requests more evenly over time. ([#1185](https://github.com/getsentry/relay/pull/1185))
- Add new statsd metrics for bucketing efficiency ([#1199](https://github.com/getsentry/relay/pull/1199), [#1192](https://github.com/getsentry/relay/pull/1192))
- Add new statsd metrics for bucketing efficiency ([#1199](https://github.com/getsentry/relay/pull/1199), [#1192](https://github.com/getsentry/relay/pull/1192), [#1200](https://github.com/getsentry/relay/pull/1200))

## 22.2.0

Expand Down
14 changes: 12 additions & 2 deletions relay-metrics/src/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ impl AggregatorConfig {
/// is, buckets that lie in the past, are flushed after the shorter `debounce_delay`.
fn get_flush_time(&self, bucket_timestamp: UnixTimestamp, project_key: ProjectKey) -> Instant {
let now = Instant::now();
let mut flush = None;

if let MonotonicResult::Instant(instant) = bucket_timestamp.to_instant() {
let bucket_end = instant + self.bucket_interval();
Expand All @@ -853,13 +854,22 @@ impl AggregatorConfig {
hasher.write(project_key.as_str().as_bytes());
let shift_millis = u64::from(hasher.finish()) % (self.bucket_interval * 1000);

return initial_flush + Duration::from_millis(shift_millis);
flush = Some(initial_flush + Duration::from_millis(shift_millis));
}
}

let delay = UnixTimestamp::now().as_secs() as i64 - bucket_timestamp.as_secs() as i64;
relay_statsd::metric!(
histogram(MetricHistograms::BucketsDelay) = delay as f64,
backedated = if flush.is_none() { "true" } else { "false" },
);

// If the initial flush time has passed or cannot be represented, debounce future flushes
// with the `debounce_delay` starting now.
now + self.debounce_delay()
match flush {
Some(initial_flush) => initial_flush,
None => now + self.debounce_delay(),
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions relay-metrics/src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ pub enum MetricHistograms {
/// BucketRelativeSize measures how many distinct values are in a bucket and therefore
/// BucketRelativeSize gives you a measurement of the bucket size and complexity.
BucketRelativeSize,

/// The reporting delay at which a bucket arrives in Relay.
///
/// A positive delay indicates the bucket arrives after its stated timestamp. Large delays
/// indicate backdating, particularly all delays larger than `bucket_interval + initial_delay`.
/// Negative delays indicate that the bucket is dated into the future, likely due to clock drift
/// on the client.
///
/// This metric is tagged with:
/// - `backdated`: A flag indicating whether the metric was reported within the `initial_delay`
/// time period (`false`) or after the initial delay has expired (`true`).
BucketsDelay,
}

impl HistogramMetric for MetricHistograms {
Expand All @@ -99,6 +111,7 @@ impl HistogramMetric for MetricHistograms {
Self::BucketsFlushed => "metrics.buckets.flushed",
Self::BucketsFlushedPerProject => "metrics.buckets.flushed_per_project",
Self::BucketRelativeSize => "metrics.buckets.relative_bucket_size",
Self::BucketsDelay => "metrics.buckets.delay",
}
}
}
Expand Down