diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/sync_instruments_test.cc | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/sync_instruments_test.cc')
-rw-r--r-- | src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/sync_instruments_test.cc | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/sync_instruments_test.cc b/src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/sync_instruments_test.cc new file mode 100644 index 000000000..1a590d8d2 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/sync_instruments_test.cc @@ -0,0 +1,138 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/metrics/sync_instruments.h" +# include "opentelemetry/context/context.h" +# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" +# include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" +# include "opentelemetry/sdk/metrics/state/multi_metric_storage.h" + +# include <gtest/gtest.h> +# include <cmath> +# include <limits> + +using namespace opentelemetry; +using namespace opentelemetry::sdk::instrumentationlibrary; +using namespace opentelemetry::sdk::metrics; + +auto instrumentation_library = InstrumentationLibrary::Create("opentelemetry-cpp", "0.1.0"); + +using M = std::map<std::string, std::string>; + +TEST(SyncInstruments, LongCounter) +{ + InstrumentDescriptor instrument_descriptor = { + "long_counter", "description", "1", InstrumentType::kCounter, InstrumentValueType::kLong}; + std::unique_ptr<WritableMetricStorage> metric_storage(new MultiMetricStorage()); + LongCounter counter(instrument_descriptor, std::move(metric_storage)); + EXPECT_NO_THROW(counter.Add(10l)); + EXPECT_NO_THROW(counter.Add(10l, opentelemetry::context::Context{})); + + EXPECT_NO_THROW(counter.Add( + 10l, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}))); + EXPECT_NO_THROW(counter.Add( + 10l, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Add(10l, opentelemetry::common::KeyValueIterableView<M>({}))); + EXPECT_NO_THROW(counter.Add(10l, opentelemetry::common::KeyValueIterableView<M>({}), + opentelemetry::context::Context{})); +} + +TEST(SyncInstruments, DoubleCounter) +{ + InstrumentDescriptor instrument_descriptor = { + "double_counter", "description", "1", InstrumentType::kCounter, InstrumentValueType::kDouble}; + std::unique_ptr<WritableMetricStorage> metric_storage(new MultiMetricStorage()); + DoubleCounter counter(instrument_descriptor, std::move(metric_storage)); + EXPECT_NO_THROW(counter.Add(10.10)); + EXPECT_NO_THROW(counter.Add(10.10, opentelemetry::context::Context{})); + + EXPECT_NO_THROW(counter.Add( + 10.10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}))); + EXPECT_NO_THROW(counter.Add( + 10.10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Add(10.10, opentelemetry::common::KeyValueIterableView<M>({}))); + EXPECT_NO_THROW(counter.Add(10.10, opentelemetry::common::KeyValueIterableView<M>({}), + opentelemetry::context::Context{})); +} + +TEST(SyncInstruments, LongUpDownCounter) +{ + InstrumentDescriptor instrument_descriptor = {"long_updowncounter", "description", "1", + InstrumentType::kUpDownCounter, + InstrumentValueType::kLong}; + std::unique_ptr<WritableMetricStorage> metric_storage(new MultiMetricStorage()); + LongUpDownCounter counter(instrument_descriptor, std::move(metric_storage)); + EXPECT_NO_THROW(counter.Add(10l)); + EXPECT_NO_THROW(counter.Add(10l, opentelemetry::context::Context{})); + + EXPECT_NO_THROW(counter.Add( + 10l, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}))); + EXPECT_NO_THROW(counter.Add( + 10l, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Add(10l, opentelemetry::common::KeyValueIterableView<M>({}))); + EXPECT_NO_THROW(counter.Add(10l, opentelemetry::common::KeyValueIterableView<M>({}), + opentelemetry::context::Context{})); +} + +TEST(SyncInstruments, DoubleUpDownCounter) +{ + InstrumentDescriptor instrument_descriptor = {"double_updowncounter", "description", "1", + InstrumentType::kUpDownCounter, + InstrumentValueType::kDouble}; + std::unique_ptr<WritableMetricStorage> metric_storage(new MultiMetricStorage()); + DoubleUpDownCounter counter(instrument_descriptor, std::move(metric_storage)); + EXPECT_NO_THROW(counter.Add(10.10)); + EXPECT_NO_THROW(counter.Add(10.10, opentelemetry::context::Context{})); + + EXPECT_NO_THROW(counter.Add( + 10.10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Add( + 10.10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}))); + EXPECT_NO_THROW(counter.Add(10.10, opentelemetry::common::KeyValueIterableView<M>({}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Add(10.10, opentelemetry::common::KeyValueIterableView<M>({}))); +} + +TEST(SyncInstruments, LongHistogram) +{ + InstrumentDescriptor instrument_descriptor = { + "long_histogram", "description", "1", InstrumentType::kHistogram, InstrumentValueType::kLong}; + std::unique_ptr<WritableMetricStorage> metric_storage(new MultiMetricStorage()); + LongHistogram counter(instrument_descriptor, std::move(metric_storage)); + EXPECT_NO_THROW(counter.Record(10l, opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Record(-10l, opentelemetry::context::Context{})); // This is ignored + + EXPECT_NO_THROW(counter.Record( + 10l, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Record(10l, opentelemetry::common::KeyValueIterableView<M>({}), + opentelemetry::context::Context{})); +} + +TEST(SyncInstruments, DoubleHistogram) +{ + InstrumentDescriptor instrument_descriptor = {"double_histogram", "description", "1", + InstrumentType::kHistogram, + InstrumentValueType::kDouble}; + std::unique_ptr<WritableMetricStorage> metric_storage(new MultiMetricStorage()); + DoubleHistogram counter(instrument_descriptor, std::move(metric_storage)); + EXPECT_NO_THROW(counter.Record(10.10, opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Record(-10.10, opentelemetry::context::Context{})); // This is ignored. + EXPECT_NO_THROW(counter.Record(std::numeric_limits<double>::quiet_NaN(), + opentelemetry::context::Context{})); // This is ignored too + EXPECT_NO_THROW(counter.Record(std::numeric_limits<double>::infinity(), + opentelemetry::context::Context{})); // This is ignored too + + EXPECT_NO_THROW(counter.Record( + 10.10, opentelemetry::common::KeyValueIterableView<M>({{"abc", "123"}, {"xyz", "456"}}), + opentelemetry::context::Context{})); + EXPECT_NO_THROW(counter.Record(10.10, opentelemetry::common::KeyValueIterableView<M>({}), + opentelemetry::context::Context{})); +} + +#endif
\ No newline at end of file |