-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asynchronous Aggregation storage (#1232)
- Loading branch information
Showing
12 changed files
with
308 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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.
28bd621
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.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_LockFreeBuffer/1
2305895.046146922
ns/iter386929.9936445267
ns/iter5.96
BM_LockFreeBuffer/2
3603078.620998483
ns/iter1152789.59274292
ns/iter3.13
This comment was automatically generated by workflow using github-action-benchmark.
28bd621
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.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_NestedSpanCreationWithScope
2769.972714527188
ns/iter999.1151279957886
ns/iter2.77
This comment was automatically generated by workflow using github-action-benchmark.
28bd621
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.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp exporters Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_otlp_grpc_with_collector
3281692.2223126446
ns/iter1637649.807063016
ns/iter2.00
This comment was automatically generated by workflow using github-action-benchmark.