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

Optimize Metric Processing for Single Collector with Delta Temporality #3236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sdk/src/metrics/state/temporal_metric_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector,
AggregationTemporality aggregation_temporarily =
collector->GetAggregationTemporality(instrument_descriptor_.type_);

// Fast path for single collector with delta temporality and counter, updown-counter, histogram
if (collectors.size() == 1 && collector->GetAggregationTemporality(
instrument_descriptor_.type_) == AggregationTemporality::kDelta)
Comment on lines +55 to +56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use the aggregation_temporarily local variable, from the previous line, in the if test.

{
// If no metrics, early return
if (delta_metrics->Size() == 0)
{
return true;
}

// Create MetricData directly
MetricData metric_data;
metric_data.instrument_descriptor = instrument_descriptor_;
metric_data.aggregation_temporality = AggregationTemporality::kDelta;
metric_data.start_ts = sdk_start_ts;
metric_data.end_ts = collection_ts;

// Direct conversion of delta metrics to point data
delta_metrics->GetAllEnteries(
[&metric_data](const MetricAttributes &attributes, Aggregation &aggregation) {
PointDataAttributes point_data_attr;
point_data_attr.point_data = aggregation.ToPoint();
point_data_attr.attributes = attributes;
metric_data.point_data_attr_.emplace_back(std::move(point_data_attr));
return true;
});

return callback(metric_data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea if this can happen or not, does the code in the fast path needs to pay attention to previous metrics in unreported_metrics_ ?

If not, consider to add a comment to explain why, and/or an assert to make sure there are no unreported metrics.

}

if (delta_metrics->Size())
{
for (auto &col : collectors)
Expand Down
Loading