Struct relay_metrics::aggregator::Aggregator
source · pub struct Aggregator { /* private fields */ }
Expand description
A collector of Bucket
submissions.
§Aggregation
Each metric is dispatched into the a Bucket
depending on its project key (DSN), name, type,
unit, tags and timestamp. The bucket timestamp is rounded to the precision declared by the
bucket_interval
field on the AggregatorConfig configuration.
Each bucket stores the accumulated value of submitted metrics:
Counter
: Sum of values.Distribution
: A list of values.Set
: A unique set of hashed values.Gauge
: A summary of the reported values, seeGaugeValue
.
§Conflicts
Metrics are uniquely identified by the combination of their name, type and unit. It is allowed to send metrics of different types and units under the same name. For example, sending a metric once as set and once as distribution will result in two actual metrics being recorded.
Implementations§
source§impl Aggregator
impl Aggregator
sourcepub fn new(config: AggregatorConfig) -> Self
pub fn new(config: AggregatorConfig) -> Self
Create a new aggregator.
sourcepub fn named(name: String, config: AggregatorConfig) -> Self
pub fn named(name: String, config: AggregatorConfig) -> Self
Like Self::new
, but with a provided name.
sourcepub fn bucket_count(&self) -> usize
pub fn bucket_count(&self) -> usize
Returns the number of buckets in the aggregator.
sourcepub fn totals_cost_exceeded(&self) -> bool
pub fn totals_cost_exceeded(&self) -> bool
Returns true
if the cost trackers value is larger than the configured max cost.
sourcepub fn into_buckets(self) -> Vec<Bucket>
pub fn into_buckets(self) -> Vec<Bucket>
Converts this aggregator into a vector of Bucket
.
sourcepub fn pop_flush_buckets(
&mut self,
force: bool,
) -> HashMap<Option<u64>, HashMap<ProjectKey, Vec<Bucket>>>
pub fn pop_flush_buckets( &mut self, force: bool, ) -> HashMap<Option<u64>, HashMap<ProjectKey, Vec<Bucket>>>
Pop and return the partitions with buckets that are eligible for flushing out according to bucket interval.
If no partitioning is enabled, the function will return a single None
partition.
Note that this function is primarily intended for tests.
sourcepub fn merge(
&mut self,
project_key: ProjectKey,
bucket: Bucket,
) -> Result<(), AggregateMetricsError>
pub fn merge( &mut self, project_key: ProjectKey, bucket: Bucket, ) -> Result<(), AggregateMetricsError>
Merge a bucket into this aggregator.
Like Self::merge_with_options
with defaults.
sourcepub fn merge_with_options(
&mut self,
project_key: ProjectKey,
bucket: Bucket,
now: UnixTimestamp,
) -> Result<(), AggregateMetricsError>
pub fn merge_with_options( &mut self, project_key: ProjectKey, bucket: Bucket, now: UnixTimestamp, ) -> Result<(), AggregateMetricsError>
Merge a bucket into this aggregator.
If no bucket exists for the given bucket key, a new bucket will be created.
Arguments:
now
: The current timestamp, when merging a large batch of buckets, the timestamp should be created outside of the loop.