From 983162bd671d04b6618f78eb5e3d833c30361fa2 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 9 Jan 2025 14:03:04 +0000 Subject: [PATCH 1/4] initial commit --- .../metrics/state/temporal_metric_storage.cc | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 10fabdf531..68d3d22325 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -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) + { + // 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); + } + if (delta_metrics->Size()) { for (auto &col : collectors) From 03efcb5911b007b597175db3a4be4be890c18346 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 21 Jan 2025 16:54:56 -0800 Subject: [PATCH 2/4] review comments --- sdk/src/metrics/state/temporal_metric_storage.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 68d3d22325..85630ef479 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -51,15 +51,15 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, AggregationTemporality aggregation_temporarily = collector->GetAggregationTemporality(instrument_descriptor_.type_); + // If no metrics, early return + if (delta_metrics->Size() == 0) + { + return true; + } + // Fast path for single collector with delta temporality and counter, updown-counter, histogram - if (collectors.size() == 1 && collector->GetAggregationTemporality( - instrument_descriptor_.type_) == AggregationTemporality::kDelta) + if (collectors.size() == 1 && aggregation_temporarily == AggregationTemporality::kDelta) { - // If no metrics, early return - if (delta_metrics->Size() == 0) - { - return true; - } // Create MetricData directly MetricData metric_data; From 822861b5b3b5e7d5e814e2a23a2e2c845cbb1ace Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 21 Jan 2025 17:05:59 -0800 Subject: [PATCH 3/4] revert --- .../metrics/state/temporal_metric_storage.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 85630ef479..34630f3f67 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -51,16 +51,16 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, AggregationTemporality aggregation_temporarily = collector->GetAggregationTemporality(instrument_descriptor_.type_); - // If no metrics, early return - if (delta_metrics->Size() == 0) - { - return true; - } - // Fast path for single collector with delta temporality and counter, updown-counter, histogram + // This path doesn't need to aggregated-with/contribute-to the unreported_metric_, as there is + // no other reader configured to collect those data. if (collectors.size() == 1 && aggregation_temporarily == AggregationTemporality::kDelta) { - + // If no metrics, early return + if (delta_metrics->Size() == 0) + { + return true; + } // Create MetricData directly MetricData metric_data; metric_data.instrument_descriptor = instrument_descriptor_; @@ -77,12 +77,10 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, metric_data.point_data_attr_.emplace_back(std::move(point_data_attr)); return true; }); - return callback(metric_data); } - if (delta_metrics->Size()) - { + if (delta_metrics->Size()) { for (auto &col : collectors) { unreported_metrics_[col.get()].push_back(delta_metrics); From 24ab03559ee25233d6085b912768914b00b9172f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 21 Jan 2025 17:08:59 -0800 Subject: [PATCH 4/4] format --- sdk/src/metrics/state/temporal_metric_storage.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index 34630f3f67..1302f9d642 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -52,7 +52,7 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, collector->GetAggregationTemporality(instrument_descriptor_.type_); // Fast path for single collector with delta temporality and counter, updown-counter, histogram - // This path doesn't need to aggregated-with/contribute-to the unreported_metric_, as there is + // This path doesn't need to aggregated-with/contribute-to the unreported_metric_, as there is // no other reader configured to collect those data. if (collectors.size() == 1 && aggregation_temporarily == AggregationTemporality::kDelta) { @@ -80,7 +80,8 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, return callback(metric_data); } - if (delta_metrics->Size()) { + if (delta_metrics->Size()) + { for (auto &col : collectors) { unreported_metrics_[col.get()].push_back(delta_metrics);