From a0af8c52b586b7264ea0d3de80d432441f0a8d2f Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:37:13 -0400 Subject: [PATCH 01/52] Create meter.h --- api/include/opentelemetry/metrics/meter.h | 258 ++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 api/include/opentelemetry/metrics/meter.h diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h new file mode 100644 index 0000000000..eeca1c7882 --- /dev/null +++ b/api/include/opentelemetry/metrics/meter.h @@ -0,0 +1,258 @@ +#pragma once + +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/key_value_iterable_view.h" +#include "opentelemetry/version.h" + +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/sync_instruments.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace meter +{ +/** + * Handles instrument creation and provides a facility for batch recording. + * + * This class provides methods to create new metric instruments, record a + * batch of values to a specified set of instruments, and collect + * measurements from all instruments. + * + */ +class Meter +{ +public: + virtual ~Meter() = default; + + /** + * Creates, adds to private metrics container, and returns a DoubleCounter with "name." + * + * @param name the name of the new DoubleCounter. + * @param description a brief description of what the DoubleCounter is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleCounter. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns an IntCounter with "name." + * + * @param name the name of the new IntCounter. + * @param description a brief description of what the IntCounter is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created IntCounter. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns a DoubleUpDownCounter with "name." + * + * @param name the name of the new DoubleUpDownCounter. + * @param description a brief description of what the DoubleUpDownCounter is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleUpDownCounter. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns an IntUpDownCounter with "name." + * + * @param name the name of the new IntUpDownCounter. + * @param description a brief description of what the IntUpDownCounter is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created IntUpDownCounter. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns a DoubleValueRecorder with "name." + * + * @param name the name of the new DoubleValueRecorder. + * @param description a brief description of what the DoubleValueRecorder is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleValueRecorder. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns an IntValueRecorder with "name." + * + * @param name the name of the new IntValueRecorder. + * @param description a brief description of what the IntValueRecorder is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created IntValueRecorder. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + bool enabled); + + /** + * Creates, adds to private metrics container, and returns a DoubleSumObserver with "name." + * + * @param name the name of the new DoubleSumObserver. + * @param description a brief description of what the DoubleSumObserver is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleSumObserver. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewDoubleSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns an IntSumObserver with "name." + * + * @param name the name of the new IntSumObserver. + * @param description a brief description of what the IntSumObserver is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleCounter. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns a DoubleUpDownSumObserver with "name." + * + * @param name the name of the new DoubleUpDownSumObserver. + * @param description a brief description of what the DoubleUpDownSumObserver is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleUpDownSumObserver. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr + NewDoubleUpDownSumObserver(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns an IntUpDownSumObserver with "name." + * + * @param name the name of the new IntUpDownSumObserver. + * @param description a brief description of what the IntUpDownSumObserver is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created IntUpDownSumObserver. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns a DoubleValueObserver with "name." + * + * @param name the name of the new DoubleValueObserver. + * @param description a brief description of what the DoubleValueObserver is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created DoubleValueObserver. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + + /** + * Creates, adds to private metrics container, and returns an IntValueObserver with "name." + * + * @param name the name of the new IntValueObserver. + * @param description a brief description of what the IntValueObserver is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a unique pointer to the created IntValueObserver. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual opentelemetry::nostd::unique_ptr NewIntValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled); + +private: + /** + * Utility method that allows users to atomically record measurements to a set of + * Metric instruments with a common set of labels. + * + * @param labels The set of labels to associate with this recorder. + * @param values A KeyValueIterable where the key is a string containing the name + * of metric instruments such as "IntCounter" or "DoubleUpDownSumObserver" + * and the value is the value to be recorded to all metric instruments in + * the batch of the associated instrument type. + */ + virtual void RecordBatch(nostd::string_view labels, + const trace::KeyValueIterable &values) noexcept; +}; +} // namespace meter +OPENTELEMETRY_END_NAMESPACE From f4921e43d4a6c634d3edea148fe1944cf595f3ac Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:37:55 -0400 Subject: [PATCH 02/52] Create noop.h --- api/include/opentelemetry/metrics/noop.h | 134 +++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 api/include/opentelemetry/metrics/noop.h diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h new file mode 100644 index 0000000000..f2c42c5a76 --- /dev/null +++ b/api/include/opentelemetry/metrics/noop.h @@ -0,0 +1,134 @@ +#pragma once + +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/key_value_iterable_view.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace meter +{ +/** + * No-op implementation of Meter. This class should not be used directly. + */ +class NoopMeter : public meter::Meter +{ +public: + NoopMeter() = default; + + opentelemetry::nostd::unique_ptr NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopDoubleCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::unique_ptr NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopIntCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopDoubleUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::unique_ptr NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopIntUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::unique_ptr NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopDoubleValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::unique_ptr NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopIntValueRecorder(name, description, unit, enabled)}; + } + + /* + opentelemetry::nostd::unique_ptr NewDoubleSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{new NoopDoubleSumObserver(name, + description, unit, enabled)}; + } + opentelemetry::nostd::unique_ptr NewIntSumObserver(nostd::string_view + name, nostd::string_view description, nostd::string_view unit, const bool enabled) override + { + return nostd::unique_ptr{new NoopIntSumObserver(name, description, + unit, enabled)}; + } + opentelemetry::nostd::unique_ptr NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopDoubleUpDownSumObserver(name, description, unit, enabled)}; + } + opentelemetry::nostd::unique_ptr NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{ + new NoopIntUpDownSumObserver(name, description, unit, enabled)}; + } + opentelemetry::nostd::unique_ptr NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::unique_ptr{new NoopDoubleValueObserver(name, + description, unit, enabled)}; + } + */ + +private: + void RecordBatch(nostd::string_view labels, + const trace::KeyValueIterable &values) noexcept override + { + // No-op + } + +}; + +} // namespace meter +OPENTELEMETRY_END_NAMESPACE From f71aafef56276100d4bc3dbd0b5e59bcd0ede807 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:38:23 -0400 Subject: [PATCH 03/52] Create key_value_iterable.h --- .../metrics/key_value_iterable.h | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 api/include/opentelemetry/metrics/key_value_iterable.h diff --git a/api/include/opentelemetry/metrics/key_value_iterable.h b/api/include/opentelemetry/metrics/key_value_iterable.h new file mode 100644 index 0000000000..8b1f2e1124 --- /dev/null +++ b/api/include/opentelemetry/metrics/key_value_iterable.h @@ -0,0 +1,34 @@ +#pragma once + +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/nostd/function_ref.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +/** + * Supports internal iteration over a collection of key-value pairs. + */ +class KeyValueIterable +{ +public: + virtual ~KeyValueIterable() = default; + + /** + * Iterate over key-value pairs + * @param callback a callback to invoke for each key-value. If the callback returns false, + * the iteration is aborted. + * @return true if every key-value pair was iterated over + */ + virtual bool ForEachKeyValue( + nostd::function_ref callback) const + noexcept = 0; + + /** + * @return the number of key-value pairs + */ + virtual size_t size() const noexcept = 0; +}; +} // namespace trace +OPENTELEMETRY_END_NAMESPACE From e36cc8e9d69d3ae9dbbc1f498030cd63938717e3 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:38:42 -0400 Subject: [PATCH 04/52] Create key_value_iterable_view.h --- .../metrics/key_value_iterable_view.h | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 api/include/opentelemetry/metrics/key_value_iterable_view.h diff --git a/api/include/opentelemetry/metrics/key_value_iterable_view.h b/api/include/opentelemetry/metrics/key_value_iterable_view.h new file mode 100644 index 0000000000..2daf83c713 --- /dev/null +++ b/api/include/opentelemetry/metrics/key_value_iterable_view.h @@ -0,0 +1,64 @@ +#pragma once + +#include +#include +#include + +#include "opentelemetry/nostd/utility.h" +#include "opentelemetry/trace/key_value_iterable.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace trace +{ +namespace detail +{ +inline void take_key_value(nostd::string_view, common::AttributeValue) {} + +template +auto is_key_value_iterable_impl(T iterable) + -> decltype(take_key_value(std::begin(iterable)->first, std::begin(iterable)->second), + nostd::size(iterable), + std::true_type{}); + +std::false_type is_key_value_iterable_impl(...); + +template +struct is_key_value_iterable +{ + static const bool value = decltype(detail::is_key_value_iterable_impl(std::declval()))::value; +}; +} // namespace detail + +template +class KeyValueIterableView final : public KeyValueIterable +{ + static_assert(detail::is_key_value_iterable::value, "Must be a key-value iterable"); + +public: + explicit KeyValueIterableView(const T &container) noexcept : container_{&container} {} + + // KeyValueIterable + bool ForEachKeyValue( + nostd::function_ref callback) const + noexcept override + { + auto iter = std::begin(*container_); + auto last = std::end(*container_); + for (; iter != last; ++iter) + { + if (!callback(iter->first, iter->second)) + { + return false; + } + } + return true; + } + + size_t size() const noexcept override { return nostd::size(*container_); } + +private: + const T *container_; +}; +} // namespace trace +OPENTELEMETRY_END_NAMESPACE From a41e0f99c608eaacb9ceb32078850c645db510a3 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:39:14 -0400 Subject: [PATCH 05/52] Create noop_test_metrics.cc --- api/test/metrics/noop_test_metrics.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 api/test/metrics/noop_test_metrics.cc diff --git a/api/test/metrics/noop_test_metrics.cc b/api/test/metrics/noop_test_metrics.cc new file mode 100644 index 0000000000..aef39d17c6 --- /dev/null +++ b/api/test/metrics/noop_test_metrics.cc @@ -0,0 +1,25 @@ +#include "opentelemetry/metrics/noop.h" + +#include +#include +#include + +#include + +using opentelemetry::meter::NoopMeter; +using opentelemetry::meter::Meter; + +TEST(NoopTest, UseNoopMeters) +{ + std::unique_ptr m{new NoopMeter{}}; + + auto intCounter = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); + + std::map batchValues1; + m->RecordBatch("", batchValues1); + + std::vector> batchValues2; + m->RecordBatch("", batchValues2); + + m->RecordBatch("", {{"IntCounter", 1}, {opentelemetry::metrics::InstrumentKind::Counter, 1.0}}); +} From 03d484154e3e2390148efb5da4898a41e3600e6f Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:39:31 -0400 Subject: [PATCH 06/52] Create CMakeLists.txt --- api/test/metrics/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 api/test/metrics/CMakeLists.txt diff --git a/api/test/metrics/CMakeLists.txt b/api/test/metrics/CMakeLists.txt new file mode 100644 index 0000000000..66cae04518 --- /dev/null +++ b/api/test/metrics/CMakeLists.txt @@ -0,0 +1,6 @@ +foreach(testname noop_test_metrics) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests(TARGET ${testname} TEST_PREFIX trace. TEST_LIST ${testname}) +endforeach() From 00f04b72e320d61aadc6d221a3427334df0d8df1 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 10:39:44 -0400 Subject: [PATCH 07/52] Create BUILD --- api/test/metrics/BUILD | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 api/test/metrics/BUILD diff --git a/api/test/metrics/BUILD b/api/test/metrics/BUILD new file mode 100644 index 0000000000..d3ae07708b --- /dev/null +++ b/api/test/metrics/BUILD @@ -0,0 +1,10 @@ +cc_test( + name = "noop_test_metrics", + srcs = [ + "noop_test_metrics.cc", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) From ba62dec6dff9d2067a0d950e7d670e16369b3249 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 1 Jul 2020 11:26:22 -0400 Subject: [PATCH 08/52] Make function RecordBatch public --- api/include/opentelemetry/metrics/meter.h | 1 - 1 file changed, 1 deletion(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index eeca1c7882..979d388083 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -240,7 +240,6 @@ class Meter nostd::string_view unit, const bool enabled); -private: /** * Utility method that allows users to atomically record measurements to a set of * Metric instruments with a common set of labels. From a7638b5bfcc8f0f5a75e1e07446f76f78e577eb0 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 2 Jul 2020 11:17:34 -0400 Subject: [PATCH 09/52] Add callback to async functions --- api/include/opentelemetry/metrics/meter.h | 99 ++++++++++++++++++----- 1 file changed, 78 insertions(+), 21 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 979d388083..18195e9406 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -6,10 +6,11 @@ #include "opentelemetry/version.h" #include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/instrument.h" #include "opentelemetry/metrics/sync_instruments.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace meter +namespace metrics { /** * Handles instrument creation and provides a facility for batch recording. @@ -36,11 +37,15 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleCounter( + virtual opentelemetry::nostd::unique_ptr NewDoubleCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled) + { + return opentelemetry::nostd::unique_ptr{ + new DoubleCounter(name, description, unit, enabled)}; + } /** * Creates, adds to private metrics container, and returns an IntCounter with "name." @@ -54,11 +59,14 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled); + virtual opentelemetry::nostd::unique_ptr NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) + { + return opentelemetry::nostd::unique_ptr{ + new IntCounter(name, description, unit, enabled)}; + } /** * Creates, adds to private metrics container, and returns a DoubleUpDownCounter with "name." @@ -72,11 +80,15 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( + virtual opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled) + { + return opentelemetry::nostd::unique_ptr{ + new DoubleUpDownCounter(name, description, unit, enabled)}; + } /** * Creates, adds to private metrics container, and returns an IntUpDownCounter with "name." @@ -94,7 +106,11 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled) + { + return opentelemetry::nostd::unique_ptr{ + new IntUpDownCounter(name, description, unit, enabled)}; + } /** * Creates, adds to private metrics container, and returns a DoubleValueRecorder with "name." @@ -112,7 +128,11 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled) + { + return opentelemetry::nostd::unique_ptr{ + new DoubleValueRecorder(name, description, unit, enabled)}; + } /** * Creates, adds to private metrics container, and returns an IntValueRecorder with "name." @@ -130,7 +150,11 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - bool enabled); + bool enabled) + { + return opentelemetry::nostd::unique_ptr{ + new IntValueRecorder(name, description, unit, enabled)}; + } /** * Creates, adds to private metrics container, and returns a DoubleSumObserver with "name." @@ -148,7 +172,12 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled, + void (*callback)(DoubleObserverResult)) + { + return opentelemetry::nostd::unique_ptr{ + new DoubleSumObserver(name, description, unit, enabled, callback)}; + } /** * Creates, adds to private metrics container, and returns an IntSumObserver with "name." @@ -166,7 +195,12 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled, + void (*callback)(IntObserverResult)) + { + return opentelemetry::nostd::unique_ptr{ + new IntSumObserver(name, description, unit, enabled, callback)}; + } /** * Creates, adds to private metrics container, and returns a DoubleUpDownSumObserver with "name." @@ -184,7 +218,12 @@ class Meter NewDoubleUpDownSumObserver(nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled, + void (*callback)(DoubleObserverResult)) + { + return opentelemetry::nostd::unique_ptr{ + new DoubleUpDownSumObserver(name, description, unit, enabled, callback)}; + } /** * Creates, adds to private metrics container, and returns an IntUpDownSumObserver with "name." @@ -202,7 +241,12 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled, + void (*callback)(IntObserverResult)) + { + return opentelemetry::nostd::unique_ptr{ + new IntUpDownSumObserver(name, description, unit, enabled, callback)}; + } /** * Creates, adds to private metrics container, and returns a DoubleValueObserver with "name." @@ -220,7 +264,12 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled, + void (*callback)(DoubleObserverResult)) + { + return opentelemetry::nostd::unique_ptr{ + new DoubleValueObserver(name, description, unit, enabled, callback)}; + } /** * Creates, adds to private metrics container, and returns an IntValueObserver with "name." @@ -238,7 +287,12 @@ class Meter nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled); + const bool enabled, + void (*callback)(IntObserverResult)) + { + return opentelemetry::nostd::unique_ptr{ + new IntValueObserver(name, description, unit, enabled, callback)}; + } /** * Utility method that allows users to atomically record measurements to a set of @@ -251,7 +305,10 @@ class Meter * the batch of the associated instrument type. */ virtual void RecordBatch(nostd::string_view labels, - const trace::KeyValueIterable &values) noexcept; + const trace::KeyValueIterable &values) noexcept + { + // No-op + } }; -} // namespace meter +} // namespace metrics OPENTELEMETRY_END_NAMESPACE From 22a9f3a298de32de73cd0bfc442f037dc2661338 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 2 Jul 2020 11:19:06 -0400 Subject: [PATCH 10/52] Remove comments and add callback to async functions --- api/include/opentelemetry/metrics/noop.h | 105 ++++++++++++----------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index f2c42c5a76..40052869b8 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -6,129 +6,134 @@ #include "opentelemetry/trace/key_value_iterable_view.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace meter +namespace metrics { /** * No-op implementation of Meter. This class should not be used directly. */ -class NoopMeter : public meter::Meter +class NoopMeter : public Meter { public: NoopMeter() = default; - opentelemetry::nostd::unique_ptr NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::unique_ptr NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::unique_ptr{ + return nostd::unique_ptr{ new NoopDoubleCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::unique_ptr NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::unique_ptr{ - new NoopIntCounter(name, description, unit, enabled)}; + return nostd::unique_ptr{new NoopIntCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( + opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::unique_ptr{ new NoopDoubleUpDownCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewIntUpDownCounter( + opentelemetry::nostd::unique_ptr NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::unique_ptr{ new NoopIntUpDownCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewDoubleValueRecorder( + opentelemetry::nostd::unique_ptr NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::unique_ptr{ new NoopDoubleValueRecorder(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewIntValueRecorder( + opentelemetry::nostd::unique_ptr NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::unique_ptr{ new NoopIntValueRecorder(name, description, unit, enabled)}; } - /* - opentelemetry::nostd::unique_ptr NewDoubleSumObserver( + opentelemetry::nostd::unique_ptr NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override + const bool enabled, + void (*callback)(DoubleObserverResult)) override { - return nostd::unique_ptr{new NoopDoubleSumObserver(name, - description, unit, enabled)}; + return nostd::unique_ptr{ + new NoopDoubleSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewIntSumObserver(nostd::string_view - name, nostd::string_view description, nostd::string_view unit, const bool enabled) override + + opentelemetry::nostd::unique_ptr NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(IntObserverResult)) override { - return nostd::unique_ptr{new NoopIntSumObserver(name, description, - unit, enabled)}; + return nostd::unique_ptr{ + new NoopIntSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewDoubleUpDownSumObserver( + + opentelemetry::nostd::unique_ptr NewDoubleUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override + const bool enabled, + void (*callback)(DoubleObserverResult)) override { - return nostd::unique_ptr{ - new NoopDoubleUpDownSumObserver(name, description, unit, enabled)}; + return nostd::unique_ptr{ + new NoopDoubleUpDownSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewIntUpDownSumObserver( + + opentelemetry::nostd::unique_ptr NewIntUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override + const bool enabled, + void (*callback)(IntObserverResult)) override { - return nostd::unique_ptr{ - new NoopIntUpDownSumObserver(name, description, unit, enabled)}; + return nostd::unique_ptr{ + new NoopIntUpDownSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewDoubleValueObserver( + + opentelemetry::nostd::unique_ptr NewDoubleValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override + const bool enabled, + void (*callback)(DoubleObserverResult)) override { - return nostd::unique_ptr{new NoopDoubleValueObserver(name, - description, unit, enabled)}; + return nostd::unique_ptr{ + new NoopDoubleValueObserver(name, description, unit, enabled, callback)}; } - */ -private: - void RecordBatch(nostd::string_view labels, - const trace::KeyValueIterable &values) noexcept override + void RecordBatch(nostd::string_view /*labels*/, + const trace::KeyValueIterable & /*values*/) noexcept override { // No-op } - }; -} // namespace meter +} // namespace metrics OPENTELEMETRY_END_NAMESPACE From 39332ffabfcd5ae32d20cd9ad540b43aa8bfe3b1 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 2 Jul 2020 11:20:16 -0400 Subject: [PATCH 11/52] Pass KeyValueIterable view not direct data struct --- api/test/metrics/noop_test_metrics.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/api/test/metrics/noop_test_metrics.cc b/api/test/metrics/noop_test_metrics.cc index aef39d17c6..90ed33209a 100644 --- a/api/test/metrics/noop_test_metrics.cc +++ b/api/test/metrics/noop_test_metrics.cc @@ -2,24 +2,26 @@ #include #include -#include #include -using opentelemetry::meter::NoopMeter; -using opentelemetry::meter::Meter; +using opentelemetry::metrics::NoopMeter; +using opentelemetry::metrics::Meter; TEST(NoopTest, UseNoopMeters) { std::unique_ptr m{new NoopMeter{}}; - auto intCounter = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); + m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - std::map batchValues1; - m->RecordBatch("", batchValues1); + using MAP = std::map; + MAP batchValues1 = {{}}; + opentelemetry::trace::KeyValueIterableView view{batchValues1}; + m->RecordBatch("abc", view); - std::vector> batchValues2; - m->RecordBatch("", batchValues2); + using VEC = std::vector>; + VEC batchValues2 = {}; + opentelemetry::trace::KeyValueIterableView view2{batchValues2}; + m->RecordBatch("abc", view2); - m->RecordBatch("", {{"IntCounter", 1}, {opentelemetry::metrics::InstrumentKind::Counter, 1.0}}); } From c4e8d748faa56c20a2944665828e88893325ba9a Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 14:58:48 -0400 Subject: [PATCH 12/52] Changed unique_ptr to shared_ptr And change type to A/SynchronousInstrument --- api/include/opentelemetry/metrics/noop.h | 55 ++++++++++-------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 40052869b8..7bb6e40404 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -1,13 +1,3 @@ -#pragma once - -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" -#include "opentelemetry/trace/key_value_iterable_view.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics -{ /** * No-op implementation of Meter. This class should not be used directly. */ @@ -16,115 +6,115 @@ class NoopMeter : public Meter public: NoopMeter() = default; - opentelemetry::nostd::unique_ptr NewDoubleCounter(nostd::string_view name, + opentelemetry::nostd::shared_ptr NewDoubleCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopDoubleCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewIntCounter(nostd::string_view name, + opentelemetry::nostd::shared_ptr NewIntCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{new NoopIntCounter(name, description, unit, enabled)}; + return nostd::shared_ptr{new NoopIntCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( + opentelemetry::nostd::shared_ptr NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopDoubleUpDownCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewIntUpDownCounter( + opentelemetry::nostd::shared_ptr NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopIntUpDownCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewDoubleValueRecorder( + opentelemetry::nostd::shared_ptr NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopDoubleValueRecorder(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewIntValueRecorder( + opentelemetry::nostd::shared_ptr NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopIntValueRecorder(name, description, unit, enabled)}; } - opentelemetry::nostd::unique_ptr NewDoubleSumObserver( + opentelemetry::nostd::shared_ptr NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(DoubleObserverResult)) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopDoubleSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewIntSumObserver( + opentelemetry::nostd::shared_ptr NewIntSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(IntObserverResult)) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopIntSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewDoubleUpDownSumObserver( + opentelemetry::nostd::shared_ptr NewDoubleUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(DoubleObserverResult)) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopDoubleUpDownSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewIntUpDownSumObserver( + opentelemetry::nostd::shared_ptr NewIntUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(IntObserverResult)) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopIntUpDownSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::unique_ptr NewDoubleValueObserver( + opentelemetry::nostd::shared_ptr NewDoubleValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(DoubleObserverResult)) override { - return nostd::unique_ptr{ + return nostd::shared_ptr{ new NoopDoubleValueObserver(name, description, unit, enabled, callback)}; } @@ -134,6 +124,5 @@ class NoopMeter : public Meter // No-op } }; - } // namespace metrics OPENTELEMETRY_END_NAMESPACE From faa9b1a430d9d37c5d41894599e009de66c89f45 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 14:59:48 -0400 Subject: [PATCH 13/52] Change unique_ptr to shared_ptr And change ptr type to A/SynchronousInstrument --- api/include/opentelemetry/metrics/meter.h | 82 +++++++++++++---------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 18195e9406..31fcedd750 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -1,7 +1,7 @@ #pragma once #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/trace/key_value_iterable_view.h" #include "opentelemetry/version.h" @@ -25,6 +25,14 @@ class Meter public: virtual ~Meter() = default; + ////////////////////////////// + // // + // Change pointer type to // + // SynchronousInstrument or // + // AsynchronousInstrument? // + // // + ////////////////////////////// + /** * Creates, adds to private metrics container, and returns a DoubleCounter with "name." * @@ -32,18 +40,18 @@ class Meter * @param description a brief description of what the DoubleCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleCounter. + * @return a shared pointer to the created DoubleCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleCounter( + virtual opentelemetry::nostd::shared_ptr NewDoubleCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new DoubleCounter(name, description, unit, enabled)}; } @@ -54,17 +62,17 @@ class Meter * @param description a brief description of what the IntCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created IntCounter. + * @return a shared pointer to the created IntCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntCounter(nostd::string_view name, + virtual opentelemetry::nostd::shared_ptr NewIntCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new IntCounter(name, description, unit, enabled)}; } @@ -75,18 +83,18 @@ class Meter * @param description a brief description of what the DoubleUpDownCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleUpDownCounter. + * @return a shared pointer to the created DoubleUpDownCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleUpDownCounter( + virtual opentelemetry::nostd::shared_ptr NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new DoubleUpDownCounter(name, description, unit, enabled)}; } @@ -97,18 +105,18 @@ class Meter * @param description a brief description of what the IntUpDownCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created IntUpDownCounter. + * @return a shared pointer to the created IntUpDownCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntUpDownCounter( + virtual opentelemetry::nostd::shared_ptr NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new IntUpDownCounter(name, description, unit, enabled)}; } @@ -119,18 +127,18 @@ class Meter * @param description a brief description of what the DoubleValueRecorder is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleValueRecorder. + * @return a shared pointer to the created DoubleValueRecorder. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleValueRecorder( + virtual opentelemetry::nostd::shared_ptr NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new DoubleValueRecorder(name, description, unit, enabled)}; } @@ -141,18 +149,18 @@ class Meter * @param description a brief description of what the IntValueRecorder is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created IntValueRecorder. + * @return a shared pointer to the created IntValueRecorder. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntValueRecorder( + virtual opentelemetry::nostd::shared_ptr NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, bool enabled) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new IntValueRecorder(name, description, unit, enabled)}; } @@ -163,19 +171,19 @@ class Meter * @param description a brief description of what the DoubleSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleSumObserver. + * @return a shared pointer to the created DoubleSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleSumObserver( + virtual opentelemetry::nostd::shared_ptr NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(DoubleObserverResult)) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new DoubleSumObserver(name, description, unit, enabled, callback)}; } @@ -186,19 +194,19 @@ class Meter * @param description a brief description of what the IntSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleCounter. + * @return a shared pointer to the created DoubleCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntSumObserver( + virtual opentelemetry::nostd::shared_ptr NewIntSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(IntObserverResult)) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new IntSumObserver(name, description, unit, enabled, callback)}; } @@ -209,19 +217,19 @@ class Meter * @param description a brief description of what the DoubleUpDownSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleUpDownSumObserver. + * @return a shared pointer to the created DoubleUpDownSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr + virtual opentelemetry::nostd::shared_ptr NewDoubleUpDownSumObserver(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(DoubleObserverResult)) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new DoubleUpDownSumObserver(name, description, unit, enabled, callback)}; } @@ -232,19 +240,19 @@ class Meter * @param description a brief description of what the IntUpDownSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created IntUpDownSumObserver. + * @return a shared pointer to the created IntUpDownSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntUpDownSumObserver( + virtual opentelemetry::nostd::shared_ptr NewIntUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(IntObserverResult)) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new IntUpDownSumObserver(name, description, unit, enabled, callback)}; } @@ -255,19 +263,19 @@ class Meter * @param description a brief description of what the DoubleValueObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created DoubleValueObserver. + * @return a shared pointer to the created DoubleValueObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewDoubleValueObserver( + virtual opentelemetry::nostd::shared_ptr NewDoubleValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(DoubleObserverResult)) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new DoubleValueObserver(name, description, unit, enabled, callback)}; } @@ -278,19 +286,19 @@ class Meter * @param description a brief description of what the IntValueObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a unique pointer to the created IntValueObserver. + * @return a shared pointer to the created IntValueObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::unique_ptr NewIntValueObserver( + virtual opentelemetry::nostd::shared_ptr NewIntValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, void (*callback)(IntObserverResult)) { - return opentelemetry::nostd::unique_ptr{ + return opentelemetry::nostd::shared_ptr{ new IntValueObserver(name, description, unit, enabled, callback)}; } From 4c578facf066e6dbc164e3ca3c8759d34636592e Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 15:00:39 -0400 Subject: [PATCH 14/52] Replace mistakenly deleted lines --- api/include/opentelemetry/metrics/noop.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 7bb6e40404..e6a7d71dd3 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -1,3 +1,13 @@ +#pragma once + +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/unique_ptr.h" +#include "opentelemetry/trace/key_value_iterable_view.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics +{ /** * No-op implementation of Meter. This class should not be used directly. */ From 07b308f141e29fa972963f61a487cdc366334aac Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 15:01:35 -0400 Subject: [PATCH 15/52] Refactor test and rename file --- api/test/metrics/noop_metrics_test.cc | 49 +++++++++++++++++++++++++++ api/test/metrics/noop_test_metrics.cc | 27 --------------- 2 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 api/test/metrics/noop_metrics_test.cc delete mode 100644 api/test/metrics/noop_test_metrics.cc diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc new file mode 100644 index 0000000000..8e3b0b9c49 --- /dev/null +++ b/api/test/metrics/noop_metrics_test.cc @@ -0,0 +1,49 @@ +#include "opentelemetry/metrics/noop.h" +#include "opentelemetry/metrics/observer_result.h" + +#include + +#include + +using opentelemetry::metrics::NoopMeter; +using opentelemetry::metrics::Meter; + +void IntCallback(opentelemetry::metrics::IntObserverResult result) +{ + result.observe(1,"key: value"); +} + +void DoubleCallback(opentelemetry::metrics::DoubleObserverResult result) { + result.observe(1.0, "key: value"); +} + +TEST(NoopTest, UseNoopMeters) +{ + std::unique_ptr m{new NoopMeter{}}; + + auto t1 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); + auto t2 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); + m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); + m->NewIntUpDownCounter("Test int counter", "For testing", "Unitless", true); + m->NewDoubleUpDownCounter("Test int counter", "For testing", "Unitless", true); + m->NewIntValueRecorder("Test int counter", "For testing", "Unitless", true); + m->NewDoubleValueRecorder("Test int counter", "For testing", "Unitless", true); + + auto alpha = m->NewIntSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + auto beta = m->NewDoubleSumObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); + auto gamma = m->NewIntUpDownSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + auto delta = m->NewDoubleUpDownSumObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); + auto epsilon = m->NewIntValueObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + auto zeta = m->NewDoubleValueObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); + + alpha->observe(1,"key:value"); + beta->observe(1.0,"key:value"); + gamma->observe(1,"key:value"); + delta->observe(1.0,"key:value"); + epsilon->observe(1,"key:value"); + zeta->observe(1.0,"key:value"); + + ASSERT_NE(t1, t2); + + //Test RecordBatch call +} diff --git a/api/test/metrics/noop_test_metrics.cc b/api/test/metrics/noop_test_metrics.cc deleted file mode 100644 index 90ed33209a..0000000000 --- a/api/test/metrics/noop_test_metrics.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "opentelemetry/metrics/noop.h" - -#include -#include - -#include - -using opentelemetry::metrics::NoopMeter; -using opentelemetry::metrics::Meter; - -TEST(NoopTest, UseNoopMeters) -{ - std::unique_ptr m{new NoopMeter{}}; - - m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - - using MAP = std::map; - MAP batchValues1 = {{}}; - opentelemetry::trace::KeyValueIterableView view{batchValues1}; - m->RecordBatch("abc", view); - - using VEC = std::vector>; - VEC batchValues2 = {}; - opentelemetry::trace::KeyValueIterableView view2{batchValues2}; - m->RecordBatch("abc", view2); - -} From ef67e997e302f4877d95a37fd1018d560f209cc7 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 15:01:55 -0400 Subject: [PATCH 16/52] Rename noop test --- api/test/metrics/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/metrics/CMakeLists.txt b/api/test/metrics/CMakeLists.txt index 66cae04518..c4dae0401c 100644 --- a/api/test/metrics/CMakeLists.txt +++ b/api/test/metrics/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(testname noop_test_metrics) +foreach(testname noop_metrics_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) From bc347e79651ca5a05211331838ea0f9254b1b030 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 15:02:23 -0400 Subject: [PATCH 17/52] Rename noop test --- api/test/metrics/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/test/metrics/BUILD b/api/test/metrics/BUILD index d3ae07708b..be3e592f1a 100644 --- a/api/test/metrics/BUILD +++ b/api/test/metrics/BUILD @@ -1,7 +1,7 @@ cc_test( - name = "noop_test_metrics", + name = "noop_metrics_test", srcs = [ - "noop_test_metrics.cc", + "noop_metrics_test.cc", ], deps = [ "//api", From a7b8e8168a071d27ec4a784f0b437bc4fa092ce9 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 15:14:18 -0400 Subject: [PATCH 18/52] Run on pushes to Meter branch for testing --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5d36c4a61..10ae2d0489 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ master ] + branches: [ master, meter ] pull_request: branches: [ master ] From 2e7ff6cdf00e627618ae2a2d942d38b1d3c6d8ab Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Fri, 3 Jul 2020 15:19:54 -0400 Subject: [PATCH 19/52] Add metrics subdirectory --- api/test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index 21b3e9a350..8c0833a51e 100644 --- a/api/test/CMakeLists.txt +++ b/api/test/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(core) add_subdirectory(plugin) add_subdirectory(nostd) add_subdirectory(trace) +add_subdirectory(metrics) From eb0193f694c58aa919e3d8fb567606ff10a40b8f Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 11:52:10 -0400 Subject: [PATCH 20/52] Delete key_value_iterable.h --- .../metrics/key_value_iterable.h | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 api/include/opentelemetry/metrics/key_value_iterable.h diff --git a/api/include/opentelemetry/metrics/key_value_iterable.h b/api/include/opentelemetry/metrics/key_value_iterable.h deleted file mode 100644 index 8b1f2e1124..0000000000 --- a/api/include/opentelemetry/metrics/key_value_iterable.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/nostd/function_ref.h" -#include "opentelemetry/version.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace trace -{ -/** - * Supports internal iteration over a collection of key-value pairs. - */ -class KeyValueIterable -{ -public: - virtual ~KeyValueIterable() = default; - - /** - * Iterate over key-value pairs - * @param callback a callback to invoke for each key-value. If the callback returns false, - * the iteration is aborted. - * @return true if every key-value pair was iterated over - */ - virtual bool ForEachKeyValue( - nostd::function_ref callback) const - noexcept = 0; - - /** - * @return the number of key-value pairs - */ - virtual size_t size() const noexcept = 0; -}; -} // namespace trace -OPENTELEMETRY_END_NAMESPACE From 5d20af1d36e0a028af0d66f27e18d4f2af6f2111 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 11:52:16 -0400 Subject: [PATCH 21/52] Delete key_value_iterable_view.h --- .../metrics/key_value_iterable_view.h | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 api/include/opentelemetry/metrics/key_value_iterable_view.h diff --git a/api/include/opentelemetry/metrics/key_value_iterable_view.h b/api/include/opentelemetry/metrics/key_value_iterable_view.h deleted file mode 100644 index 2daf83c713..0000000000 --- a/api/include/opentelemetry/metrics/key_value_iterable_view.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "opentelemetry/nostd/utility.h" -#include "opentelemetry/trace/key_value_iterable.h" -#include "opentelemetry/version.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace trace -{ -namespace detail -{ -inline void take_key_value(nostd::string_view, common::AttributeValue) {} - -template -auto is_key_value_iterable_impl(T iterable) - -> decltype(take_key_value(std::begin(iterable)->first, std::begin(iterable)->second), - nostd::size(iterable), - std::true_type{}); - -std::false_type is_key_value_iterable_impl(...); - -template -struct is_key_value_iterable -{ - static const bool value = decltype(detail::is_key_value_iterable_impl(std::declval()))::value; -}; -} // namespace detail - -template -class KeyValueIterableView final : public KeyValueIterable -{ - static_assert(detail::is_key_value_iterable::value, "Must be a key-value iterable"); - -public: - explicit KeyValueIterableView(const T &container) noexcept : container_{&container} {} - - // KeyValueIterable - bool ForEachKeyValue( - nostd::function_ref callback) const - noexcept override - { - auto iter = std::begin(*container_); - auto last = std::end(*container_); - for (; iter != last; ++iter) - { - if (!callback(iter->first, iter->second)) - { - return false; - } - } - return true; - } - - size_t size() const noexcept override { return nostd::size(*container_); } - -private: - const T *container_; -}; -} // namespace trace -OPENTELEMETRY_END_NAMESPACE From ad110b2b19cb9af208f5fc0a2bde3650e8e85f5e Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 12:01:35 -0400 Subject: [PATCH 22/52] Replace KeyValueIterable with span of pairs --- api/include/opentelemetry/metrics/meter.h | 39 +++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 31fcedd750..5e51c15ab9 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -1,7 +1,9 @@ #pragma once -#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/variant.h" #include "opentelemetry/trace/key_value_iterable_view.h" #include "opentelemetry/version.h" @@ -25,14 +27,6 @@ class Meter public: virtual ~Meter() = default; - ////////////////////////////// - // // - // Change pointer type to // - // SynchronousInstrument or // - // AsynchronousInstrument? // - // // - ////////////////////////////// - /** * Creates, adds to private metrics container, and returns a DoubleCounter with "name." * @@ -67,10 +61,11 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewIntCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) + virtual opentelemetry::nostd::shared_ptr NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) { return opentelemetry::nostd::shared_ptr{ new IntCounter(name, description, unit, enabled)}; @@ -222,12 +217,12 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr - NewDoubleUpDownSumObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(DoubleObserverResult)) + virtual opentelemetry::nostd::shared_ptr NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(DoubleObserverResult)) { return opentelemetry::nostd::shared_ptr{ new DoubleUpDownSumObserver(name, description, unit, enabled, callback)}; @@ -312,8 +307,10 @@ class Meter * and the value is the value to be recorded to all metric instruments in * the batch of the associated instrument type. */ - virtual void RecordBatch(nostd::string_view labels, - const trace::KeyValueIterable &values) noexcept + virtual void RecordBatch( + nostd::string_view labels, + const nostd::span, + nostd::variant>> values) noexcept { // No-op } From 998f1cae19bee179331cb7e9ca9eae16201a195b Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 12:02:08 -0400 Subject: [PATCH 23/52] Replace KeyValueIterable and format --- api/include/opentelemetry/metrics/noop.h | 39 ++++++++++-------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index e6a7d71dd3..f09e24c83b 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -1,13 +1,3 @@ -#pragma once - -#include "opentelemetry/metrics/meter.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/unique_ptr.h" -#include "opentelemetry/trace/key_value_iterable_view.h" - -OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics -{ /** * No-op implementation of Meter. This class should not be used directly. */ @@ -16,21 +6,24 @@ class NoopMeter : public Meter public: NoopMeter() = default; - opentelemetry::nostd::shared_ptr NewDoubleCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { return nostd::shared_ptr{ new NoopDoubleCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr NewIntCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr{new NoopIntCounter(name, description, unit, enabled)}; + return nostd::shared_ptr{ + new NoopIntCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr NewDoubleUpDownCounter( @@ -128,11 +121,11 @@ class NoopMeter : public Meter new NoopDoubleValueObserver(name, description, unit, enabled, callback)}; } - void RecordBatch(nostd::string_view /*labels*/, - const trace::KeyValueIterable & /*values*/) noexcept override + void RecordBatch( + nostd::string_view labels, + const nostd::span, + nostd::variant>> values) noexcept override { // No-op } }; -} // namespace metrics -OPENTELEMETRY_END_NAMESPACE From 8780d19eace93bfb56d77b56121dd7d191c21ca4 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 12:03:47 -0400 Subject: [PATCH 24/52] Add RecordBatch test --- api/test/metrics/noop_metrics_test.cc | 60 +++++++++++++++++++-------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 8e3b0b9c49..ad7475ebae 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -1,19 +1,23 @@ #include "opentelemetry/metrics/noop.h" #include "opentelemetry/metrics/observer_result.h" +#include #include #include -using opentelemetry::metrics::NoopMeter; +OPENTELEMETRY_BEGIN_NAMESPACE + using opentelemetry::metrics::Meter; +using opentelemetry::metrics::NoopMeter; void IntCallback(opentelemetry::metrics::IntObserverResult result) { - result.observe(1,"key: value"); + result.observe(1, "key: value"); } -void DoubleCallback(opentelemetry::metrics::DoubleObserverResult result) { +void DoubleCallback(opentelemetry::metrics::DoubleObserverResult result) +{ result.observe(1.0, "key: value"); } @@ -23,27 +27,49 @@ TEST(NoopTest, UseNoopMeters) auto t1 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); auto t2 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); + auto t3 = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); m->NewIntUpDownCounter("Test int counter", "For testing", "Unitless", true); m->NewDoubleUpDownCounter("Test int counter", "For testing", "Unitless", true); m->NewIntValueRecorder("Test int counter", "For testing", "Unitless", true); m->NewDoubleValueRecorder("Test int counter", "For testing", "Unitless", true); - auto alpha = m->NewIntSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); - auto beta = m->NewDoubleSumObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); - auto gamma = m->NewIntUpDownSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); - auto delta = m->NewDoubleUpDownSumObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); - auto epsilon = m->NewIntValueObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); - auto zeta = m->NewDoubleValueObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); + auto alpha = + m->NewIntSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + auto beta = + m->NewDoubleSumObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); + auto gamma = + m->NewIntUpDownSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + auto delta = m->NewDoubleUpDownSumObserver("Test int counter", "For testing", "Unitless", true, + &DoubleCallback); + auto epsilon = + m->NewIntValueObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + auto zeta = m->NewDoubleValueObserver("Test int counter", "For testing", "Unitless", true, + &DoubleCallback); - alpha->observe(1,"key:value"); - beta->observe(1.0,"key:value"); - gamma->observe(1,"key:value"); - delta->observe(1.0,"key:value"); - epsilon->observe(1,"key:value"); - zeta->observe(1.0,"key:value"); + alpha->observe(1, "key:value"); + beta->observe(1.0, "key:value"); + gamma->observe(1, "key:value"); + delta->observe(1.0, "key:value"); + epsilon->observe(1, "key:value"); + zeta->observe(1.0, "key:value"); ASSERT_NE(t1, t2); - //Test RecordBatch call + using M = + std::pair, nostd::variant>; + M t1_pair; + nostd::shared_ptr tmp = t1; + t1_pair.first = tmp; + t1_pair.second = 1; + + M t3_pair; + nostd::shared_ptr tmp2 = t3; + t3_pair.first = tmp2; + t3_pair.second = 2.0; + + std::array arr{t1_pair, t3_pair}; + nostd::span span(arr); + + m->RecordBatch("key: value", span); } +OPENTELEMETRY_END_NAMESPACE From 13bc1b3b2708083f0ee9172f9a427332ddb50692 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 12:07:39 -0400 Subject: [PATCH 25/52] Change test prefix from trace. to metrics. --- api/test/metrics/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/metrics/CMakeLists.txt b/api/test/metrics/CMakeLists.txt index c4dae0401c..35adef4887 100644 --- a/api/test/metrics/CMakeLists.txt +++ b/api/test/metrics/CMakeLists.txt @@ -2,5 +2,5 @@ foreach(testname noop_metrics_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) - gtest_add_tests(TARGET ${testname} TEST_PREFIX trace. TEST_LIST ${testname}) + gtest_add_tests(TARGET ${testname} TEST_PREFIX metrics. TEST_LIST ${testname}) endforeach() From 052889e27edbc8b2e29625b77b259e2d77eecf31 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 14:48:49 -0400 Subject: [PATCH 26/52] Change labels in RecordBatch from string_view to KeyValueIterable --- api/include/opentelemetry/metrics/meter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 5e51c15ab9..e0a3707629 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -308,7 +308,7 @@ class Meter * the batch of the associated instrument type. */ virtual void RecordBatch( - nostd::string_view labels, + const trace::KeyValueIterable &labels, const nostd::span, nostd::variant>> values) noexcept { From fe29603de9e0e67dadbef4b68441e32150534e11 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 14:49:52 -0400 Subject: [PATCH 27/52] Add namespace and change labels to KeyValueIterable --- api/include/opentelemetry/metrics/noop.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index f09e24c83b..321d5b5f40 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -1,3 +1,5 @@ +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics { /** * No-op implementation of Meter. This class should not be used directly. */ @@ -6,6 +8,8 @@ class NoopMeter : public Meter public: NoopMeter() = default; + // All NewInstrument functions return a shared_ptr to a no-op form of that instrument. + opentelemetry::nostd::shared_ptr NewDoubleCounter( nostd::string_view name, nostd::string_view description, @@ -122,10 +126,12 @@ class NoopMeter : public Meter } void RecordBatch( - nostd::string_view labels, + const trace::KeyValueIterable &labels, const nostd::span, nostd::variant>> values) noexcept override { // No-op } }; +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE From 075a5425d160294a772adbb9e0165f75686723d3 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 14:53:39 -0400 Subject: [PATCH 28/52] Update comments --- api/include/opentelemetry/metrics/meter.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index e0a3707629..0357823021 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -166,6 +166,7 @@ class Meter * @param description a brief description of what the DoubleSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created DoubleSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. @@ -189,6 +190,7 @@ class Meter * @param description a brief description of what the IntSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created DoubleCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. @@ -212,6 +214,7 @@ class Meter * @param description a brief description of what the DoubleUpDownSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created DoubleUpDownSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. @@ -235,6 +238,7 @@ class Meter * @param description a brief description of what the IntUpDownSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created IntUpDownSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. @@ -258,6 +262,7 @@ class Meter * @param description a brief description of what the DoubleValueObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created DoubleValueObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. @@ -281,6 +286,7 @@ class Meter * @param description a brief description of what the IntValueObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created IntValueObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. @@ -301,11 +307,9 @@ class Meter * Utility method that allows users to atomically record measurements to a set of * Metric instruments with a common set of labels. * - * @param labels The set of labels to associate with this recorder. - * @param values A KeyValueIterable where the key is a string containing the name - * of metric instruments such as "IntCounter" or "DoubleUpDownSumObserver" - * and the value is the value to be recorded to all metric instruments in - * the batch of the associated instrument type. + * @param labels the set of labels to associate with this recorder. + * @param values a span of pairs where the first element of the pair is a metric instrument + * to record to, and the second element is the value to update that instrument with. */ virtual void RecordBatch( const trace::KeyValueIterable &labels, From 0ecc1215f6b517034378e836b1f5ac9053b89716 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 7 Jul 2020 17:29:33 -0400 Subject: [PATCH 29/52] Remove CI running on Meter pushes --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10ae2d0489..a5d36c4a61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ master, meter ] + branches: [ master ] pull_request: branches: [ master ] From 7f5f7ac005aa4e7f93e56285e18fcfd91c7110c0 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 8 Jul 2020 10:57:00 -0400 Subject: [PATCH 30/52] Test BatchRecord and remove observer tests Also added comments --- api/test/metrics/noop_metrics_test.cc | 65 ++++++++++++++++----------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index ad7475ebae..374b9e5104 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -25,51 +25,66 @@ TEST(NoopTest, UseNoopMeters) { std::unique_ptr m{new NoopMeter{}}; + // Test instrument constructors auto t1 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); auto t2 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - auto t3 = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); - m->NewIntUpDownCounter("Test int counter", "For testing", "Unitless", true); - m->NewDoubleUpDownCounter("Test int counter", "For testing", "Unitless", true); - m->NewIntValueRecorder("Test int counter", "For testing", "Unitless", true); - m->NewDoubleValueRecorder("Test int counter", "For testing", "Unitless", true); + auto t3 = m->NewDoubleCounter("Test double counter", "For testing", "Unitless", true); + m->NewIntUpDownCounter("Test intud counter", "For testing", "Unitless", true); + m->NewDoubleUpDownCounter("Test doubleud counter", "For testing", "Unitless", true); + m->NewIntValueRecorder("Test int recorder", "For testing", "Unitless", true); + m->NewDoubleValueRecorder("Test double recorder", "For testing", "Unitless", true); auto alpha = - m->NewIntSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); + m->NewIntSumObserver("Test int sum obs", "For testing", "Unitless", true, + &IntCallback); auto beta = - m->NewDoubleSumObserver("Test int counter", "For testing", "Unitless", true, &DoubleCallback); + m->NewDoubleSumObserver("Test double sum obs", "For testing", "Unitless", true, + &DoubleCallback); auto gamma = - m->NewIntUpDownSumObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); - auto delta = m->NewDoubleUpDownSumObserver("Test int counter", "For testing", "Unitless", true, + m->NewIntUpDownSumObserver("Test intud sum obs", "For testing", "Unitless", true, + &IntCallback); + auto delta = + m->NewDoubleUpDownSumObserver("Test doubleud sum obs", "For testing", "Unitless", true, &DoubleCallback); auto epsilon = - m->NewIntValueObserver("Test int counter", "For testing", "Unitless", true, &IntCallback); - auto zeta = m->NewDoubleValueObserver("Test int counter", "For testing", "Unitless", true, + m->NewIntValueObserver("Test int val obs", "For testing", "Unitless", true, + &IntCallback); + auto zeta = + m->NewDoubleValueObserver("Test double val obs", "For testing", "Unitless", true, &DoubleCallback); - alpha->observe(1, "key:value"); - beta->observe(1.0, "key:value"); - gamma->observe(1, "key:value"); - delta->observe(1.0, "key:value"); - epsilon->observe(1, "key:value"); - zeta->observe(1.0, "key:value"); - + // Two instruments with the same characteristic should NOT be equal. + // Note: In actual (non-noop) implementations of the Meter class, creating two + // instruments with the same name is disallowed. ASSERT_NE(t1, t2); + // Test BatchRecord + // This is awkward to use because BatchRecord takes a KeyValueIterable and nostd::span of + // std::pairs as arguments. + // This is to adhere to ABI stability. using M = std::pair, nostd::variant>; + + // (t1, 1) M t1_pair; - nostd::shared_ptr tmp = t1; - t1_pair.first = tmp; - t1_pair.second = 1; + t1_pair.first = t1; + t1_pair.second = 1; + // (t3, 2.0) M t3_pair; - nostd::shared_ptr tmp2 = t3; - t3_pair.first = tmp2; - t3_pair.second = 2.0; + t3_pair.first = t3; + t3_pair.second = 2.0; + // Create a std::array and use that array to create a span. std::array arr{t1_pair, t3_pair}; nostd::span span(arr); - m->RecordBatch("key: value", span); + using N = std::map; + + // Create a std::map and use that map to create a KeyValueIterableView + N mp = {{"key", "value"}}; + opentelemetry::trace::KeyValueIterableView view{mp}; + + m->RecordBatch(view, span); } OPENTELEMETRY_END_NAMESPACE From 3600ee4dac2b252ddd5ca0ba569e84607ea8dcb7 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 9 Jul 2020 10:59:23 -0400 Subject: [PATCH 31/52] Add overloaded BatchRecord functions --- api/include/opentelemetry/metrics/meter.h | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 0357823021..4c2f81d2e6 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -318,6 +318,61 @@ class Meter { // No-op } + + /** + * Utility method that allows users to atomically record measurements to a set of + * Metric instruments with a common set of labels. + * + * This overloads the BatchRecord function to allow {@code labels} to be of type std::map. + * + * @param labels the set of labels to associate with this recorder. + * @param values a span of pairs where the first element of the pair is a metric instrument + * to record to, and the second element is the value to update that instrument with. + */ + template ::value> * = nullptr> + void RecordBatch( + const T &labels, + const nostd::span, + nostd::variant>> values) noexcept + { + // No-op + } + + /** + * Utility method that allows users to atomically record measurements to a set of + * Metric instruments with a common set of labels. + * + * This overloads the BatchRecord function to allow {@code labels} to be of type initializer list. + * + * @param labels the set of labels to associate with this recorder. + * @param values a span of pairs where the first element of the pair is a metric instrument + * to record to, and the second element is the value to update that instrument with. + */ + void RecordBatch( + std::initializer_list> labels, + const nostd::span, + nostd::variant>> values) noexcept + { + // No-op + } + + /** + * Utility method that allows users to atomically record measurements to a set of + * Metric instruments with a common set of labels. + * + * This overloads the BatchRecord function to allow {@code labels} and {@code values} + * to be of type initializer list. + * + * @param labels the set of labels to associate with this recorder. + * @param values a span of pairs where the first element of the pair is a metric instrument + * to record to, and the second element is the value to update that instrument with. + */ + void RecordBatch( + std::initializer_list> labels, + std::initializer_list, nostd::variant>>) noexcept + { + // No-op + } }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE From f4e2740b48dd6332a63858e2f3f89e22a598eb85 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 9 Jul 2020 11:00:19 -0400 Subject: [PATCH 32/52] Update noop_metrics_test.cc --- api/test/metrics/noop_metrics_test.cc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 374b9e5104..9ca2b28766 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -44,14 +44,14 @@ TEST(NoopTest, UseNoopMeters) m->NewIntUpDownSumObserver("Test intud sum obs", "For testing", "Unitless", true, &IntCallback); auto delta = - m->NewDoubleUpDownSumObserver("Test doubleud sum obs", "For testing", "Unitless", true, - &DoubleCallback); + m->NewDoubleUpDownSumObserver("Test doubleud sum obs", "For testing", "Unitless", true, + &DoubleCallback); auto epsilon = m->NewIntValueObserver("Test int val obs", "For testing", "Unitless", true, &IntCallback); auto zeta = - m->NewDoubleValueObserver("Test double val obs", "For testing", "Unitless", true, - &DoubleCallback); + m->NewDoubleValueObserver("Test double val obs", "For testing", "Unitless", true, + &DoubleCallback); // Two instruments with the same characteristic should NOT be equal. // Note: In actual (non-noop) implementations of the Meter class, creating two @@ -64,7 +64,7 @@ TEST(NoopTest, UseNoopMeters) // This is to adhere to ABI stability. using M = std::pair, nostd::variant>; - + // (t1, 1) M t1_pair; t1_pair.first = t1; @@ -79,12 +79,13 @@ TEST(NoopTest, UseNoopMeters) std::array arr{t1_pair, t3_pair}; nostd::span span(arr); - using N = std::map; - - // Create a std::map and use that map to create a KeyValueIterableView + using N = std::map; + N mp = {{"key", "value"}}; - opentelemetry::trace::KeyValueIterableView view{mp}; - - m->RecordBatch(view, span); + + // Test all versions of RecordBatch + m->RecordBatch(mp, span); + m->RecordBatch({{"Key", "Value"}}, span); + m->RecordBatch({{"Key", "Value"}}, {{t1, 1}, {t3, 2.0}}); } OPENTELEMETRY_END_NAMESPACE From 9c825cc0fb67271f2019c76c15292f54ddec3863 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 9 Jul 2020 11:43:15 -0400 Subject: [PATCH 33/52] Update comments --- api/include/opentelemetry/metrics/meter.h | 36 +++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 4c2f81d2e6..25dff34d2d 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -28,7 +28,8 @@ class Meter virtual ~Meter() = default; /** - * Creates, adds to private metrics container, and returns a DoubleCounter with "name." + * Creates a DoubleCounter with the passed characteristics and returns a shared_ptr to that + * DoubleCounter. * * @param name the name of the new DoubleCounter. * @param description a brief description of what the DoubleCounter is used for. @@ -50,7 +51,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns an IntCounter with "name." + * Creates an IntCounter with the passed characteristics and returns a shared_ptr to that + * IntCounter. * * @param name the name of the new IntCounter. * @param description a brief description of what the IntCounter is used for. @@ -72,7 +74,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns a DoubleUpDownCounter with "name." + * Creates a DoubleUpDownCounter with the passed characteristics and returns a shared_ptr to that + * DoubleUpDownCounter. * * @param name the name of the new DoubleUpDownCounter. * @param description a brief description of what the DoubleUpDownCounter is used for. @@ -94,7 +97,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns an IntUpDownCounter with "name." + * Creates an IntUpDownCounter with the passed characteristics and returns a shared_ptr to that + * IntUpDownCounter. * * @param name the name of the new IntUpDownCounter. * @param description a brief description of what the IntUpDownCounter is used for. @@ -116,7 +120,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns a DoubleValueRecorder with "name." + * Creates a DoubleValueRecorder with the passed characteristics and returns a shared_ptr to that + * DoubleValueRecorder. * * @param name the name of the new DoubleValueRecorder. * @param description a brief description of what the DoubleValueRecorder is used for. @@ -138,7 +143,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns an IntValueRecorder with "name." + * Creates an IntValueRecorder with the passed characteristics and returns a shared_ptr to that + * IntValueRecoder. * * @param name the name of the new IntValueRecorder. * @param description a brief description of what the IntValueRecorder is used for. @@ -160,7 +166,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns a DoubleSumObserver with "name." + * Creates a DoubleSumObserver with the passed characteristics and returns a shared_ptr to that + * DoubleSumObserver. * * @param name the name of the new DoubleSumObserver. * @param description a brief description of what the DoubleSumObserver is used for. @@ -184,7 +191,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns an IntSumObserver with "name." + * Creates a IntSumObserver with the passed characteristics and returns a shared_ptr to that + * IntSumObserver. * * @param name the name of the new IntSumObserver. * @param description a brief description of what the IntSumObserver is used for. @@ -208,7 +216,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns a DoubleUpDownSumObserver with "name." + * Creates a DoubleUpDownSumObserver with the passed characteristics and returns a shared_ptr to + * that DoubleUpDowNSumObserver. * * @param name the name of the new DoubleUpDownSumObserver. * @param description a brief description of what the DoubleUpDownSumObserver is used for. @@ -232,7 +241,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns an IntUpDownSumObserver with "name." + * Creates a IntUpDownSumObserver with the passed characteristics and returns a shared_ptr to that + * IntUpDownSumObserver. * * @param name the name of the new IntUpDownSumObserver. * @param description a brief description of what the IntUpDownSumObserver is used for. @@ -256,7 +266,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns a DoubleValueObserver with "name." + * Creates a DoubleValueObserver with the passed characteristics and returns a shared_ptr to that + * DoubleValueObserver. * * @param name the name of the new DoubleValueObserver. * @param description a brief description of what the DoubleValueObserver is used for. @@ -280,7 +291,8 @@ class Meter } /** - * Creates, adds to private metrics container, and returns an IntValueObserver with "name." + * Creates an IntValueObserver with the passed characteristics and returns a shared_ptr to that + * IntValueObserver. * * @param name the name of the new IntValueObserver. * @param description a brief description of what the IntValueObserver is used for. From 6f4f9c2277e45b765a1ceb65e01ee1a662dcd14a Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 15 Jul 2020 12:57:14 -0400 Subject: [PATCH 34/52] Template Meter class Also made instrument functions purely virtual --- api/include/opentelemetry/metrics/meter.h | 294 ++++------------------ 1 file changed, 54 insertions(+), 240 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 25dff34d2d..6315ec3f13 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -22,109 +22,56 @@ namespace metrics * measurements from all instruments. * */ +//TODO: FIGURE OUT HOW TO LET THE USER CREATE METRIC INSTRUMENTS OF VARIOUS TYPES +template class Meter { public: virtual ~Meter() = default; /** - * Creates a DoubleCounter with the passed characteristics and returns a shared_ptr to that - * DoubleCounter. + * Creates a Counter with the passed characteristics and returns a shared_ptr to that Counter. * - * @param name the name of the new DoubleCounter. - * @param description a brief description of what the DoubleCounter is used for. + * @param name the name of the new Counter. + * @param description a brief description of what the Counter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a shared pointer to the created DoubleCounter. + * @return a shared pointer to the created Counter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewDoubleCounter( + virtual opentelemetry::nostd::shared_ptr> NewCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) - { - return opentelemetry::nostd::shared_ptr{ - new DoubleCounter(name, description, unit, enabled)}; - } - - /** - * Creates an IntCounter with the passed characteristics and returns a shared_ptr to that - * IntCounter. - * - * @param name the name of the new IntCounter. - * @param description a brief description of what the IntCounter is used for. - * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. - * @return a shared pointer to the created IntCounter. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. - */ - virtual opentelemetry::nostd::shared_ptr NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) - { - return opentelemetry::nostd::shared_ptr{ - new IntCounter(name, description, unit, enabled)}; - } - - /** - * Creates a DoubleUpDownCounter with the passed characteristics and returns a shared_ptr to that - * DoubleUpDownCounter. - * - * @param name the name of the new DoubleUpDownCounter. - * @param description a brief description of what the DoubleUpDownCounter is used for. - * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. - * @return a shared pointer to the created DoubleUpDownCounter. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. - */ - virtual opentelemetry::nostd::shared_ptr NewDoubleUpDownCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) - { - return opentelemetry::nostd::shared_ptr{ - new DoubleUpDownCounter(name, description, unit, enabled)}; - } + const bool enabled) = 0; /** - * Creates an IntUpDownCounter with the passed characteristics and returns a shared_ptr to that - * IntUpDownCounter. + * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that + * UpDownCounter. * - * @param name the name of the new IntUpDownCounter. - * @param description a brief description of what the IntUpDownCounter is used for. + * @param name the name of the new UpDownCounter. + * @param description a brief description of what the UpDownCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. - * @return a shared pointer to the created IntUpDownCounter. + * @return a shared pointer to the created UpDownCounter. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewIntUpDownCounter( + virtual opentelemetry::nostd::shared_ptr> NewUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) - { - return opentelemetry::nostd::shared_ptr{ - new IntUpDownCounter(name, description, unit, enabled)}; - } + const bool enabled) = 0; /** - * Creates a DoubleValueRecorder with the passed characteristics and returns a shared_ptr to that - * DoubleValueRecorder. + * Creates a ValueRecorder with the passed characteristics and returns a shared_ptr to that + * ValueRecorder. * - * @param name the name of the new DoubleValueRecorder. - * @param description a brief description of what the DoubleValueRecorder is used for. + * @param name the name of the new ValueRecorder. + * @param description a brief description of what the ValueRecorder is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. * @return a shared pointer to the created DoubleValueRecorder. @@ -132,192 +79,78 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewDoubleValueRecorder( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) - { - return opentelemetry::nostd::shared_ptr{ - new DoubleValueRecorder(name, description, unit, enabled)}; - } - - /** - * Creates an IntValueRecorder with the passed characteristics and returns a shared_ptr to that - * IntValueRecoder. - * - * @param name the name of the new IntValueRecorder. - * @param description a brief description of what the IntValueRecorder is used for. - * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. - * @return a shared pointer to the created IntValueRecorder. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. - */ - virtual opentelemetry::nostd::shared_ptr NewIntValueRecorder( + virtual opentelemetry::nostd::shared_ptr> NewValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - bool enabled) - { - return opentelemetry::nostd::shared_ptr{ - new IntValueRecorder(name, description, unit, enabled)}; - } + const bool enabled) = 0; /** - * Creates a DoubleSumObserver with the passed characteristics and returns a shared_ptr to that - * DoubleSumObserver. + * Creates a SumObserver with the passed characteristics and returns a shared_ptr to that + * SumObserver. * - * @param name the name of the new DoubleSumObserver. - * @param description a brief description of what the DoubleSumObserver is used for. + * @param name the name of the new SumObserver. + * @param description a brief description of what the SumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. * @param callback the function to be observed by the instrument. - * @return a shared pointer to the created DoubleSumObserver. + * @return a shared pointer to the created SumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewDoubleSumObserver( + virtual opentelemetry::nostd::shared_ptr> NewSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(DoubleObserverResult)) - { - return opentelemetry::nostd::shared_ptr{ - new DoubleSumObserver(name, description, unit, enabled, callback)}; - } + void (*callback)(ObserverResult)) = 0; /** - * Creates a IntSumObserver with the passed characteristics and returns a shared_ptr to that - * IntSumObserver. + * Creates an UpDownSumObserver with the passed characteristics and returns a shared_ptr to + * that UpDowNSumObserver. * - * @param name the name of the new IntSumObserver. - * @param description a brief description of what the IntSumObserver is used for. + * @param name the name of the new UpDownSumObserver. + * @param description a brief description of what the UpDownSumObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. * @param callback the function to be observed by the instrument. - * @return a shared pointer to the created DoubleCounter. + * @return a shared pointer to the created UpDownSumObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewIntSumObserver( + virtual opentelemetry::nostd::shared_ptr> NewUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(IntObserverResult)) - { - return opentelemetry::nostd::shared_ptr{ - new IntSumObserver(name, description, unit, enabled, callback)}; - } + void (*callback)(ObserverResult)) = 0; /** - * Creates a DoubleUpDownSumObserver with the passed characteristics and returns a shared_ptr to - * that DoubleUpDowNSumObserver. + * Creates a ValueObserver with the passed characteristics and returns a shared_ptr to that + * ValueObserver. * - * @param name the name of the new DoubleUpDownSumObserver. - * @param description a brief description of what the DoubleUpDownSumObserver is used for. + * @param name the name of the new ValueObserver. + * @param description a brief description of what the ValueObserver is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. * @param callback the function to be observed by the instrument. - * @return a shared pointer to the created DoubleUpDownSumObserver. + * @return a shared pointer to the created ValueObserver. * @throws NullPointerException if {@code name} is null * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr NewDoubleUpDownSumObserver( + virtual opentelemetry::nostd::shared_ptr> NewValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(DoubleObserverResult)) - { - return opentelemetry::nostd::shared_ptr{ - new DoubleUpDownSumObserver(name, description, unit, enabled, callback)}; - } - - /** - * Creates a IntUpDownSumObserver with the passed characteristics and returns a shared_ptr to that - * IntUpDownSumObserver. - * - * @param name the name of the new IntUpDownSumObserver. - * @param description a brief description of what the IntUpDownSumObserver is used for. - * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. - * @param callback the function to be observed by the instrument. - * @return a shared pointer to the created IntUpDownSumObserver. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. - */ - virtual opentelemetry::nostd::shared_ptr NewIntUpDownSumObserver( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(IntObserverResult)) - { - return opentelemetry::nostd::shared_ptr{ - new IntUpDownSumObserver(name, description, unit, enabled, callback)}; - } - - /** - * Creates a DoubleValueObserver with the passed characteristics and returns a shared_ptr to that - * DoubleValueObserver. - * - * @param name the name of the new DoubleValueObserver. - * @param description a brief description of what the DoubleValueObserver is used for. - * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. - * @param callback the function to be observed by the instrument. - * @return a shared pointer to the created DoubleValueObserver. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. - */ - virtual opentelemetry::nostd::shared_ptr NewDoubleValueObserver( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(DoubleObserverResult)) - { - return opentelemetry::nostd::shared_ptr{ - new DoubleValueObserver(name, description, unit, enabled, callback)}; - } - - /** - * Creates an IntValueObserver with the passed characteristics and returns a shared_ptr to that - * IntValueObserver. - * - * @param name the name of the new IntValueObserver. - * @param description a brief description of what the IntValueObserver is used for. - * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. - * @param callback the function to be observed by the instrument. - * @return a shared pointer to the created IntValueObserver. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. - */ - virtual opentelemetry::nostd::shared_ptr NewIntValueObserver( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(IntObserverResult)) - { - return opentelemetry::nostd::shared_ptr{ - new IntValueObserver(name, description, unit, enabled, callback)}; - } + void (*callback)(ObserverResult)) = 0; /** * Utility method that allows users to atomically record measurements to a set of - * Metric instruments with a common set of labels. + * synchronous metric instruments with a common set of labels. * * @param labels the set of labels to associate with this recorder. * @param values a span of pairs where the first element of the pair is a metric instrument @@ -325,63 +158,44 @@ class Meter */ virtual void RecordBatch( const trace::KeyValueIterable &labels, - const nostd::span, - nostd::variant>> values) noexcept + const nostd::span>, + T>> values) noexcept { // No-op } /** * Utility method that allows users to atomically record measurements to a set of - * Metric instruments with a common set of labels. - * - * This overloads the BatchRecord function to allow {@code labels} to be of type std::map. - * - * @param labels the set of labels to associate with this recorder. - * @param values a span of pairs where the first element of the pair is a metric instrument - * to record to, and the second element is the value to update that instrument with. - */ - template ::value> * = nullptr> - void RecordBatch( - const T &labels, - const nostd::span, - nostd::variant>> values) noexcept - { - // No-op - } - - /** - * Utility method that allows users to atomically record measurements to a set of - * Metric instruments with a common set of labels. + * synchronous metric instruments with a common set of labels. * * This overloads the BatchRecord function to allow {@code labels} to be of type initializer list. * - * @param labels the set of labels to associate with this recorder. + * @param labels an initializer list holding labels to associate with this recording. * @param values a span of pairs where the first element of the pair is a metric instrument * to record to, and the second element is the value to update that instrument with. */ void RecordBatch( std::initializer_list> labels, - const nostd::span, - nostd::variant>> values) noexcept + const nostd::span>, + T>> values) noexcept { // No-op } /** * Utility method that allows users to atomically record measurements to a set of - * Metric instruments with a common set of labels. + * synchronous metric instruments with a common set of labels. * * This overloads the BatchRecord function to allow {@code labels} and {@code values} * to be of type initializer list. * - * @param labels the set of labels to associate with this recorder. - * @param values a span of pairs where the first element of the pair is a metric instrument - * to record to, and the second element is the value to update that instrument with. + * @param labels an initializer list of pairs holding labels to associate with this recording. + * @param values an initializer list of pairs holding ptrs to instruments and the value to record + * to that respective instrument. */ void RecordBatch( std::initializer_list> labels, - std::initializer_list, nostd::variant>>) noexcept + std::initializer_list>, T>>) noexcept { // No-op } From 8426b08caa7c46bc280b440a89490a1228be369f Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 15 Jul 2020 13:00:44 -0400 Subject: [PATCH 35/52] Template Noop Meter class Also removed RecordBatch implementation as inherited No-op works fine. --- api/include/opentelemetry/metrics/noop.h | 107 +++++------------------ 1 file changed, 23 insertions(+), 84 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 321d5b5f40..414a29f337 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -3,134 +3,73 @@ namespace metrics { /** * No-op implementation of Meter. This class should not be used directly. */ -class NoopMeter : public Meter +template +class NoopMeter : public Meter { public: NoopMeter() = default; - // All NewInstrument functions return a shared_ptr to a no-op form of that instrument. - - opentelemetry::nostd::shared_ptr NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override - { - return nostd::shared_ptr{ - new NoopDoubleCounter(name, description, unit, enabled)}; - } - - opentelemetry::nostd::shared_ptr NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override - { - return nostd::shared_ptr{ - new NoopIntCounter(name, description, unit, enabled)}; - } - - opentelemetry::nostd::shared_ptr NewDoubleUpDownCounter( + nostd::shared_ptr> NewCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr{ - new NoopDoubleUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr NewIntUpDownCounter( + nostd::shared_ptr> NewUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr{ - new NoopIntUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr NewDoubleValueRecorder( + nostd::shared_ptr> NewValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr{ - new NoopDoubleValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr NewIntValueRecorder( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override - { - return nostd::shared_ptr{ - new NoopIntValueRecorder(name, description, unit, enabled)}; - } - - opentelemetry::nostd::shared_ptr NewDoubleSumObserver( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(DoubleObserverResult)) override - { - return nostd::shared_ptr{ - new NoopDoubleSumObserver(name, description, unit, enabled, callback)}; - } - - opentelemetry::nostd::shared_ptr NewIntSumObserver( + nostd::shared_ptr> NewSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(IntObserverResult)) override + void (*callback)(ObserverResult)) override { - return nostd::shared_ptr{ - new NoopIntSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::shared_ptr NewDoubleUpDownSumObserver( + nostd::shared_ptr> NewUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(DoubleObserverResult)) override + void (*callback)(ObserverResult)) override { - return nostd::shared_ptr{ - new NoopDoubleUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } - opentelemetry::nostd::shared_ptr NewIntUpDownSumObserver( + nostd::shared_ptr> NewValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(IntObserverResult)) override - { - return nostd::shared_ptr{ - new NoopIntUpDownSumObserver(name, description, unit, enabled, callback)}; - } - - opentelemetry::nostd::shared_ptr NewDoubleValueObserver( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(DoubleObserverResult)) override - { - return nostd::shared_ptr{ - new NoopDoubleValueObserver(name, description, unit, enabled, callback)}; - } - - void RecordBatch( - const trace::KeyValueIterable &labels, - const nostd::span, - nostd::variant>> values) noexcept override + void (*callback)(ObserverResult)) override { - // No-op + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } }; } // namespace metrics From 28ca75de1922e30828734316d5359e0f7ac19602 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 15 Jul 2020 13:01:35 -0400 Subject: [PATCH 36/52] Switch to use template noop meter class Also split the tests up into separate sub-tests. --- api/test/metrics/noop_metrics_test.cc | 96 +++++++++++++++------------ 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 9ca2b28766..f39f428b61 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -1,91 +1,99 @@ +#include #include "opentelemetry/metrics/noop.h" #include "opentelemetry/metrics/observer_result.h" #include #include -#include - OPENTELEMETRY_BEGIN_NAMESPACE using opentelemetry::metrics::Meter; using opentelemetry::metrics::NoopMeter; -void IntCallback(opentelemetry::metrics::IntObserverResult result) +void Callback(opentelemetry::metrics::ObserverResult result) { - result.observe(1, "key: value"); + std::map labels = {{"key", "value"}}; + auto labelkv = trace::KeyValueIterableView{labels}; + result.observe(1, labelkv); } -void DoubleCallback(opentelemetry::metrics::DoubleObserverResult result) +TEST(NoopTest, CreateInstruments) { - result.observe(1.0, "key: value"); -} - -TEST(NoopTest, UseNoopMeters) -{ - std::unique_ptr m{new NoopMeter{}}; + std::unique_ptr> m{std::unique_ptr>(new NoopMeter{})}; // Test instrument constructors - auto t1 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - auto t2 = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - auto t3 = m->NewDoubleCounter("Test double counter", "For testing", "Unitless", true); - m->NewIntUpDownCounter("Test intud counter", "For testing", "Unitless", true); - m->NewDoubleUpDownCounter("Test doubleud counter", "For testing", "Unitless", true); - m->NewIntValueRecorder("Test int recorder", "For testing", "Unitless", true); - m->NewDoubleValueRecorder("Test double recorder", "For testing", "Unitless", true); + auto t1 = m->NewCounter("Test counter", "For testing", "Unitless", true); + auto t2 = m->NewCounter("Test counter", "For testing", "Unitless", true); + m->NewUpDownCounter("Test ud counter", "For testing", "Unitless", true); + m->NewValueRecorder("Test recorder", "For testing", "Unitless", true); auto alpha = - m->NewIntSumObserver("Test int sum obs", "For testing", "Unitless", true, - &IntCallback); + m->NewSumObserver("Test sum obs", "For testing", "Unitless", true, + &Callback); auto beta = - m->NewDoubleSumObserver("Test double sum obs", "For testing", "Unitless", true, - &DoubleCallback); + m->NewUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, + &Callback); auto gamma = - m->NewIntUpDownSumObserver("Test intud sum obs", "For testing", "Unitless", true, - &IntCallback); - auto delta = - m->NewDoubleUpDownSumObserver("Test doubleud sum obs", "For testing", "Unitless", true, - &DoubleCallback); - auto epsilon = - m->NewIntValueObserver("Test int val obs", "For testing", "Unitless", true, - &IntCallback); - auto zeta = - m->NewDoubleValueObserver("Test double val obs", "For testing", "Unitless", true, - &DoubleCallback); + m->NewValueObserver("Test val obs", "For testing", "Unitless", true, + &Callback); // Two instruments with the same characteristic should NOT be equal. // Note: In actual (non-noop) implementations of the Meter class, creating two // instruments with the same name is disallowed. ASSERT_NE(t1, t2); +} +TEST(NoopMeter, RecordBatch) +{ // Test BatchRecord // This is awkward to use because BatchRecord takes a KeyValueIterable and nostd::span of // std::pairs as arguments. // This is to adhere to ABI stability. + std::unique_ptr> m{std::unique_ptr>(new NoopMeter{})}; + auto t1 = m->NewCounter("Test counter", "For testing", "Unitless", true); + auto t2 = m->NewCounter("Test counter", "For testing", "Unitless", true); + using M = - std::pair, nostd::variant>; + std::pair>, int>; // (t1, 1) M t1_pair; t1_pair.first = t1; t1_pair.second = 1; - // (t3, 2.0) - M t3_pair; - t3_pair.first = t3; - t3_pair.second = 2.0; + // (t2, 2) + M t2_pair; + t2_pair.first = t2; + t2_pair.second = 2; // Create a std::array and use that array to create a span. - std::array arr{t1_pair, t3_pair}; + std::array arr{t1_pair, t2_pair}; nostd::span span(arr); - using N = std::map; - - N mp = {{"key", "value"}}; + // Create a KeyValueIterableView for labels + std::map labels = {{"key", "value"}}; + auto labelkv = trace::KeyValueIterableView{labels}; // Test all versions of RecordBatch - m->RecordBatch(mp, span); + m->RecordBatch(labelkv, span); m->RecordBatch({{"Key", "Value"}}, span); - m->RecordBatch({{"Key", "Value"}}, {{t1, 1}, {t3, 2.0}}); + m->RecordBatch({{"Key", "Value"}}, {{t1, 1}, {t2, 2}}); +} + +TEST(NoopMeter, InstrumentTypes) +{ + std::unique_ptr> m{std::unique_ptr>(new NoopMeter{})}; + + auto counter = + m->NewCounter("Test counter", "For testing", "Unitless", true); + + auto other_counter = + m->NewCounter("Other test counter", "For testing", "Unitless", true); + + std::map labels = {{"key", "value"}}; + auto labelkv = trace::KeyValueIterableView{labels}; + + counter->update(1, labelkv); + other_counter->update(1.0, labelkv); } OPENTELEMETRY_END_NAMESPACE From afebf7507dd26d58c3190264bd96fcbaecf2b42f Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 15:59:38 -0400 Subject: [PATCH 37/52] Refactored to integrate with instrument classes - Changed the return type of the NewInstrument functions to return a nostd::shared_ptr to the actual instrument rather than a nostd::shared_ptr to SynchronousInstrument or AsynchronousInstrument - Altered the parameters of RecordBatch so that they are ABI-stable - Added new overloaded functions to improve user interaction with the RecordBatch class. --- api/include/opentelemetry/metrics/meter.h | 235 +++++++++++++++++----- 1 file changed, 184 insertions(+), 51 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 6315ec3f13..f2a23b0397 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -1,16 +1,13 @@ #pragma once +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/instrument.h" +#include "opentelemetry/metrics/sync_instruments.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/variant.h" -#include "opentelemetry/trace/key_value_iterable_view.h" #include "opentelemetry/version.h" -#include "opentelemetry/metrics/async_instruments.h" -#include "opentelemetry/metrics/instrument.h" -#include "opentelemetry/metrics/sync_instruments.h" - OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics { @@ -22,8 +19,6 @@ namespace metrics * measurements from all instruments. * */ -//TODO: FIGURE OUT HOW TO LET THE USER CREATE METRIC INSTRUMENTS OF VARIOUS TYPES -template class Meter { public: @@ -41,7 +36,25 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr> NewCounter( + virtual nostd::shared_ptr> NewShortCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, @@ -60,7 +73,25 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr> NewUpDownCounter( + virtual nostd::shared_ptr> NewShortUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, @@ -79,7 +110,25 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr> NewValueRecorder( + virtual nostd::shared_ptr> NewShortValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, @@ -99,12 +148,33 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr> NewSumObserver( + virtual nostd::shared_ptr> NewShortSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewFloatSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; + void (*callback)(ObserverResult)) = 0; /** * Creates an UpDownSumObserver with the passed characteristics and returns a shared_ptr to @@ -120,12 +190,33 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr> NewUpDownSumObserver( + virtual nostd::shared_ptr> NewShortUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewDoubleUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; + void (*callback)(ObserverResult)) = 0; /** * Creates a ValueObserver with the passed characteristics and returns a shared_ptr to that @@ -141,12 +232,33 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual opentelemetry::nostd::shared_ptr> NewValueObserver( + virtual nostd::shared_ptr> NewShortValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewIntValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewFloatValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; /** * Utility method that allows users to atomically record measurements to a set of @@ -156,49 +268,70 @@ class Meter * @param values a span of pairs where the first element of the pair is a metric instrument * to record to, and the second element is the value to update that instrument with. */ - virtual void RecordBatch( + virtual void RecordShortBatch( const trace::KeyValueIterable &labels, - const nostd::span>, - T>> values) noexcept + nostd::span>> instruments, + nostd::span values) noexcept = 0; + + void RecordShortBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - // No-op + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordShortBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); } - /** - * Utility method that allows users to atomically record measurements to a set of - * synchronous metric instruments with a common set of labels. - * - * This overloads the BatchRecord function to allow {@code labels} to be of type initializer list. - * - * @param labels an initializer list holding labels to associate with this recording. - * @param values a span of pairs where the first element of the pair is a metric instrument - * to record to, and the second element is the value to update that instrument with. - */ - void RecordBatch( - std::initializer_list> labels, - const nostd::span>, - T>> values) noexcept + virtual void RecordIntBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept = 0; + + void RecordIntBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - // No-op + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordIntBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); } - /** - * Utility method that allows users to atomically record measurements to a set of - * synchronous metric instruments with a common set of labels. - * - * This overloads the BatchRecord function to allow {@code labels} and {@code values} - * to be of type initializer list. - * - * @param labels an initializer list of pairs holding labels to associate with this recording. - * @param values an initializer list of pairs holding ptrs to instruments and the value to record - * to that respective instrument. - */ - void RecordBatch( - std::initializer_list> labels, - std::initializer_list>, T>>) noexcept + virtual void RecordFloatBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept = 0; + + void RecordFloatBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - // No-op + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordFloatBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); } + + virtual void RecordDoubleBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept = 0; + + void RecordDoubleBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) + { + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordDoubleBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); + } + }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE From e75ba610ff9f8111ee8d1d283cd152fe03c73fa7 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 16:00:37 -0400 Subject: [PATCH 38/52] Update to match func signatures of Meter class --- api/include/opentelemetry/metrics/noop.h | 311 +++++++++++++++++++++-- 1 file changed, 288 insertions(+), 23 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 414a29f337..4140a41ef4 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -3,73 +3,338 @@ namespace metrics { /** * No-op implementation of Meter. This class should not be used directly. */ -template -class NoopMeter : public Meter +class NoopMeter : public Meter { public: NoopMeter() = default; - nostd::shared_ptr> NewCounter( + /** + * + * Creates a new NoopCounter and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } - nostd::shared_ptr> NewUpDownCounter( + opentelemetry::nostd::shared_ptr> NewIntCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } - nostd::shared_ptr> NewValueRecorder( + opentelemetry::nostd::shared_ptr> NewFloatCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } - nostd::shared_ptr> NewSumObserver( + opentelemetry::nostd::shared_ptr> NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + } + + /** + * + * Creates a new NoopCounter and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + } + + /** + * + * Creates a new ValueRecorder and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + } + + /** + * + * Creates a new SumObserver and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) override + void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; } - nostd::shared_ptr> NewUpDownSumObserver( + /** + * + * Creates a new UpDownSumObserver and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) override + void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } - nostd::shared_ptr> NewValueObserver( + opentelemetry::nostd::shared_ptr> NewIntUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) override + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + /** + * + * Creates a new ValueObserverObserver and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewIntValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + /** + * + * Utility method that allows users to atomically record measurements to a set of + * synchronous metric instruments with a common set of labels. + * + * @param labels the set of labels to associate with this recorder. + * @param instrs the instruments to record to. + * @param values the value to record to those instruments. + */ + void RecordShortBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept override + { + // No-op + } + + void RecordIntBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept override + { + // No-op + } + + void RecordFloatBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept override + { + // No-op + } + + void RecordDoubleBatch( + const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept override { - return nostd::shared_ptr>{ - new NoopValueObserver(name, description, unit, enabled, callback)}; + // No-op } }; } // namespace metrics From 0386da3c2bfdecb3c83d95e50db6f36da41b539c Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 16:01:30 -0400 Subject: [PATCH 39/52] Update function args to match updates to NoopMeter --- api/test/metrics/noop_metrics_test.cc | 80 ++++++--------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index f39f428b61..2617fb7d52 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -2,7 +2,6 @@ #include "opentelemetry/metrics/noop.h" #include "opentelemetry/metrics/observer_result.h" -#include #include OPENTELEMETRY_BEGIN_NAMESPACE @@ -19,81 +18,38 @@ void Callback(opentelemetry::metrics::ObserverResult result) TEST(NoopTest, CreateInstruments) { - std::unique_ptr> m{std::unique_ptr>(new NoopMeter{})}; + auto m = std::unique_ptr(new NoopMeter{}); // Test instrument constructors - auto t1 = m->NewCounter("Test counter", "For testing", "Unitless", true); - auto t2 = m->NewCounter("Test counter", "For testing", "Unitless", true); - m->NewUpDownCounter("Test ud counter", "For testing", "Unitless", true); - m->NewValueRecorder("Test recorder", "For testing", "Unitless", true); + m->NewIntCounter("Test counter", "For testing", "Unitless", true); + m->NewIntUpDownCounter("Test ud counter", "For testing", "Unitless", true); + m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true); - auto alpha = - m->NewSumObserver("Test sum obs", "For testing", "Unitless", true, + m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, &Callback); - auto beta = - m->NewUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, + m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, &Callback); - auto gamma = - m->NewValueObserver("Test val obs", "For testing", "Unitless", true, + m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback); - - // Two instruments with the same characteristic should NOT be equal. - // Note: In actual (non-noop) implementations of the Meter class, creating two - // instruments with the same name is disallowed. - ASSERT_NE(t1, t2); } TEST(NoopMeter, RecordBatch) { - // Test BatchRecord - // This is awkward to use because BatchRecord takes a KeyValueIterable and nostd::span of - // std::pairs as arguments. - // This is to adhere to ABI stability. - std::unique_ptr> m{std::unique_ptr>(new NoopMeter{})}; - auto t1 = m->NewCounter("Test counter", "For testing", "Unitless", true); - auto t2 = m->NewCounter("Test counter", "For testing", "Unitless", true); - - using M = - std::pair>, int>; - - // (t1, 1) - M t1_pair; - t1_pair.first = t1; - t1_pair.second = 1; + // Test BatchRecord with all supported types + // Create Counter and call RecordBatch for all four supported types: short, int, float, and double - // (t2, 2) - M t2_pair; - t2_pair.first = t2; - t2_pair.second = 2; + std::unique_ptr m{std::unique_ptr(new NoopMeter{})}; - // Create a std::array and use that array to create a span. - std::array arr{t1_pair, t2_pair}; - nostd::span span(arr); + auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); + m->RecordShortBatch({{"Key", "Value"}}, {s}, {1}); - // Create a KeyValueIterableView for labels - std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; - - // Test all versions of RecordBatch - m->RecordBatch(labelkv, span); - m->RecordBatch({{"Key", "Value"}}, span); - m->RecordBatch({{"Key", "Value"}}, {{t1, 1}, {t2, 2}}); -} + auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); + m->RecordIntBatch({{"Key", "Value"}}, {i}, {1}); -TEST(NoopMeter, InstrumentTypes) -{ - std::unique_ptr> m{std::unique_ptr>(new NoopMeter{})}; - - auto counter = - m->NewCounter("Test counter", "For testing", "Unitless", true); - - auto other_counter = - m->NewCounter("Other test counter", "For testing", "Unitless", true); - - std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); + m->RecordFloatBatch({{"Key", "Value"}}, {f}, {1}); - counter->update(1, labelkv); - other_counter->update(1.0, labelkv); + auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); + m->RecordDoubleBatch({{"Key", "Value"}}, {d}, {1}); } OPENTELEMETRY_END_NAMESPACE From a3bd972c554635cc1f0e0353482cc13a4ebe9630 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 21:39:53 -0400 Subject: [PATCH 40/52] Update RecordBatch calls --- api/test/metrics/noop_metrics_test.cc | 50 ++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 2617fb7d52..b225b318fe 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -1,6 +1,7 @@ #include #include "opentelemetry/metrics/noop.h" #include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/metrics/sync_instruments.h" #include @@ -40,16 +41,57 @@ TEST(NoopMeter, RecordBatch) std::unique_ptr m{std::unique_ptr(new NoopMeter{})}; + std::map labels = {{"Key", "Value"}}; + auto labelkv = opentelemetry::trace::KeyValueIterableView{labels}; + auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); - m->RecordShortBatch({{"Key", "Value"}}, {s}, {1}); + + nostd::shared_ptr> + sinstr_arr[] = + {nostd::shared_ptr>(s.get())}; + short svalues_arr[] = {1}; + + nostd::span>> sinstrs + {sinstr_arr}; + nostd::span svalues {svalues_arr}; + + m->RecordShortBatch(labelkv, sinstrs, svalues); auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - m->RecordIntBatch({{"Key", "Value"}}, {i}, {1}); + + nostd::shared_ptr> + iinstr_arr[] = + {nostd::shared_ptr>(i.get())}; + int ivalues_arr[] = {1}; + + nostd::span>> iinstrs + {iinstr_arr}; + nostd::span ivalues {ivalues_arr}; + m->RecordIntBatch(labelkv, iinstrs, ivalues); auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); - m->RecordFloatBatch({{"Key", "Value"}}, {f}, {1}); + + nostd::shared_ptr> + finstr_arr[] = + {nostd::shared_ptr>(f.get())}; + float fvalues_arr[] = {1.0}; + + nostd::span>> + finstrs {finstr_arr}; + nostd::span fvalues {fvalues_arr}; + m->RecordFloatBatch(labelkv, finstrs, fvalues); auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); - m->RecordDoubleBatch({{"Key", "Value"}}, {d}, {1}); + + nostd::shared_ptr> + dinstr_arr[] = + {nostd::shared_ptr>(d.get())}; + double dvalues_arr[] = {1.0}; + + nostd::span>> + dinstrs {dinstr_arr}; + nostd::span dvalues {dvalues_arr}; + m->RecordDoubleBatch(labelkv, dinstrs, dvalues); + } OPENTELEMETRY_END_NAMESPACE From 8a0295d6fdcfd98f480797a0dcd31b8a8a51c382 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 21:40:42 -0400 Subject: [PATCH 41/52] Remove overloaded RecordBatch functions I could not get the counter upcasting to work correctly for some reason. --- api/include/opentelemetry/metrics/meter.h | 44 ----------------------- 1 file changed, 44 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index f2a23b0397..de290ef1d9 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -273,65 +273,21 @@ class Meter nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordShortBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; - - RecordShortBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); - } - virtual void RecordIntBatch( const trace::KeyValueIterable &labels, nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordIntBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; - - RecordIntBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); - } - virtual void RecordFloatBatch( const trace::KeyValueIterable &labels, nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordFloatBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; - - RecordFloatBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); - } - virtual void RecordDoubleBatch( const trace::KeyValueIterable &labels, nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordDoubleBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; - - RecordDoubleBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); - } - }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE From af71ffc75cc7eed2a52fc110f797628e459990aa Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 22:00:49 -0400 Subject: [PATCH 42/52] Undo previous commit Replace overloaded RecordBatch functions. --- api/include/opentelemetry/metrics/meter.h | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index de290ef1d9..f2a23b0397 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -273,21 +273,65 @@ class Meter nostd::span>> instruments, nostd::span values) noexcept = 0; + void RecordShortBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) + { + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordShortBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); + } + virtual void RecordIntBatch( const trace::KeyValueIterable &labels, nostd::span>> instruments, nostd::span values) noexcept = 0; + void RecordIntBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) + { + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordIntBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); + } + virtual void RecordFloatBatch( const trace::KeyValueIterable &labels, nostd::span>> instruments, nostd::span values) noexcept = 0; + void RecordFloatBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) + { + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordFloatBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); + } + virtual void RecordDoubleBatch( const trace::KeyValueIterable &labels, nostd::span>> instruments, nostd::span values) noexcept = 0; + void RecordDoubleBatch(std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) + { + opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + + RecordDoubleBatch(labelskv, + nostd::span>> {instruments.begin(), instruments.end()}, + nostd::span {values.begin(), values.end()}); + } + }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE From 1f72e8b924e2d58d1956558f9caf78a775c6e544 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Sat, 25 Jul 2020 22:01:30 -0400 Subject: [PATCH 43/52] Update RecordBatch parameters --- api/test/metrics/noop_metrics_test.cc | 41 +++------------------------ 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index b225b318fe..abc5c82ac0 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -46,52 +46,19 @@ TEST(NoopMeter, RecordBatch) auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); - nostd::shared_ptr> - sinstr_arr[] = - {nostd::shared_ptr>(s.get())}; - short svalues_arr[] = {1}; - - nostd::span>> sinstrs - {sinstr_arr}; - nostd::span svalues {svalues_arr}; - - m->RecordShortBatch(labelkv, sinstrs, svalues); + m->RecordShortBatch({{"Key", "Value"}}, {s}, {1}); auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - nostd::shared_ptr> - iinstr_arr[] = - {nostd::shared_ptr>(i.get())}; - int ivalues_arr[] = {1}; - - nostd::span>> iinstrs - {iinstr_arr}; - nostd::span ivalues {ivalues_arr}; - m->RecordIntBatch(labelkv, iinstrs, ivalues); + m->RecordIntBatch({{"Key", "Value"}}, {i}, {1}); auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); - nostd::shared_ptr> - finstr_arr[] = - {nostd::shared_ptr>(f.get())}; - float fvalues_arr[] = {1.0}; - - nostd::span>> - finstrs {finstr_arr}; - nostd::span fvalues {fvalues_arr}; - m->RecordFloatBatch(labelkv, finstrs, fvalues); + m->RecordFloatBatch({{"Key," "Value"}}, {f}, {1.0}); auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); - nostd::shared_ptr> - dinstr_arr[] = - {nostd::shared_ptr>(d.get())}; - double dvalues_arr[] = {1.0}; - - nostd::span>> - dinstrs {dinstr_arr}; - nostd::span dvalues {dvalues_arr}; - m->RecordDoubleBatch(labelkv, dinstrs, dvalues); + m->RecordDoubleBatch({{"Key", "Value"}}, {d}, {1.0}); } OPENTELEMETRY_END_NAMESPACE From ff302b4be89be3da24ecd2af50afa8145ec4d8e1 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Tue, 28 Jul 2020 13:10:27 -0400 Subject: [PATCH 44/52] Add explicit casting to RecordBatch tests Note that this is definitely not ideal for users. Making this function more user-friendly is a potential future enhancement to our code. --- api/test/metrics/noop_metrics_test.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index abc5c82ac0..f2516940ce 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -10,6 +10,8 @@ OPENTELEMETRY_BEGIN_NAMESPACE using opentelemetry::metrics::Meter; using opentelemetry::metrics::NoopMeter; +namespace metrics_api = opentelemetry::metrics; + void Callback(opentelemetry::metrics::ObserverResult result) { std::map labels = {{"key", "value"}}; @@ -27,11 +29,11 @@ TEST(NoopTest, CreateInstruments) m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true); m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, - &Callback); + &Callback); m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, - &Callback); - m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback); + m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, + &Callback); } TEST(NoopMeter, RecordBatch) @@ -46,19 +48,27 @@ TEST(NoopMeter, RecordBatch) auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); - m->RecordShortBatch({{"Key", "Value"}}, {s}, {1}); + m->RecordShortBatch({{"Key", "Value"}}, + {nostd::dynamic_pointer_cast>(s)}, + {1}); auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - m->RecordIntBatch({{"Key", "Value"}}, {i}, {1}); + m->RecordIntBatch({{"Key", "Value"}}, + {nostd::dynamic_pointer_cast>(i)}, + {1}); auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); - m->RecordFloatBatch({{"Key," "Value"}}, {f}, {1.0}); + m->RecordFloatBatch({{"Key", "Value"}}, + {nostd::dynamic_pointer_cast>(f)}, + {1.0}); auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); - m->RecordDoubleBatch({{"Key", "Value"}}, {d}, {1.0}); + m->RecordDoubleBatch({{"Key", "Value"}}, + {nostd::dynamic_pointer_cast>(d)}, + {1}); } OPENTELEMETRY_END_NAMESPACE From cf0788e092e74b1c85bb99c6ee7bad6ccb2b24e0 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 29 Jul 2020 16:23:45 -0400 Subject: [PATCH 45/52] Format --- api/include/opentelemetry/metrics/meter.h | 125 ++++++++++++---------- api/include/opentelemetry/metrics/noop.h | 117 +++++++++++--------- api/test/metrics/noop_metrics_test.cc | 13 +-- 3 files changed, 139 insertions(+), 116 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index f2a23b0397..35354d8353 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -36,29 +36,25 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual nostd::shared_ptr> NewShortCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewFloatCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -79,11 +75,10 @@ class Meter nostd::string_view unit, const bool enabled) = 0; - virtual nostd::shared_ptr> NewIntUpDownCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewIntUpDownCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; virtual nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, @@ -116,11 +111,10 @@ class Meter nostd::string_view unit, const bool enabled) = 0; - virtual nostd::shared_ptr> NewIntValueRecorder( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewIntValueRecorder(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; virtual nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, @@ -273,15 +267,19 @@ class Meter nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordShortBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) + void RecordShortBatch( + std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + opentelemetry::trace::KeyValueIterableView< + std::initializer_list>> + labelskv{labels}; RecordShortBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); + nostd::span>>{ + instruments.begin(), instruments.end()}, + nostd::span{values.begin(), values.end()}); } virtual void RecordIntBatch( @@ -289,15 +287,19 @@ class Meter nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordIntBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) + void RecordIntBatch( + std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + opentelemetry::trace::KeyValueIterableView< + std::initializer_list>> + labelskv{labels}; RecordIntBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); + nostd::span>>{ + instruments.begin(), instruments.end()}, + nostd::span{values.begin(), values.end()}); } virtual void RecordFloatBatch( @@ -305,15 +307,19 @@ class Meter nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordFloatBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) + void RecordFloatBatch( + std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + opentelemetry::trace::KeyValueIterableView< + std::initializer_list>> + labelskv{labels}; RecordFloatBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); + nostd::span>>{ + instruments.begin(), instruments.end()}, + nostd::span{values.begin(), values.end()}); } virtual void RecordDoubleBatch( @@ -321,17 +327,20 @@ class Meter nostd::span>> instruments, nostd::span values) noexcept = 0; - void RecordDoubleBatch(std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) + void RecordDoubleBatch( + std::initializer_list> labels, + std::initializer_list>> instruments, + std::initializer_list values) { - opentelemetry::trace::KeyValueIterableView>> labelskv{labels}; + opentelemetry::trace::KeyValueIterableView< + std::initializer_list>> + labelskv{labels}; RecordDoubleBatch(labelskv, - nostd::span>> {instruments.begin(), instruments.end()}, - nostd::span {values.begin(), values.end()}); + nostd::span>>{ + instruments.begin(), instruments.end()}, + nostd::span{values.begin(), values.end()}); } - }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 4140a41ef4..70ee59d46d 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -1,5 +1,6 @@ OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics { +namespace metrics +{ /** * No-op implementation of Meter. This class should not be used directly. */ @@ -18,40 +19,39 @@ class NoopMeter : public Meter * @param enabled a boolean that turns the metric instrument on and off. * @return */ - opentelemetry::nostd::shared_ptr> NewShortCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewFloatCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } /** @@ -70,7 +70,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewIntUpDownCounter( @@ -79,7 +80,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewFloatUpDownCounter( @@ -88,7 +90,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewDoubleUpDownCounter( @@ -97,7 +100,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } /** @@ -116,7 +120,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewIntValueRecorder( @@ -125,7 +130,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewFloatValueRecorder( @@ -134,7 +140,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewDoubleValueRecorder( @@ -143,7 +150,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } /** @@ -163,7 +171,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntSumObserver( @@ -173,7 +182,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatSumObserver( @@ -183,7 +193,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleSumObserver( @@ -193,7 +204,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } /** @@ -213,7 +225,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntUpDownSumObserver( @@ -223,7 +236,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatUpDownSumObserver( @@ -233,7 +247,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleUpDownSumObserver( @@ -243,7 +258,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } /** @@ -263,7 +279,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntValueObserver( @@ -273,7 +290,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatValueObserver( @@ -283,7 +301,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleValueObserver( @@ -293,7 +312,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } /** @@ -313,10 +333,9 @@ class NoopMeter : public Meter // No-op } - void RecordIntBatch( - const trace::KeyValueIterable &labels, - nostd::span>> instruments, - nostd::span values) noexcept override + void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span>> instruments, + nostd::span values) noexcept override { // No-op } diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index f2516940ce..2661d28ea8 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -28,12 +28,9 @@ TEST(NoopTest, CreateInstruments) m->NewIntUpDownCounter("Test ud counter", "For testing", "Unitless", true); m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true); - m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, - &Callback); - m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, - &Callback); - m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, - &Callback); + m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, &Callback); + m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, &Callback); + m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback); } TEST(NoopMeter, RecordBatch) @@ -55,8 +52,7 @@ TEST(NoopMeter, RecordBatch) auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); m->RecordIntBatch({{"Key", "Value"}}, - {nostd::dynamic_pointer_cast>(i)}, - {1}); + {nostd::dynamic_pointer_cast>(i)}, {1}); auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); @@ -69,6 +65,5 @@ TEST(NoopMeter, RecordBatch) m->RecordDoubleBatch({{"Key", "Value"}}, {nostd::dynamic_pointer_cast>(d)}, {1}); - } OPENTELEMETRY_END_NAMESPACE From 33407ddb9509f5ab5ce6415e6135d7ba7938094d Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 29 Jul 2020 21:23:25 -0400 Subject: [PATCH 46/52] Change RecordBatch to remove pointer_casting --- api/include/opentelemetry/metrics/meter.h | 135 +++++++--------------- api/include/opentelemetry/metrics/noop.h | 126 +++++++++----------- api/test/metrics/noop_metrics_test.cc | 42 ++++--- 3 files changed, 124 insertions(+), 179 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 35354d8353..9f23c4e706 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -36,25 +36,29 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual nostd::shared_ptr> NewShortCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewIntCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewFloatCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewShortCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -75,10 +79,11 @@ class Meter nostd::string_view unit, const bool enabled) = 0; - virtual nostd::shared_ptr> NewIntUpDownCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; virtual nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, @@ -111,10 +116,11 @@ class Meter nostd::string_view unit, const bool enabled) = 0; - virtual nostd::shared_ptr> NewIntValueRecorder(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; virtual nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, @@ -259,88 +265,31 @@ class Meter * synchronous metric instruments with a common set of labels. * * @param labels the set of labels to associate with this recorder. - * @param values a span of pairs where the first element of the pair is a metric instrument - * to record to, and the second element is the value to update that instrument with. + * @param instruments a span of pointers to the instruments to record to. + * @param values a span of values to record to the instruments in the corresponding + * position in the instruments span. */ virtual void RecordShortBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, + nostd::span*> instruments, nostd::span values) noexcept = 0; - void RecordShortBatch( - std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView< - std::initializer_list>> - labelskv{labels}; - - RecordShortBatch(labelskv, - nostd::span>>{ - instruments.begin(), instruments.end()}, - nostd::span{values.begin(), values.end()}); - } - virtual void RecordIntBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, + nostd::span*> instruments, nostd::span values) noexcept = 0; - void RecordIntBatch( - std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView< - std::initializer_list>> - labelskv{labels}; - - RecordIntBatch(labelskv, - nostd::span>>{ - instruments.begin(), instruments.end()}, - nostd::span{values.begin(), values.end()}); - } - virtual void RecordFloatBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, + nostd::span*> instruments, nostd::span values) noexcept = 0; - void RecordFloatBatch( - std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView< - std::initializer_list>> - labelskv{labels}; - - RecordFloatBatch(labelskv, - nostd::span>>{ - instruments.begin(), instruments.end()}, - nostd::span{values.begin(), values.end()}); - } - virtual void RecordDoubleBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, + nostd::span*> instruments, nostd::span values) noexcept = 0; - void RecordDoubleBatch( - std::initializer_list> labels, - std::initializer_list>> instruments, - std::initializer_list values) - { - opentelemetry::trace::KeyValueIterableView< - std::initializer_list>> - labelskv{labels}; - - RecordDoubleBatch(labelskv, - nostd::span>>{ - instruments.begin(), instruments.end()}, - nostd::span{values.begin(), values.end()}); - } + }; } // namespace metrics -OPENTELEMETRY_END_NAMESPACE +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 70ee59d46d..8dfd724e3c 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -19,39 +19,40 @@ class NoopMeter : public Meter * @param enabled a boolean that turns the metric instrument on and off. * @return */ - opentelemetry::nostd::shared_ptr> NewShortCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewShortCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ - new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewIntCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewFloatCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewFloatCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ - new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ - new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; } /** @@ -70,8 +71,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewIntUpDownCounter( @@ -80,8 +80,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewFloatUpDownCounter( @@ -90,8 +89,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewDoubleUpDownCounter( @@ -100,8 +98,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; } /** @@ -120,8 +117,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewIntValueRecorder( @@ -130,8 +126,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewFloatValueRecorder( @@ -140,8 +135,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewDoubleValueRecorder( @@ -150,8 +144,7 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ - new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; } /** @@ -171,8 +164,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntSumObserver( @@ -182,8 +174,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatSumObserver( @@ -193,8 +184,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleSumObserver( @@ -204,8 +194,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; } /** @@ -225,8 +214,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntUpDownSumObserver( @@ -236,8 +224,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatUpDownSumObserver( @@ -247,8 +234,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleUpDownSumObserver( @@ -258,8 +244,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } /** @@ -279,8 +264,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntValueObserver( @@ -290,8 +274,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatValueObserver( @@ -301,8 +284,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleValueObserver( @@ -312,8 +294,7 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ - new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; } /** @@ -327,31 +308,32 @@ class NoopMeter : public Meter */ void RecordShortBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, - nostd::span values) noexcept override + nostd::span*> instruments, + nostd::span values) noexcept override { // No-op } - void RecordIntBatch(const trace::KeyValueIterable &labels, - nostd::span>> instruments, - nostd::span values) noexcept override + void RecordIntBatch( + const trace::KeyValueIterable &labels, + nostd::span*> instruments, + nostd::span values) noexcept override { // No-op } void RecordFloatBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, - nostd::span values) noexcept override + nostd::span*> instruments, + nostd::span values) noexcept override { // No-op } void RecordDoubleBatch( const trace::KeyValueIterable &labels, - nostd::span>> instruments, - nostd::span values) noexcept override + nostd::span*> instruments, + nostd::span values) noexcept override { // No-op } diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 2661d28ea8..6262c79e82 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -1,4 +1,5 @@ #include +#include "opentelemetry/metrics/instrument.h" #include "opentelemetry/metrics/noop.h" #include "opentelemetry/metrics/observer_result.h" #include "opentelemetry/metrics/sync_instruments.h" @@ -28,9 +29,12 @@ TEST(NoopTest, CreateInstruments) m->NewIntUpDownCounter("Test ud counter", "For testing", "Unitless", true); m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true); - m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, &Callback); - m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, &Callback); - m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback); + m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, + &Callback); + m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, + &Callback); + m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, + &Callback); } TEST(NoopMeter, RecordBatch) @@ -45,25 +49,35 @@ TEST(NoopMeter, RecordBatch) auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); - m->RecordShortBatch({{"Key", "Value"}}, - {nostd::dynamic_pointer_cast>(s)}, - {1}); + std::array*, 1> siarr{s.get()}; + std::array svarr{1}; + nostd::span*> ssp{siarr}; + nostd::span sval {svarr}; + m->RecordShortBatch(labelkv, ssp, sval); auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - m->RecordIntBatch({{"Key", "Value"}}, - {nostd::dynamic_pointer_cast>(i)}, {1}); + std::array*, 1> iiarr{i.get()}; + std::array ivarr{1}; + nostd::span*> isp{iiarr}; + nostd::span ival {ivarr}; + m->RecordIntBatch(labelkv, isp, ival); auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); - m->RecordFloatBatch({{"Key", "Value"}}, - {nostd::dynamic_pointer_cast>(f)}, - {1.0}); + std::array*, 1> fiarr{f.get()}; + std::array fvarr{1.0f}; + nostd::span*> fsp{fiarr}; + nostd::span fval {fvarr}; + m->RecordFloatBatch(labelkv, fsp, fval); auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); - m->RecordDoubleBatch({{"Key", "Value"}}, - {nostd::dynamic_pointer_cast>(d)}, - {1}); + std::array*, 1> diarr{d.get()}; + std::array dvarr{1.0f}; + nostd::span*> dsp{diarr}; + nostd::span dval {dvarr}; + m->RecordDoubleBatch(labelkv, dsp, dval); + } OPENTELEMETRY_END_NAMESPACE From d4a527b2a1bedf56eda1b12870f18b26c908794d Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Wed, 29 Jul 2020 21:47:13 -0400 Subject: [PATCH 47/52] Format --- api/include/opentelemetry/metrics/meter.h | 90 ++++++-------- api/include/opentelemetry/metrics/noop.h | 137 ++++++++++++---------- api/test/metrics/BUILD | 4 +- api/test/metrics/CMakeLists.txt | 3 +- api/test/metrics/noop_metrics_test.cc | 34 +++--- 5 files changed, 133 insertions(+), 135 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 2da5475aa0..c58c489f2a 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -36,29 +36,25 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual nostd::shared_ptr> NewShortCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewFloatCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; - - virtual nostd::shared_ptr> NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -79,11 +75,10 @@ class Meter nostd::string_view unit, const bool enabled) = 0; - virtual nostd::shared_ptr> NewIntUpDownCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewIntUpDownCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; virtual nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, @@ -116,11 +111,10 @@ class Meter nostd::string_view unit, const bool enabled) = 0; - virtual nostd::shared_ptr> NewIntValueRecorder( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) = 0; + virtual nostd::shared_ptr> NewIntValueRecorder(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; virtual nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, @@ -269,27 +263,21 @@ class Meter * @param values a span of values to record to the instruments in the corresponding * position in the instruments span. */ - virtual void RecordShortBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept = 0; - - virtual void RecordIntBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept = 0; - - virtual void RecordFloatBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept = 0; + virtual void RecordShortBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; - virtual void RecordDoubleBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept = 0; + virtual void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + virtual void RecordFloatBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + virtual void RecordDoubleBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index c14e40a33b..c5569fd4e9 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -277,7 +277,7 @@ class NoopValueRecorder : public ValueRecorder virtual InstrumentKind GetKind() override { return InstrumentKind::ValueRecorder; } }; - + /** * No-op implementation of Meter. This class should not be used directly. */ @@ -296,40 +296,39 @@ class NoopMeter : public Meter * @param enabled a boolean that turns the metric instrument on and off. * @return */ - opentelemetry::nostd::shared_ptr> NewShortCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewFloatCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } - opentelemetry::nostd::shared_ptr> NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override + opentelemetry::nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override { - return nostd::shared_ptr>{ new NoopCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; } /** @@ -348,7 +347,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewIntUpDownCounter( @@ -357,7 +357,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewFloatUpDownCounter( @@ -366,7 +367,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewDoubleUpDownCounter( @@ -375,7 +377,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{new NoopUpDownCounter(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; } /** @@ -394,7 +397,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewIntValueRecorder( @@ -403,7 +407,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewFloatValueRecorder( @@ -412,7 +417,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } opentelemetry::nostd::shared_ptr> NewDoubleValueRecorder( @@ -421,7 +427,8 @@ class NoopMeter : public Meter nostd::string_view unit, const bool enabled) override { - return nostd::shared_ptr>{ new NoopValueRecorder(name, description, unit, enabled)}; + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; } /** @@ -441,7 +448,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntSumObserver( @@ -451,7 +459,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatSumObserver( @@ -461,7 +470,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleSumObserver( @@ -471,7 +481,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; } /** @@ -491,7 +502,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntUpDownSumObserver( @@ -501,7 +513,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatUpDownSumObserver( @@ -511,7 +524,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleUpDownSumObserver( @@ -521,7 +535,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; } /** @@ -541,7 +556,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewIntValueObserver( @@ -551,7 +567,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewFloatValueObserver( @@ -561,7 +578,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } opentelemetry::nostd::shared_ptr> NewDoubleValueObserver( @@ -571,7 +589,8 @@ class NoopMeter : public Meter const bool enabled, void (*callback)(ObserverResult)) override { - return nostd::shared_ptr>{ new NoopValueObserver(name, description, unit, enabled, callback)}; + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; } /** @@ -583,34 +602,30 @@ class NoopMeter : public Meter * @param instrs the instruments to record to. * @param values the value to record to those instruments. */ - void RecordShortBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override + void RecordShortBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override { // No-op } - void RecordIntBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override + void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override { // No-op } - void RecordFloatBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override + void RecordFloatBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override { // No-op } - void RecordDoubleBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override + void RecordDoubleBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override { // No-op } diff --git a/api/test/metrics/BUILD b/api/test/metrics/BUILD index 1c78e5f669..09b4d8018d 100644 --- a/api/test/metrics/BUILD +++ b/api/test/metrics/BUILD @@ -16,12 +16,12 @@ cc_test( srcs = [ "noop_metrics_test.cc", ], - deps = [ + deps = [ "//api", "@com_google_googletest//:gtest_main", ], ) - + cc_test( name = "noop_instrument_test", srcs = [ diff --git a/api/test/metrics/CMakeLists.txt b/api/test/metrics/CMakeLists.txt index 76b82098b4..c9d2083d5a 100644 --- a/api/test/metrics/CMakeLists.txt +++ b/api/test/metrics/CMakeLists.txt @@ -1,5 +1,4 @@ -foreach(testname noop_instrument_test meter_provider_test - noop_metrics_test) +foreach(testname noop_instrument_test meter_provider_test noop_metrics_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc index 6262c79e82..85533e070e 100644 --- a/api/test/metrics/noop_metrics_test.cc +++ b/api/test/metrics/noop_metrics_test.cc @@ -29,12 +29,9 @@ TEST(NoopTest, CreateInstruments) m->NewIntUpDownCounter("Test ud counter", "For testing", "Unitless", true); m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true); - m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, - &Callback); - m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, - &Callback); - m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, - &Callback); + m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, &Callback); + m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, &Callback); + m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback); } TEST(NoopMeter, RecordBatch) @@ -49,35 +46,34 @@ TEST(NoopMeter, RecordBatch) auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); - std::array*, 1> siarr{s.get()}; + std::array *, 1> siarr{s.get()}; std::array svarr{1}; - nostd::span*> ssp{siarr}; - nostd::span sval {svarr}; + nostd::span *> ssp{siarr}; + nostd::span sval{svarr}; m->RecordShortBatch(labelkv, ssp, sval); auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); - std::array*, 1> iiarr{i.get()}; + std::array *, 1> iiarr{i.get()}; std::array ivarr{1}; - nostd::span*> isp{iiarr}; - nostd::span ival {ivarr}; + nostd::span *> isp{iiarr}; + nostd::span ival{ivarr}; m->RecordIntBatch(labelkv, isp, ival); auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); - std::array*, 1> fiarr{f.get()}; + std::array *, 1> fiarr{f.get()}; std::array fvarr{1.0f}; - nostd::span*> fsp{fiarr}; - nostd::span fval {fvarr}; + nostd::span *> fsp{fiarr}; + nostd::span fval{fvarr}; m->RecordFloatBatch(labelkv, fsp, fval); auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); - std::array*, 1> diarr{d.get()}; + std::array *, 1> diarr{d.get()}; std::array dvarr{1.0f}; - nostd::span*> dsp{diarr}; - nostd::span dval {dvarr}; + nostd::span *> dsp{diarr}; + nostd::span dval{dvarr}; m->RecordDoubleBatch(labelkv, dsp, dval); - } OPENTELEMETRY_END_NAMESPACE From 8f05585bb70a62980de8eccc058c5313821969c3 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 30 Jul 2020 16:17:16 -0400 Subject: [PATCH 48/52] Add Meter SDK Stub to pass tests This is necessary because the MeterProvider class (that is already merged into the repo) instantiates this class and the Meter SDK stub in the repo will have unimplemented pure virtual functions if this PR is merged. This stub will be updated with the actual header when the Meter SDK class is merged (pending approval in PR #212). --- sdk/include/opentelemetry/sdk/metrics/meter.h | 188 +++++++++++++++++- 1 file changed, 180 insertions(+), 8 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 9a66adb6d9..61ac0d38c8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -4,25 +4,197 @@ #include "opentelemetry/version.h" #include -#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace metrics { -class Meter final : public opentelemetry::metrics::Meter, public std::enable_shared_from_this +namespace metrics_api = opentelemetry::metrics; +class Meter final : public metrics_api::Meter, public std::enable_shared_from_this { -public: - explicit Meter(std::string library_name, std::string library_version) +explicit Meter(std::string library_name, std::string library_version = "") { - library_name_ = library_name; + library_name_ = library_name; library_version_ = library_version; } -private: - std::string library_name_; - std::string library_version_; + nostd::shared_ptr> NewShortCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewIntCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewFloatCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewDoubleCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewShortUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewShortValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewFloatValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override {} + + nostd::shared_ptr> NewShortSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewFloatSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewDoubleSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewShortUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override{} + + nostd::shared_ptr> NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + + nostd::shared_ptr> NewShortValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewIntValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewFloatValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + nostd::shared_ptr> NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override {} + + void RecordShortBatch( + const trace::KeyValueIterable &labels, + nostd::span*> instruments, + nostd::span values) noexcept override {} + + void RecordIntBatch( + const trace::KeyValueIterable &labels, + nostd::span*> instruments, + nostd::span values) noexcept override {} + + void RecordFloatBatch( + const trace::KeyValueIterable &labels, + nostd::span*> instruments, + nostd::span values) noexcept override {} + + void RecordDoubleBatch( + const trace::KeyValueIterable &labels, + nostd::span*> instruments, + nostd::span values) noexcept override {} }; } // namespace metrics } // namespace sdk From 6391b48301b92dd67522bbcfcdc937f1ecbe4377 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 30 Jul 2020 16:21:21 -0400 Subject: [PATCH 49/52] Add private vars --- sdk/include/opentelemetry/sdk/metrics/meter.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 61ac0d38c8..dbfb5bcce0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -13,7 +13,8 @@ namespace metrics namespace metrics_api = opentelemetry::metrics; class Meter final : public metrics_api::Meter, public std::enable_shared_from_this { -explicit Meter(std::string library_name, std::string library_version = "") +public: + explicit Meter(std::string library_name, std::string library_version = "") { library_name_ = library_name; library_version_ = library_version; @@ -195,6 +196,9 @@ explicit Meter(std::string library_name, std::string library_version = "") const trace::KeyValueIterable &labels, nostd::span*> instruments, nostd::span values) noexcept override {} +private: + std::string library_name_; + std::string library_version_; }; } // namespace metrics } // namespace sdk From e9a11fa65ca2b521ccaba1cb505aeedbec2a9d79 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 30 Jul 2020 16:25:04 -0400 Subject: [PATCH 50/52] Format --- sdk/include/opentelemetry/sdk/metrics/meter.h | 150 ++++++++++-------- 1 file changed, 85 insertions(+), 65 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index dbfb5bcce0..2104e1055f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -16,186 +16,206 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th public: explicit Meter(std::string library_name, std::string library_version = "") { - library_name_ = library_name; + library_name_ = library_name; library_version_ = library_version; } - nostd::shared_ptr> NewShortCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override {} - - nostd::shared_ptr> NewIntCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override {} - - nostd::shared_ptr> NewFloatCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override {} - - nostd::shared_ptr> NewDoubleCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled) override {} + nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + {} + + nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + {} + + nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + {} + + nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + {} nostd::shared_ptr> NewShortUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewShortValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, - const bool enabled) override {} + const bool enabled) override + {} nostd::shared_ptr> NewShortSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewIntSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewFloatSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewDoubleSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewShortUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override{} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewIntUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewFloatUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewDoubleUpDownSumObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} - + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewShortValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewIntValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewFloatValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} + void (*callback)(metrics_api::ObserverResult)) override + {} nostd::shared_ptr> NewDoubleValueObserver( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(metrics_api::ObserverResult)) override {} - - void RecordShortBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override {} - - void RecordIntBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override {} - - void RecordFloatBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override {} - - void RecordDoubleBatch( - const trace::KeyValueIterable &labels, - nostd::span*> instruments, - nostd::span values) noexcept override {} + void (*callback)(metrics_api::ObserverResult)) override + {} + + void RecordShortBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + + void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + + void RecordFloatBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + + void RecordDoubleBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + private: std::string library_name_; std::string library_version_; From 45c0f74c108edbe833383eb86b1f3c81a42bca11 Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 30 Jul 2020 16:49:31 -0400 Subject: [PATCH 51/52] Add stub returns to pass CI --- sdk/include/opentelemetry/sdk/metrics/meter.h | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 2104e1055f..88107400ad 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -24,81 +24,81 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewIntCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewFloatCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewShortUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewShortValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewShortSumObserver( nostd::string_view name, @@ -106,7 +106,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewIntSumObserver( nostd::string_view name, @@ -114,7 +114,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewFloatSumObserver( nostd::string_view name, @@ -122,7 +122,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewDoubleSumObserver( nostd::string_view name, @@ -130,7 +130,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewShortUpDownSumObserver( nostd::string_view name, @@ -138,7 +138,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewIntUpDownSumObserver( nostd::string_view name, @@ -146,7 +146,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewFloatUpDownSumObserver( nostd::string_view name, @@ -154,7 +154,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewDoubleUpDownSumObserver( nostd::string_view name, @@ -162,7 +162,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewShortValueObserver( nostd::string_view name, @@ -170,7 +170,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewIntValueObserver( nostd::string_view name, @@ -178,7 +178,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewFloatValueObserver( nostd::string_view name, @@ -186,7 +186,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} nostd::shared_ptr> NewDoubleValueObserver( nostd::string_view name, @@ -194,7 +194,7 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {} + {return nostd::shared_ptr>(nullptr);} void RecordShortBatch(const trace::KeyValueIterable &labels, nostd::span *> instruments, From cb737d1586740fdcfc107237a64ef6f55e29a77d Mon Sep 17 00:00:00 2001 From: Brandon Kimberly Date: Thu, 30 Jul 2020 16:51:19 -0400 Subject: [PATCH 52/52] Format --- sdk/include/opentelemetry/sdk/metrics/meter.h | 96 ++++++++++++++----- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 88107400ad..ccb96ea804 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -24,81 +24,105 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewIntCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewFloatCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewShortUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewIntUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewFloatUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewDoubleUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewShortValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewIntValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewFloatValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewDoubleValueRecorder( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewShortSumObserver( nostd::string_view name, @@ -106,7 +130,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewIntSumObserver( nostd::string_view name, @@ -114,7 +140,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewFloatSumObserver( nostd::string_view name, @@ -122,7 +150,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewDoubleSumObserver( nostd::string_view name, @@ -130,7 +160,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewShortUpDownSumObserver( nostd::string_view name, @@ -138,7 +170,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewIntUpDownSumObserver( nostd::string_view name, @@ -146,7 +180,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewFloatUpDownSumObserver( nostd::string_view name, @@ -154,7 +190,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewDoubleUpDownSumObserver( nostd::string_view name, @@ -162,7 +200,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewShortValueObserver( nostd::string_view name, @@ -170,7 +210,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewIntValueObserver( nostd::string_view name, @@ -178,7 +220,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewFloatValueObserver( nostd::string_view name, @@ -186,7 +230,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } nostd::shared_ptr> NewDoubleValueObserver( nostd::string_view name, @@ -194,7 +240,9 @@ class Meter final : public metrics_api::Meter, public std::enable_shared_from_th nostd::string_view unit, const bool enabled, void (*callback)(metrics_api::ObserverResult)) override - {return nostd::shared_ptr>(nullptr);} + { + return nostd::shared_ptr>(nullptr); + } void RecordShortBatch(const trace::KeyValueIterable &labels, nostd::span *> instruments,