-
Notifications
You must be signed in to change notification settings - Fork 508
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
refactor: AggregatedMetrics as enum instead of dyn Aggregation #2857
Conversation
0b88d1f
to
3692f9b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2857 +/- ##
=======================================
- Coverage 80.9% 80.7% -0.2%
=======================================
Files 124 124
Lines 23726 23703 -23
=======================================
- Hits 19201 19146 -55
- Misses 4525 4557 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
/// Support downcasting during aggregation | ||
fn as_mut(&mut self) -> &mut dyn any::Any; | ||
/// Aggregated metrics data from an instrument | ||
#[derive(Debug, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a user's perspective, it's more convenient to have a MetricData<T>
, because this allows almost all code to be generic over metric data.
fn clone_inner<T: Clone>(data: &MetricData<T>) -> MetricData<T> {
match data {
MetricData::Gauge(gauge) => Gauge {
data_points: gauge.data_points.clone(),
start_time: gauge.start_time,
time: gauge.time,
}
.into(),
MetricData::Sum(sum) => Sum {
data_points: sum.data_points.clone(),
start_time: sum.start_time,
time: sum.time,
temporality: sum.temporality,
is_monotonic: sum.is_monotonic,
}
.into(),
MetricData::Histogram(histogram) => Histogram {
data_points: histogram.data_points.clone(),
start_time: histogram.start_time,
time: histogram.time,
temporality: histogram.temporality,
}
.into(),
MetricData::ExponentialHistogram(exponential_histogram) => ExponentialHistogram {
data_points: exponential_histogram.data_points.clone(),
start_time: exponential_histogram.start_time,
time: exponential_histogram.time,
temporality: exponential_histogram.temporality,
}
.into(),
}
}
match data {
AggregatedMetrics::F64(metric_data) => AggregatedMetrics::F64(clone_inner(metric_data)),
AggregatedMetrics::U64(metric_data) => AggregatedMetrics::U64(clone_inner(metric_data)),
AggregatedMetrics::I64(metric_data) => AggregatedMetrics::I64(clone_inner(metric_data)),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can followup on the open comments (Moving resource out, removing i64 in aggregation etc.)
Changes
AggregatedMetrics
enum, which store data reported by Instruments.Metric::data
field fromBox<dyn Aggregation>
toAggregatedMetrics
.ResourceMetrics
is nowClone
, becauseAggregatedMetrics
is a simple enum that can be easilycloned
.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes