Skip to content

Commit

Permalink
Limit number of retrieved event aggregations for stats and metrics (#…
Browse files Browse the repository at this point in the history
…2498)

Limit aggregations processing when retrieving stats and metrics

Make sure metrics and stats will never exceed cycles limit when
trying to collect event aggregations.
  • Loading branch information
Frederik Rothenberger authored Jun 7, 2024
1 parent e06aea1 commit 1ce1fa6
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ fn retrieve_aggregation_internal<M: Memory>(
ii_domain: Option<IIDomain>,
s: &Storage<M>,
) -> Vec<(String, u64)> {
// Limit the number of aggregations retrieved in one go to avoid hitting the cycles limit when
// retrieving stats or metrics. This limit is currently over-provisioned by ~10x.
// If the limit is reached, we should switch to a naturally ordered aggregation
// data structure such that we can retrieve the top-n elements directly.
const AGGREGATIONS_LIMIT: usize = 5_000;
let range_start = AggregationKey {
kind: aggregation.kind(),
window,
Expand All @@ -92,6 +97,7 @@ fn retrieve_aggregation_internal<M: Memory>(
let mut data: Vec<_> = s
.event_aggregations
.range((Bound::Included(range_start), range_end))
.take(AGGREGATIONS_LIMIT)
.map(|(key, weight)| (aggregation.key_label(key), weight))
.collect();
data.sort_by(|(_, weight_a), (_, weight_b)| weight_b.cmp(weight_a));
Expand Down

0 comments on commit 1ce1fa6

Please sign in to comment.