// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_METRICS_PREVIEW # include # include # include # include # include "opentelemetry/_metrics/noop.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics { void noopIntCallback(ObserverResult result) { std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; result.observe(1, labelkv); result.observe(-1, labelkv); } void noopDoubleCallback(ObserverResult result) { std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; result.observe(1.5, labelkv); result.observe(-1.5, labelkv); } TEST(ValueObserver, Observe) { NoopValueObserver alpha("test", "none", "unitless", true, &noopIntCallback); NoopValueObserver beta("test", "none", "unitless", true, &noopDoubleCallback); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.observe(1, labelkv); beta.observe(1.5, labelkv); } TEST(SumObserver, DefaultConstruction) { NoopSumObserver alpha("test", "none", "unitless", true, &noopIntCallback); NoopSumObserver beta("test", "none", "unitless", true, &noopDoubleCallback); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.observe(1, labelkv); beta.observe(1.5, labelkv); } TEST(UpDownSumObserver, DefaultConstruction) { NoopUpDownSumObserver alpha("test", "none", "unitless", true, &noopIntCallback); NoopUpDownSumObserver beta("test", "none", "unitless", true, &noopDoubleCallback); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.observe(1, labelkv); beta.observe(1.0, labelkv); alpha.observe(-1, labelkv); beta.observe(-1.0, labelkv); } TEST(Counter, DefaultConstruction) { NoopCounter alpha("test", "none", "unitless", true); NoopCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.bind(labelkv); auto gamma = alpha.bindNoopCounter(labelkv); auto delta = beta.bindNoopCounter(labelkv); gamma->unbind(); delta->unbind(); } TEST(Counter, Add) { NoopCounter alpha("test", "none", "unitless", true); NoopCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.add(1, labelkv); beta.add(1.5, labelkv); auto gamma = alpha.bindNoopCounter(labelkv); auto delta = beta.bindNoopCounter(labelkv); gamma->add(1); delta->add(1.5); gamma->unbind(); delta->unbind(); } TEST(UpDownCounter, DefaultConstruction) { NoopUpDownCounter alpha("test", "none", "unitless", true); NoopUpDownCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.bind(labelkv); auto gamma = alpha.bindNoopUpDownCounter(labelkv); auto delta = beta.bindNoopUpDownCounter(labelkv); gamma->unbind(); delta->unbind(); } TEST(UpDownCounter, Add) { NoopUpDownCounter alpha("test", "none", "unitless", true); NoopUpDownCounter beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.add(1, labelkv); beta.add(1.5, labelkv); auto gamma = alpha.bindNoopUpDownCounter(labelkv); auto delta = beta.bindNoopUpDownCounter(labelkv); gamma->add(1); delta->add(1.0); gamma->add(-1); delta->add(-1.0); gamma->unbind(); delta->unbind(); } TEST(ValueRecorder, DefaultConstruction) { NoopValueRecorder alpha("test", "none", "unitless", true); NoopValueRecorder beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.bind(labelkv); auto gamma = alpha.bindNoopValueRecorder(labelkv); auto delta = beta.bindNoopValueRecorder(labelkv); gamma->unbind(); delta->unbind(); } TEST(ValueRecorder, Record) { NoopValueRecorder alpha("test", "none", "unitless", true); NoopValueRecorder beta("other", "none", "unitless", true); std::map labels = {{"key", "value"}}; auto labelkv = common::KeyValueIterableView{labels}; alpha.record(1, labelkv); beta.record(1.5, labelkv); auto gamma = alpha.bindNoopValueRecorder(labelkv); auto delta = beta.bindNoopValueRecorder(labelkv); gamma->record(1); delta->record(1.5); gamma->unbind(); delta->unbind(); } } // namespace metrics OPENTELEMETRY_END_NAMESPACE #endif