-
Notifications
You must be signed in to change notification settings - Fork 567
Asynchronous Aggregation storage #1232
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e3cc10b
initial commit
lalitb 2dfd1de
remaining files
lalitb 6286691
Format
lalitb 40fe87c
revert newline change
lalitb bf8c71b
fix bazel build
lalitb 40d4ae4
review comments
lalitb d307397
Merge branch 'main' into async-store
lalitb 7a12b64
Merge branch 'main' into async-store
esigo 31271be
Merge branch 'main' into async-store
esigo 8b4b394
fix
lalitb 26803b0
Merge branch 'async-store' of github.com:lalitb/opentelemetry-cpp int…
lalitb a45f968
Merge branch 'main' into async-store
esigo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #ifndef ENABLE_METRICS_PREVIEW | ||
| # include "opentelemetry/common/key_value_iterable.h" | ||
| # include "opentelemetry/metrics/observer_result.h" | ||
| # include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" | ||
| # include "opentelemetry/sdk/metrics/view/attributes_processor.h" | ||
|
|
||
| # include <map> | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace metrics | ||
| { | ||
| template <class T> | ||
| class ObserverResult final : public opentelemetry::metrics::ObserverResult<T> | ||
| { | ||
| public: | ||
| ObserverResult(const AttributesProcessor *attributes_processor) | ||
| : attributes_processor_(attributes_processor) | ||
| {} | ||
|
|
||
| void Observe(T value) noexcept override { data_.insert({{}, value}); } | ||
|
|
||
| void Observe(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
| { | ||
| auto attr = attributes_processor_->process(attributes); | ||
| data_.insert({attr, value}); | ||
| } | ||
|
|
||
| const std::unordered_map<MetricAttributes, T, AttributeHashGenerator> &GetMeasurements() | ||
| { | ||
| return data_; | ||
| } | ||
|
|
||
| private: | ||
| std::unordered_map<MetricAttributes, T, AttributeHashGenerator> data_; | ||
|
|
||
| const AttributesProcessor *attributes_processor_; | ||
| }; | ||
| } // namespace metrics | ||
| } // namespace sdk | ||
|
|
||
| OPENTELEMETRY_END_NAMESPACE | ||
| #endif |
80 changes: 80 additions & 0 deletions
80
sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #ifndef ENABLE_METRICS_PREVIEW | ||
| # include "opentelemetry/sdk/common/attributemap_hash.h" | ||
| # include "opentelemetry/sdk/metrics/instruments.h" | ||
|
|
||
| # include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" | ||
| # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" | ||
| # include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" | ||
| # include "opentelemetry/sdk/metrics/state/metric_storage.h" | ||
| # include "opentelemetry/sdk/metrics/view/attributes_processor.h" | ||
| # include "opentelemetry/sdk/resource/resource.h" | ||
|
|
||
| # include <memory> | ||
| # include "opentelemetry/sdk/metrics/observer_result.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace metrics | ||
| { | ||
|
|
||
| template <class T> | ||
| class AsyncMetricStorage : public MetricStorage | ||
| { | ||
| public: | ||
| AsyncMetricStorage(InstrumentDescriptor instrument_descriptor, | ||
| const AggregationType aggregation_type, | ||
| void (*measurement_callback)(opentelemetry::metrics::ObserverResult<T> &), | ||
| const AttributesProcessor *attributes_processor) | ||
| : instrument_descriptor_(instrument_descriptor), | ||
| aggregation_type_{aggregation_type}, | ||
| measurement_collection_callback_{measurement_callback}, | ||
| attributes_processor_{attributes_processor}, | ||
| active_attributes_hashmap_(new AttributesHashMap()) | ||
| {} | ||
|
|
||
| bool Collect( | ||
| MetricCollector *collector, | ||
| nostd::span<MetricCollector *> collectors, | ||
| opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary *instrumentation_library, | ||
| opentelemetry::sdk::resource::Resource *resource, | ||
| nostd::function_ref<bool(MetricData &)> metric_collection_callback) noexcept override | ||
| { | ||
| opentelemetry::sdk::metrics::ObserverResult<T> ob_res(attributes_processor_); | ||
|
|
||
| // read the measurement using configured callback | ||
| measurement_collection_callback_(ob_res); | ||
|
|
||
| // process the read measurements - aggregate and store in hashmap | ||
| for (auto &measurement : ob_res.GetMeasurements()) | ||
| { | ||
| auto agg = DefaultAggregation::CreateAggregation(aggregation_type_, instrument_descriptor_); | ||
| agg->Aggregate(measurement.second); | ||
| active_attributes_hashmap_->Set(measurement.first, std::move(agg)); | ||
| } | ||
|
|
||
| // TBD -> read aggregation from hashmap, and perform metric collection | ||
| MetricData metric_data; | ||
| if (metric_collection_callback(metric_data)) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private: | ||
| InstrumentDescriptor instrument_descriptor_; | ||
| AggregationType aggregation_type_; | ||
| void (*measurement_collection_callback_)(opentelemetry::metrics::ObserverResult<T> &); | ||
| const AttributesProcessor *attributes_processor_; | ||
| std::unique_ptr<AttributesHashMap> active_attributes_hashmap_; | ||
| }; | ||
|
|
||
| } // namespace metrics | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.