-
Notifications
You must be signed in to change notification settings - Fork 501
[Metrics] Perform async Re-Aggregation when Spatial Attributes are dropped #3691
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
base: main
Are you sure you want to change the base?
[Metrics] Perform async Re-Aggregation when Spatial Attributes are dropped #3691
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3691 +/- ##
==========================================
- Coverage 89.95% 89.75% -0.20%
==========================================
Files 225 226 +1
Lines 7273 7326 +53
==========================================
+ Hits 6542 6575 +33
- Misses 731 751 +20
🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR addresses the issue of performing async re-aggregation when spatial attributes are dropped in OpenTelemetry metrics. The main purpose is to ensure that when attributes are filtered out by attribute processors in async counters, the measurements are properly reaggregated to combine values that now have identical attribute sets.
Key changes include:
- Introduced a new
MeasurementAttributestype for better handling of attribute-value mappings - Modified async metric storage to perform reaggregation during attribute processing
- Updated observer result handling to use the new measurement structure
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/include/opentelemetry/sdk/metrics/state/measurement_attributes_map.h | New header defining custom hash/equality functions and MeasurementAttributes type for attribute maps |
| sdk/include/opentelemetry/sdk/metrics/observer_result.h | Updated ObserverResultT to use new MeasurementAttributes type and removed dependency on AttributesProcessor |
| sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h | Added ConvertMeasurementsToMetricAttributes method to handle reaggregation and attributes processor integration |
| sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h | Updated AsyncWritableMetricStorage interface to use MeasurementAttributes type |
| sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h | Updated AsyncMultiMetricStorage to use new MeasurementAttributes type |
| sdk/src/metrics/meter.cc | Modified async metric storage registration to pass attributes processor |
| sdk/src/metrics/state/observable_registry.cc | Updated to create ObserverResultT without attributes processor parameter |
| sdk/test/metrics/async_metric_storage_test.cc | Updated tests to use new types and added attributes processor setup |
| sdk/test/metrics/observer_result_test.cc | Simplified test to use new ObserverResultT constructor |
| sdk/test/metrics/sum_aggregation_test.cc | Added comprehensive tests for observable counter reaggregation scenarios |
sdk/include/opentelemetry/sdk/metrics/state/measurement_attributes_map.h
Show resolved
Hide resolved
sdk/include/opentelemetry/sdk/metrics/state/measurement_attributes_map.h
Show resolved
Hide resolved
|
Assigned it to self. Will review during this week. |
| explicit ObserverResultT(const AttributesProcessor *attributes_processor = nullptr) | ||
| : attributes_processor_(attributes_processor) | ||
| {} | ||
| explicit ObserverResultT() = default; |
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.
explicit not required for default constructor. Here it can also be removed (rule of 0)
| AttributeMapHash, | ||
| AttributeMapEqual>; | ||
|
|
||
| } // namespace metrics |
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.
add another type here for use in AsyncMetricStorage:
using MeasurementsKeyType = typename Measurements::key_type;
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.
I am not sure that it's worth, adding another runtime expensive associative container just for a list of some attributes. Unordered_map gets efficient with thousands and thousands of entries. But still very slow in comparison to a boost::flat_map or absl::flat_hash_map or a simple std::vector.
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.
with the type std::unordered_map<nostd::string_view, opentelemetry::common::AttributeValue> it will also lead to dangling references. It will work when the string_view is created with "abcd", because this will stay in memory, but putting in a std::string... > crash
| void Observe(T value) noexcept override | ||
| { | ||
| data_[MetricAttributes{{}, attributes_processor_}] = value; | ||
| std::unordered_map<nostd::string_view, opentelemetry::common::AttributeValue> empty; |
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.
Can be replaced with new type MeasurementsKeyType
| { | ||
| data_[MetricAttributes{attributes, attributes_processor_}] = | ||
| value; // overwrites the previous value if present | ||
| std::unordered_map<nostd::string_view, opentelemetry::common::AttributeValue> attr_map; |
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.
replace with new type MeasurementsKeyType
| exemplar_filter_type | ||
| #endif | ||
| ](const View &view) { | ||
| ](const View &view) -> bool { |
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.
superfluous, compiler knows it
| opentelemetry::sdk::metrics::FilterAttributeMap allowedattr; | ||
|
|
||
| std::unique_ptr<opentelemetry::sdk::metrics::AttributesProcessor> attrproc{ | ||
| new opentelemetry::sdk::metrics::FilteringAttributesProcessor(allowedattr)}; |
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.
please replace new with std::make_unique or std::make_shared accordingly. Rationale - CppCoreGuidelines#r22 and r23
|
|
||
| // Hash function for unordered_map of key-value pairs | ||
| // This Custom Hash is only applied to strings and int for now | ||
| struct AttributeMapHash |
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.
Please see sdk/common/attributemap_hash.h -> GetHash and GetHashForAttributeValueVisitor. Consider if these can be used.
|
Thanks for the PR @nikhilbhatia08! I've left a few nitpick comments but I'm interested to dig more into the specification and requirements for this change to provide a better review. The original linked issue #1724 is a bit old and it references an opentelemetry-specification issue 2905 that has since been closed as not planned. Can you update the description of the PR with a bit more context on the use cases enabled and links to the relevant sections of otel specification? Thanks! |
Fixes #1724
Performing Reaggregation when spatial dimensions are dropped in async counters. There are also unit tests provided to the change.
Changes
Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes