]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/api/test/_metrics/noop_metrics_test.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / api / test / _metrics / noop_metrics_test.cc
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #ifdef ENABLE_METRICS_PREVIEW
5 # include <gtest/gtest.h>
6 # include "opentelemetry/_metrics/instrument.h"
7 # include "opentelemetry/_metrics/noop.h"
8 # include "opentelemetry/_metrics/observer_result.h"
9 # include "opentelemetry/_metrics/sync_instruments.h"
10
11 # include <array>
12 # include <memory>
13
14 OPENTELEMETRY_BEGIN_NAMESPACE
15
16 using opentelemetry::metrics::Meter;
17 using opentelemetry::metrics::NoopMeter;
18
19 void Callback(opentelemetry::metrics::ObserverResult<int> result)
20 {
21 std::map<std::string, std::string> labels = {{"key", "value"}};
22 auto labelkv = common::KeyValueIterableView<decltype(labels)>{labels};
23 result.observe(1, labelkv);
24 }
25
26 TEST(NoopTest, CreateInstruments)
27 {
28 auto m = std::unique_ptr<Meter>(new NoopMeter{});
29
30 // Test instrument constructors
31 m->NewIntCounter("Test counter", "For testing", "Unitless", true);
32 m->NewIntUpDownCounter("Test ud counter", "For testing", "Unitless", true);
33 m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true);
34
35 m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, &Callback);
36 m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, &Callback);
37 m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback);
38 }
39
40 TEST(NoopMeter, RecordBatch)
41 {
42 // Test BatchRecord with all supported types
43 // Create Counter and call RecordBatch for all four supported types: short, int, float, and double
44
45 std::unique_ptr<Meter> m{std::unique_ptr<Meter>(new NoopMeter{})};
46
47 std::map<std::string, std::string> labels = {{"Key", "Value"}};
48 auto labelkv = opentelemetry::common::KeyValueIterableView<decltype(labels)>{labels};
49
50 auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true);
51
52 std::array<metrics::SynchronousInstrument<short> *, 1> siarr{s.get()};
53 std::array<short, 1> svarr{1};
54 nostd::span<metrics::SynchronousInstrument<short> *> ssp{siarr};
55 nostd::span<short> sval{svarr};
56 m->RecordShortBatch(labelkv, ssp, sval);
57
58 auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true);
59
60 std::array<metrics::SynchronousInstrument<int> *, 1> iiarr{i.get()};
61 std::array<int, 1> ivarr{1};
62 nostd::span<metrics::SynchronousInstrument<int> *> isp{iiarr};
63 nostd::span<int> ival{ivarr};
64 m->RecordIntBatch(labelkv, isp, ival);
65
66 auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true);
67
68 std::array<metrics::SynchronousInstrument<float> *, 1> fiarr{f.get()};
69 std::array<float, 1> fvarr{1.0f};
70 nostd::span<metrics::SynchronousInstrument<float> *> fsp{fiarr};
71 nostd::span<float> fval{fvarr};
72 m->RecordFloatBatch(labelkv, fsp, fval);
73
74 auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true);
75
76 std::array<metrics::SynchronousInstrument<double> *, 1> diarr{d.get()};
77 std::array<double, 1> dvarr{1.0f};
78 nostd::span<metrics::SynchronousInstrument<double> *> dsp{diarr};
79 nostd::span<double> dval{dvarr};
80 m->RecordDoubleBatch(labelkv, dsp, dval);
81 }
82 OPENTELEMETRY_END_NAMESPACE
83 #endif