Skip to content

Commit b9aa0b9

Browse files
authored
fix(metrics): Make project max bucket limit partitioning aware (#4404)
1 parent 5144771 commit b9aa0b9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

relay-metrics/src/aggregator/inner.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ impl Inner {
253253
});
254254
}
255255
}
256+
let total_slots = slots.len();
256257

257258
let bucket_interval = u64::from(bucket_interval);
258259
let num_partitions = u64::from(num_partitions);
@@ -266,7 +267,22 @@ impl Inner {
266267
.map_or(u64::MAX, |v| v.div_ceil(bucket_interval)),
267268
};
268269

269-
let total_slots = slots.len();
270+
// Break down the maximum project cost to a maximum cost per partition.
271+
let max_partition_project = {
272+
let ratio_per_partition = match config.partition_by {
273+
// All buckets in the same timeslot of a project are in the same partition.
274+
// -> The total maximum allowed ratio is just determined by the amount of timeslots
275+
FlushBatching::None | FlushBatching::Project => u64::from(num_time_slots),
276+
// Buckets are evenly distributed across all existing partitions and timeslots.
277+
_ => total_slots as u64,
278+
};
279+
280+
config
281+
.max_project_key_bucket_bytes
282+
.map(|c| c.div_ceil(ratio_per_partition))
283+
.unwrap_or(u64::MAX)
284+
};
285+
270286
Self {
271287
slots: VecDeque::from(slots),
272288
num_partitions,
@@ -276,11 +292,7 @@ impl Inner {
276292
stats: stats::Total::default(),
277293
limits: stats::Limits {
278294
max_total: config.max_total_bucket_bytes.unwrap_or(u64::MAX),
279-
// Break down the maximum project cost to a maximum cost per partition.
280-
max_partition_project: config
281-
.max_project_key_bucket_bytes
282-
.map(|c| c.div_ceil(total_slots as u64))
283-
.unwrap_or(u64::MAX),
295+
max_partition_project,
284296
},
285297
slot_range: slot_diff,
286298
partition_by: config.partition_by,

0 commit comments

Comments
 (0)