Skip to content

Commit

Permalink
[Metrics SDK] Move Metrics Exemplar processing behind feature flag (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 25, 2022
1 parent 9b8a4dc commit 419e2d6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ option(WITH_EXAMPLES "Whether to build examples" ON)
option(WITH_METRICS_PREVIEW "Whether to build metrics preview" OFF)
option(WITH_LOGS_PREVIEW "Whether to build logs preview" OFF)
option(WITH_ASYNC_EXPORT_PREVIEW "Whether enable async export" OFF)
# Exemplar specs status is experimental, so behind feature flag by default
option(WITH_METRICS_EXEMPLAR_PREVIEW
"Whethere to enable exemplar within metrics" OFF)

find_package(Threads)

Expand Down
5 changes: 5 additions & 0 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ endif()
if(WITH_ASYNC_EXPORT_PREVIEW)
target_compile_definitions(opentelemetry_api INTERFACE ENABLE_ASYNC_EXPORT)
endif()

if(WITH_METRICS_EXEMPLAR_PREVIEW)
target_compile_definitions(opentelemetry_api
INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW)
endif()
9 changes: 7 additions & 2 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mkdir -p "${BUILD_DIR}"
[ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin
mkdir -p "${PLUGIN_DIR}"

BAZEL_OPTIONS="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST"
BAZEL_OPTIONS="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST --copt=-DENABLE_METRICS_EXEMPLAR_PREVIEW"

BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"

Expand All @@ -82,7 +82,8 @@ if [[ "$1" == "cmake.test" ]]; then
-DWITH_ZIPKIN=ON \
-DWITH_JAEGER=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_PREVIEW=ON \
-DWITH_METRICS_PREVIEW=OFF \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
"${SRC_DIR}"
Expand All @@ -99,6 +100,7 @@ elif [[ "$1" == "cmake.maintainer.test" ]]; then
-DWITH_ELASTICSEARCH=ON \
-DWITH_LOGS_PREVIEW=ON \
-DWITH_METRICS_PREVIEW=OFF \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DOTELCPP_MAINTAINER_MODE=ON \
"${SRC_DIR}"
Expand All @@ -114,6 +116,7 @@ elif [[ "$1" == "cmake.with_async_export.test" ]]; then
-DWITH_JAEGER=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_PREVIEW=OFF \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand Down Expand Up @@ -142,6 +145,7 @@ elif [[ "$1" == "cmake.abseil.test" ]]; then
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_METRICS_PREVIEW=OFF \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand All @@ -166,6 +170,7 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_METRICS_PREVIEW=OFF \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
aggregation_type_{aggregation_type},
attributes_hashmap_(new AttributesHashMap()),
attributes_processor_{attributes_processor},
# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_reservoir_(exemplar_reservoir),
# endif
temporal_metric_storage_(instrument_descriptor, aggregation_config)

{
Expand All @@ -52,7 +54,9 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
{
return;
}
# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_reservoir_->OfferMeasurement(value, {}, context, std::chrono::system_clock::now());
# endif
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
attributes_hashmap_->GetOrSetDefault({}, create_default_aggregation_)->Aggregate(value);
}
Expand All @@ -65,9 +69,10 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
{
return;
}

# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_reservoir_->OfferMeasurement(value, attributes, context,
std::chrono::system_clock::now());
# endif
auto attr = attributes_processor_->process(attributes);
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
attributes_hashmap_->GetOrSetDefault(attr, create_default_aggregation_)->Aggregate(value);
Expand All @@ -79,7 +84,9 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
{
return;
}
# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_reservoir_->OfferMeasurement(value, {}, context, std::chrono::system_clock::now());
# endif
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
attributes_hashmap_->GetOrSetDefault({}, create_default_aggregation_)->Aggregate(value);
}
Expand All @@ -88,14 +95,18 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::context::Context &context) noexcept override
{
# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_reservoir_->OfferMeasurement(value, attributes, context,
std::chrono::system_clock::now());
# endif
if (instrument_descriptor_.value_type_ != InstrumentValueType::kDouble)
{
return;
}
# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
exemplar_reservoir_->OfferMeasurement(value, attributes, context,
std::chrono::system_clock::now());
# endif
auto attr = attributes_processor_->process(attributes);
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
attributes_hashmap_->GetOrSetDefault(attr, create_default_aggregation_)->Aggregate(value);
Expand All @@ -120,7 +131,9 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
std::unordered_map<CollectorHandle *, LastReportedMetrics> last_reported_metrics_;
const AttributesProcessor *attributes_processor_;
std::function<std::unique_ptr<Aggregation>()> create_default_aggregation_;
# ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
nostd::shared_ptr<ExemplarReservoir> exemplar_reservoir_;
# endif
TemporalMetricStorage temporal_metric_storage_;
opentelemetry::common::SpinLockMutex attribute_hashmap_lock_;
};
Expand Down

0 comments on commit 419e2d6

Please sign in to comment.