From 07bde3826d6e6952ea2ec7c2805c4b43ad0042e3 Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Mon, 20 Jul 2020 12:20:38 -0400 Subject: [PATCH] cleaning up for PR --- .../opentelemetry/metrics/async_instruments.h | 24 +- .../opentelemetry/metrics/instrument.h | 29 +-- api/include/opentelemetry/metrics/noop.h | 213 ++++++++++++------ .../opentelemetry/metrics/observer_result.h | 1 + .../opentelemetry/metrics/sync_instruments.h | 37 +-- api/test/metrics/noop_instrument_test.cc | 24 +- 6 files changed, 196 insertions(+), 132 deletions(-) diff --git a/api/include/opentelemetry/metrics/async_instruments.h b/api/include/opentelemetry/metrics/async_instruments.h index 53e1d2f17e..37ce7da900 100644 --- a/api/include/opentelemetry/metrics/async_instruments.h +++ b/api/include/opentelemetry/metrics/async_instruments.h @@ -15,10 +15,10 @@ class ValueObserver : public AsynchronousInstrument ValueObserver() = default; ValueObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled, - void (*callback)(ObserverResult)) + nostd::string_view description, + nostd::string_view unit, + bool enabled, + void (*callback)(ObserverResult)) {} /* @@ -39,10 +39,10 @@ class SumObserver : public AsynchronousInstrument SumObserver() = default; SumObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled, - void (*callback)(ObserverResult)) + nostd::string_view description, + nostd::string_view unit, + bool enabled, + void (*callback)(ObserverResult)) {} /* @@ -64,10 +64,10 @@ class UpDownSumObserver : public AsynchronousInstrument UpDownSumObserver() = default; UpDownSumObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled, - void (*callback)(ObserverResult)) + nostd::string_view description, + nostd::string_view unit, + bool enabled, + void (*callback)(ObserverResult)) {} virtual void observe(int value, const trace::KeyValueIterable &labels) {} diff --git a/api/include/opentelemetry/metrics/instrument.h b/api/include/opentelemetry/metrics/instrument.h index 2d3915feb5..3e57bd735a 100644 --- a/api/include/opentelemetry/metrics/instrument.h +++ b/api/include/opentelemetry/metrics/instrument.h @@ -12,29 +12,12 @@ namespace metrics // Enum classes to help determine instrument types in other parts of the API enum class InstrumentKind { - IntCounter, - IntUpDownCounter, - IntValueRecorder, - IntValueObserver, - IntSumObserver, - IntUpDownSumObserver, - DoubleCounter, - DoubleUpDownCounter, - DoubleValueRecorder, - DoubleValueObserver, - DoubleSumObserver, - DoubleUpDownSumObserver -}; - -// Fewer Bound types because Asynchronous instruments cannot bind -enum class BoundInstrumentKind -{ - BoundIntCounter, - BoundIntUpDownCounter, - BoundIntValueRecorder, - BoundDoubleCounter, - BoundDoubleUpDownCounter, - BoundDoubleValueRecorder + Counter = 0, + UpDownCounter = 1, + ValueRecorder = 2, + ValueObserver = 3, + SumObserver = 4, + UpDownSumObserver = 5, }; class Instrument diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 7b12e61f1a..373691318c 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -12,63 +12,90 @@ class NoopValueObserver : public ValueObserver public: NoopValueObserver(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/, - void (*callback)(ObserverResult)) - {} + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/, + void (*callback)(ObserverResult)) {} + + virtual bool IsEnabled() override { + return false; + } - virtual bool IsEnabled() override { return false; } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } }; + template class NoopSumObserver : public SumObserver { public: NoopSumObserver(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/, - void (*callback)(ObserverResult)) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/, + void (*callback)(ObserverResult)) {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } }; + template class NoopUpDownSumObserver : public UpDownSumObserver { public: NoopUpDownSumObserver(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/, - void (*callback)(ObserverResult)) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/, + void (*callback)(ObserverResult)) {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } }; + template class BoundNoopCounter : public BoundCounter { @@ -77,20 +104,29 @@ class BoundNoopCounter : public BoundCounter BoundNoopCounter() = default; BoundNoopCounter(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/) {} virtual void add(T value) override {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } + + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } }; template @@ -101,9 +137,9 @@ class NoopCounter : public Counter NoopCounter() = default; NoopCounter(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/) {} nostd::shared_ptr> bind(const trace::KeyValueIterable & /*labels*/) @@ -113,13 +149,22 @@ class NoopCounter : public Counter virtual void add(T value, const trace::KeyValueIterable & /*labels*/) override {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } + + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } }; template @@ -130,20 +175,29 @@ class BoundNoopUpDownCounter : public BoundUpDownCounter BoundNoopUpDownCounter() = default; BoundNoopUpDownCounter(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/) {} virtual void add(T value) override {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } + + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } }; template @@ -154,9 +208,9 @@ class NoopUpDownCounter : public UpDownCounter NoopUpDownCounter() = default; NoopUpDownCounter(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/) {} nostd::shared_ptr> bind(const trace::KeyValueIterable & /*labels*/) @@ -166,15 +220,24 @@ class NoopUpDownCounter : public UpDownCounter virtual void add(T value, const trace::KeyValueIterable & /*labels*/) override {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } }; + template class BoundNoopValueRecorder : public BoundValueRecorder { @@ -183,20 +246,28 @@ class BoundNoopValueRecorder : public BoundValueRecorder BoundNoopValueRecorder() = default; BoundNoopValueRecorder(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/) {} virtual void record(T value) override {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } }; template @@ -207,9 +278,9 @@ class NoopValueRecorder : public ValueRecorder NoopValueRecorder() = default; NoopValueRecorder(nostd::string_view /*name*/, - nostd::string_view /*description*/, - nostd::string_view /*unit*/, - bool /*enabled*/) + nostd::string_view /*description*/, + nostd::string_view /*unit*/, + bool /*enabled*/) {} nostd::shared_ptr> bind(const trace::KeyValueIterable & /*labels*/) @@ -219,13 +290,21 @@ class NoopValueRecorder : public ValueRecorder virtual void record(T value, const trace::KeyValueIterable & /*labels*/) override {} - virtual bool IsEnabled() override { return false; } + virtual bool IsEnabled() override { + return false; + } - virtual nostd::string_view GetName() override { return nostd::string_view(""); } + virtual nostd::string_view GetName() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetDescription() override { return nostd::string_view(""); } + virtual nostd::string_view GetDescription() override { + return nostd::string_view(""); + } - virtual nostd::string_view GetUnits() override { return nostd::string_view(""); } + virtual nostd::string_view GetUnits() override { + return nostd::string_view(""); + } }; } // namespace metrics diff --git a/api/include/opentelemetry/metrics/observer_result.h b/api/include/opentelemetry/metrics/observer_result.h index 3a7bfc9df8..bb61e97bf9 100644 --- a/api/include/opentelemetry/metrics/observer_result.h +++ b/api/include/opentelemetry/metrics/observer_result.h @@ -24,6 +24,7 @@ class ObserverResult ObserverResult(nostd::shared_ptr> instrument) {} virtual void observe(T value, const trace::KeyValueIterable &labels) {} + }; } // namespace metrics diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index d8ddc98122..8a36005e9f 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -14,9 +14,9 @@ class BoundCounter : public BoundSynchronousInstrument BoundCounter() = default; BoundCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled); + nostd::string_view description, + nostd::string_view unit, + bool enabled); /* * Add adds the value to the counter's sum. The labels are already linked * to the instrument @@ -36,9 +36,9 @@ class Counter : public SynchronousInstrument Counter() = default; Counter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled); + nostd::string_view description, + nostd::string_view unit, + bool enabled); /* * Bind creates a bound instrument for this counter. The labels are @@ -68,9 +68,9 @@ class BoundUpDownCounter : public BoundSynchronousInstrument BoundUpDownCounter() = default; BoundUpDownCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled); + nostd::string_view description, + nostd::string_view unit, + bool enabled); /* * Add adds the value to the counter's sum. The labels are already linked to * the instrument and @@ -90,9 +90,9 @@ class UpDownCounter : public SynchronousInstrument UpDownCounter() = default; UpDownCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled); + nostd::string_view description, + nostd::string_view unit, + bool enabled); nostd::shared_ptr> bind(const trace::KeyValueIterable &labels); //{ @@ -118,9 +118,9 @@ class BoundValueRecorder : public BoundSynchronousInstrument BoundValueRecorder() = default; BoundValueRecorder(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled); + nostd::string_view description, + nostd::string_view unit, + bool enabled); /* * Records the value by summing it with previous measurements and checking * previously stored @@ -132,6 +132,7 @@ class BoundValueRecorder : public BoundSynchronousInstrument virtual void record(T value) = 0; }; + template class ValueRecorder : public SynchronousInstrument { @@ -140,9 +141,9 @@ class ValueRecorder : public SynchronousInstrument ValueRecorder() = default; ValueRecorder(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled); + nostd::string_view description, + nostd::string_view unit, + bool enabled); nostd::shared_ptr> bind(const trace::KeyValueIterable &labels); //{ diff --git a/api/test/metrics/noop_instrument_test.cc b/api/test/metrics/noop_instrument_test.cc index 7b693046d7..b68206059f 100644 --- a/api/test/metrics/noop_instrument_test.cc +++ b/api/test/metrics/noop_instrument_test.cc @@ -1,8 +1,8 @@ #include #include -#include #include #include "opentelemetry/metrics/noop.h" +#include OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics @@ -11,7 +11,7 @@ namespace metrics void noopIntCallback(ObserverResult result) { std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; result.observe(1, labelkv); result.observe(-1, labelkv); } @@ -19,7 +19,7 @@ void noopIntCallback(ObserverResult result) void noopDoubleCallback(ObserverResult result) { std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; result.observe(1.5, labelkv); result.observe(-1.5, labelkv); } @@ -31,7 +31,7 @@ TEST(ValueObserver, Observe) NoopValueObserver beta("test", "none", "unitless", true, &noopDoubleCallback); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.observe(1, labelkv); beta.observe(1.5, labelkv); @@ -44,7 +44,7 @@ TEST(SumObserver, DefaultConstruction) NoopSumObserver beta("test", "none", "unitless", true, &noopDoubleCallback); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.observe(1, labelkv); beta.observe(1.5, labelkv); @@ -57,7 +57,7 @@ TEST(UpDownSumObserver, DefaultConstruction) NoopUpDownSumObserver beta("test", "none", "unitless", true, &noopDoubleCallback); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.observe(1, labelkv); beta.observe(1.0, labelkv); @@ -71,7 +71,7 @@ TEST(Counter, DefaultConstruction) NoopCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.bind(labelkv); @@ -88,7 +88,7 @@ TEST(Counter, Add) NoopCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.add(1, labelkv); beta.add(1.5, labelkv); @@ -109,7 +109,7 @@ TEST(UpDownCounter, DefaultConstruction) NoopUpDownCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.bind(labelkv); @@ -126,7 +126,7 @@ TEST(UpDownCounter, Add) NoopUpDownCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.add(1, labelkv); beta.add(1.5, labelkv); @@ -149,7 +149,7 @@ TEST(ValueRecorder, DefaultConstruction) NoopValueRecorder beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.bind(labelkv); @@ -166,7 +166,7 @@ TEST(ValueRecorder, Record) NoopValueRecorder beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; - auto labelkv = trace::KeyValueIterableView{labels}; + auto labelkv = trace::KeyValueIterableView{labels}; alpha.record(1, labelkv); beta.record(1.5, labelkv);