Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f3c38a3
Implementing configurable aggregation cardinality limit and collector…
PradSenn Mar 12, 2025
0d80b39
Fixing initialization order issue
PradSenn Mar 12, 2025
491ef3c
Merge branch 'main' into main
PradSenn Mar 12, 2025
671e4ca
Fixing integer size mismatch error
PradSenn Mar 14, 2025
203fd46
Merge branch 'main' into main
lalitb Mar 24, 2025
3af667c
Merge branch 'main' into main
ThomsonTan Apr 1, 2025
277f5ee
Merge branch 'main' into PradSenn/main
ThomsonTan Sep 3, 2025
db29ab1
Resolve conflict in meter.cc
ThomsonTan Sep 3, 2025
14aa407
Fix View constructor
ThomsonTan Sep 4, 2025
5f153a2
Fix format
ThomsonTan Sep 4, 2025
b446e6f
Fix iwyu
ThomsonTan Sep 4, 2025
9b34954
Fix more iwyu
ThomsonTan Sep 4, 2025
5186013
More fix on iywu
ThomsonTan Sep 4, 2025
969ad85
More iwyu
ThomsonTan Sep 4, 2025
8a5b7a1
More fix on iwyu
ThomsonTan Sep 4, 2025
34f1d13
Merge branch 'main' into add_cadinality_limit
ThomsonTan Sep 4, 2025
6c91fbb
More iwyu fix
ThomsonTan Sep 4, 2025
2c9305c
Remove extra empty line
ThomsonTan Sep 4, 2025
100959c
More iwyu fix
ThomsonTan Sep 4, 2025
f6719f2
One more iwyu
ThomsonTan Sep 4, 2025
d0c4b95
Increase test timeout for valgrind
ThomsonTan Sep 4, 2025
d4aaf6a
Update changelog
ThomsonTan Sep 4, 2025
c7b4a64
Merge branch 'main' into add_cadinality_limit
ThomsonTan Sep 5, 2025
f3ea8f0
Address feedback
ThomsonTan Sep 5, 2025
d8d4fdd
Format code
ThomsonTan Sep 5, 2025
fcebda2
Merge branch 'main' into add_cadinality_limit
ThomsonTan Sep 8, 2025
121d6c6
Address feedback
ThomsonTan Sep 8, 2025
9c6fb5e
Address more feedback
ThomsonTan Sep 9, 2025
f81f8bd
Remove static inline which is C++ 17
ThomsonTan Sep 9, 2025
93b9914
Reformat
ThomsonTan Sep 9, 2025
274614c
Merge branch 'main' into add_cadinality_limit
ThomsonTan Sep 10, 2025
7dde674
Move GetOrDefault to AggregationConfig
ThomsonTan Sep 10, 2025
dc5661c
Address feedback
ThomsonTan Sep 10, 2025
df2c451
Run format
ThomsonTan Sep 10, 2025
49eac75
Revert "Run format"
ThomsonTan Sep 11, 2025
02fc44e
Revert "Address feedback"
ThomsonTan Sep 11, 2025
e29dc0f
Merge branch 'main' into add_cadinality_limit
lalitb Sep 11, 2025
a42ae43
Address feedback
ThomsonTan Sep 11, 2025
24ed437
Merge branch 'main' into add_cadinality_limit
marcalff Sep 11, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Increment the:
* [BUILD] Use -dev versions in main branch
[#3609](https://github.com/open-telemetry/opentelemetry-cpp/pull/3609)

* [SDK] Implementing configurable aggregation cardinality limit and collector
emitting all views instead of last view
[#3624](https://github.com/open-telemetry/opentelemetry-cpp/pull/3624)

Important changes:

* [CMAKE] Upgrade CMake minimum version to 3.16
Expand Down
2 changes: 1 addition & 1 deletion ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ elif [[ "$1" == "bazel.tsan" ]]; then
exit 0
elif [[ "$1" == "bazel.valgrind" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC //...
bazel $BAZEL_STARTUP_OPTIONS test --run_under="/usr/bin/valgrind --leak-check=full --error-exitcode=1 --errors-for-leak-kinds=definite --suppressions=\"${SRC_DIR}/ci/valgrind-suppressions\"" $BAZEL_TEST_OPTIONS_ASYNC //...
bazel $BAZEL_STARTUP_OPTIONS test --test_timeout=600 --run_under="/usr/bin/valgrind --leak-check=full --error-exitcode=1 --errors-for-leak-kinds=definite --suppressions=\"${SRC_DIR}/ci/valgrind-suppressions\"" $BAZEL_TEST_OPTIONS_ASYNC //...
exit 0
elif [[ "$1" == "bazel.e2e" ]]; then
cd examples/e2e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <vector>

#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
Expand All @@ -15,6 +16,10 @@ namespace metrics
class AggregationConfig
{
public:
AggregationConfig(size_t cardinality_limit = kAggregationCardinalityLimit)
: cardinality_limit_(cardinality_limit)
{}
size_t cardinality_limit_;
virtual ~AggregationConfig() = default;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
const AggregationConfig *aggregation_config)
: instrument_descriptor_(instrument_descriptor),
aggregation_type_{aggregation_type},
cumulative_hash_map_(new AttributesHashMap()),
delta_hash_map_(new AttributesHashMap()),
aggregation_config_{aggregation_config},
cumulative_hash_map_(new AttributesHashMap(aggregation_config
? aggregation_config->cardinality_limit_
: kAggregationCardinalityLimit)),
delta_hash_map_(new AttributesHashMap(aggregation_config
? aggregation_config->cardinality_limit_
: kAggregationCardinalityLimit)),
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_filter_type_(exempler_filter_type),
exemplar_reservoir_(exemplar_reservoir),
Expand Down Expand Up @@ -124,7 +129,9 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(hashmap_lock_);
delta_metrics = std::move(delta_hash_map_);
delta_hash_map_.reset(new AttributesHashMap);
delta_hash_map_.reset(new AttributesHashMap(aggregation_config_
? aggregation_config_->cardinality_limit_
: kAggregationCardinalityLimit));
}

auto status =
Expand All @@ -136,6 +143,7 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
private:
InstrumentDescriptor instrument_descriptor_;
AggregationType aggregation_type_;
const AggregationConfig *aggregation_config_;
std::unique_ptr<AttributesHashMap> cumulative_hash_map_;
std::unique_ptr<AttributesHashMap> delta_hash_map_;
opentelemetry::common::SpinLockMutex hashmap_lock_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ class AttributesHashMapWithCustomHash
public:
AttributesHashMapWithCustomHash(size_t attributes_limit = kAggregationCardinalityLimit)
: attributes_limit_(attributes_limit)
{}
{
if (attributes_limit_ > kAggregationCardinalityLimit)
{
hash_map_.reserve(attributes_limit_);
}
}

Aggregation *Get(const MetricAttributes &attributes) const
{
auto it = hash_map_.find(attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
ExemplarFilterType exempler_filter_type,
nostd::shared_ptr<ExemplarReservoir> &&exemplar_reservoir,
#endif
const AggregationConfig *aggregation_config,
size_t attributes_limit = kAggregationCardinalityLimit)
const AggregationConfig *aggregation_config)
: instrument_descriptor_(instrument_descriptor),
attributes_hashmap_(new AttributesHashMap(attributes_limit)),
aggregation_config_(aggregation_config),
attributes_hashmap_(new AttributesHashMap(aggregation_config
? aggregation_config->cardinality_limit_
: kAggregationCardinalityLimit)),
attributes_processor_(std::move(attributes_processor)),
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_filter_type_(exempler_filter_type),
Expand Down Expand Up @@ -173,6 +175,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
private:
InstrumentDescriptor instrument_descriptor_;
// hashmap to maintain the metrics for delta collection (i.e, collection since last Collect call)
const AggregationConfig *aggregation_config_;
std::unique_ptr<AttributesHashMap> attributes_hashmap_;
std::function<std::unique_ptr<Aggregation>()> create_default_aggregation_;
std::shared_ptr<const AttributesProcessor> attributes_processor_;
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/metrics/state/sync_metric_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h"
#include "opentelemetry/sdk/metrics/state/metric_collector.h"
Expand All @@ -35,7 +36,9 @@ bool SyncMetricStorage::Collect(CollectorHandle *collector,
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
delta_metrics = std::move(attributes_hashmap_);
attributes_hashmap_.reset(new AttributesHashMap);
attributes_hashmap_.reset(new AttributesHashMap(aggregation_config_
? aggregation_config_->cardinality_limit_
: kAggregationCardinalityLimit));
}

return temporal_metric_storage_.buildMetrics(collector, collectors, sdk_start_ts, collection_ts,
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/metrics/state/temporal_metric_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector,
}
auto unreported_list = std::move(present->second);
// Iterate over the unreporter metrics for `collector` and store result in `merged_metrics`
std::unique_ptr<AttributesHashMap> merged_metrics(new AttributesHashMap);
std::unique_ptr<AttributesHashMap> merged_metrics(
new AttributesHashMap(aggregation_config_ ? aggregation_config_->cardinality_limit_
: kAggregationCardinalityLimit));
for (auto &agg_hashmap : unreported_list)
{
agg_hashmap->GetAllEnteries(
Expand Down
10 changes: 7 additions & 3 deletions sdk/test/metrics/async_metric_storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h"
#include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h"
#include "opentelemetry/sdk/metrics/state/metric_collector.h"
#include "opentelemetry/sdk/metrics/view/attributes_processor.h"

#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
# include "opentelemetry/sdk/metrics/data/exemplar_data.h"
# include "opentelemetry/sdk/metrics/exemplar/filter_type.h"
# include "opentelemetry/sdk/metrics/exemplar/reservoir.h"
#else
# include "opentelemetry/sdk/metrics/view/attributes_processor.h"
#endif

using namespace opentelemetry::sdk::metrics;
Expand Down Expand Up @@ -192,8 +194,10 @@ TEST_P(WritableMetricStorageTestUpDownFixture, TestAggregation)
}
return true;
});
// subsequent recording after collection shouldn't fail
// monotonic increasing values;
// Note: When the cardinality limit is set to n, the attributes hashmap emits n-1 distinct
// attribute sets, plus an overflow bucket for additional attributes. The test logic below is made
// generic to succeed for either n or n-1 total cardinality. If this behavior is unexpected,
// please investigate and file an issue.
Copy link
Member

Choose a reason for hiding this comment

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

Per the spec, the overflow bucket is included in the cardinality limit, not added on top of it. We can remove this comment, or update accordingly.

int64_t get_count2 = -50;
int64_t put_count2 = -70;

Expand Down
4 changes: 3 additions & 1 deletion sdk/test/metrics/cardinality_limit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/sdk/metrics/aggregation/aggregation.h"
#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
#include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/data/point_data.h"
Expand Down Expand Up @@ -110,14 +111,15 @@ TEST_P(WritableMetricStorageCardinalityLimitTestFixture, LongCounterSumAggregati
const size_t attributes_limit = 10;
InstrumentDescriptor instr_desc = {"name", "desc", "1unit", InstrumentType::kCounter,
InstrumentValueType::kLong};
AggregationConfig aggConfig(attributes_limit);
std::shared_ptr<DefaultAttributesProcessor> default_attributes_processor{
new DefaultAttributesProcessor{}};
SyncMetricStorage storage(instr_desc, AggregationType::kSum, default_attributes_processor,
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
ExemplarFilterType::kAlwaysOff,
ExemplarReservoir::GetNoExemplarReservoir(),
#endif
nullptr, attributes_limit);
&aggConfig);

int64_t record_value = 100;
// add 9 unique metric points, and 6 more above limit.
Expand Down
Loading
Loading