]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/metrics/MetricsTest.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / metrics / MetricsTest.cpp
CommitLineData
f67539c2
TL
1/*
2 * Copyright (c) 2017 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "jaegertracing/metrics/Counter.h"
18#include "jaegertracing/metrics/Gauge.h"
19#include "jaegertracing/metrics/InMemoryStatsReporter.h"
20#include "jaegertracing/metrics/Metrics.h"
21#include "jaegertracing/metrics/StatsFactoryImpl.h"
22#include "jaegertracing/metrics/Timer.h"
23#include <cstdint>
24#include <gtest/gtest.h>
25#include <iterator>
26#include <memory>
27#include <unordered_map>
28#include <utility>
29
30namespace jaegertracing {
31namespace metrics {
32
33class MetricsTest : public ::testing::Test {
34 public:
35 MetricsTest()
36 : _metricsReporter()
37 , _metrics(Metrics::fromStatsReporter(_metricsReporter))
38 {
39 }
40
41 protected:
42 InMemoryStatsReporter _metricsReporter;
43 std::unique_ptr<Metrics> _metrics;
44};
45
46TEST_F(MetricsTest, testCounter)
47{
48 constexpr auto counterValue = static_cast<int64_t>(3);
49 constexpr auto metricName = "jaeger.test-counter";
50 StatsFactoryImpl factory(_metricsReporter);
51 auto counter = factory.createCounter(metricName);
52 counter->inc(counterValue);
53 const auto& counters = _metricsReporter.counters();
54 ASSERT_EQ(1, counters.size());
55 auto itr = counters.find(metricName);
56 ASSERT_TRUE(itr != std::end(counters));
57 ASSERT_EQ(counterValue, itr->second);
58}
59
60TEST_F(MetricsTest, testGauge)
61{
62 constexpr auto gaugeValue = static_cast<int64_t>(3);
63 constexpr auto metricName = "jaeger.test-gauge";
64 StatsFactoryImpl factory(_metricsReporter);
65 auto gauge = factory.createGauge(metricName);
66 gauge->update(gaugeValue);
67 const auto& gauges = _metricsReporter.gauges();
68 ASSERT_EQ(1, gauges.size());
69 auto itr = gauges.find(metricName);
70 ASSERT_TRUE(itr != std::end(gauges));
71 ASSERT_EQ(gaugeValue, itr->second);
72}
73
74TEST_F(MetricsTest, testTimer)
75{
76 constexpr auto timeValue = static_cast<int64_t>(5);
77 constexpr auto metricName = "jaeger.test-timer";
78 StatsFactoryImpl factory(_metricsReporter);
79 auto timer = factory.createTimer(metricName);
80 timer->record(timeValue);
81 const auto& timers = _metricsReporter.timers();
82 ASSERT_EQ(1, timers.size());
83 auto itr = timers.find(metricName);
84 ASSERT_TRUE(itr != std::end(timers));
85 ASSERT_EQ(timeValue, itr->second);
86}
87
88TEST_F(MetricsTest, testReset)
89{
90 _metrics->tracesStartedSampled().inc(1);
91 const auto& counters = _metricsReporter.counters();
92 ASSERT_EQ(1, counters.size());
93
94 _metrics->reporterQueueLength().update(1);
95 const auto& gauges = _metricsReporter.gauges();
96 ASSERT_EQ(1, gauges.size());
97
98 constexpr auto time = static_cast<int64_t>(1);
99 constexpr auto timerName = "jaeger.test-timer";
100 _metricsReporter.recordTimer(timerName, time);
101 const auto& timers = _metricsReporter.timers();
102 ASSERT_EQ(1, timers.size());
103
104 _metricsReporter.reset();
105 ASSERT_TRUE(counters.empty());
106 ASSERT_TRUE(gauges.empty());
107 ASSERT_TRUE(timers.empty());
108}
109
110} // namespace metrics
111} // namespace jaegertracing