1 #include "artdaq-utilities/Plugins/MetricPlugin.hh"
2 #include "artdaq-utilities/Plugins/TestMetric.hh"
4 #define BOOST_TEST_MODULES MetricPlugin_t
5 #include "cetlib/quiet_unit_test.hpp"
6 #include "cetlib_except/exception.h"
7 #include "fhiclcpp/make_ParameterSet.h"
11 namespace artdaqtest {
17 , sendMetric_string_calls(0)
18 , sendMetric_int_calls(0)
19 , sendMetric_double_calls(0)
20 , sendMetric_float_calls(0)
21 , sendMetric_unsigned_calls(0)
22 , startMetrics_calls(0)
23 , stopMetrics_calls(0)
26 virtual void sendMetric_(
const std::string&,
const std::string&,
const std::string&)
override { sendMetric_string_calls++; }
27 virtual void sendMetric_(
const std::string&,
const int&,
const std::string&)
override { sendMetric_int_calls++; }
28 virtual void sendMetric_(
const std::string&,
const double&,
const std::string&)
override { sendMetric_double_calls++; }
29 virtual void sendMetric_(
const std::string&,
const float&,
const std::string&)
override { sendMetric_float_calls++; }
30 virtual void sendMetric_(
const std::string&,
const long unsigned int&,
const std::string&)
override { sendMetric_unsigned_calls++; }
35 size_t sendMetric_string_calls;
36 size_t sendMetric_int_calls;
37 size_t sendMetric_double_calls;
38 size_t sendMetric_float_calls;
39 size_t sendMetric_unsigned_calls;
40 size_t startMetrics_calls;
41 size_t stopMetrics_calls;
44 fhicl::ParameterSet get_pset() {
return pset; }
46 std::string get_app_name_() {
return app_name_; }
47 bool get_inhibit_() {
return inhibit_; }
48 std::bitset<64> get_level_mask_() {
return level_mask_; }
52 BOOST_AUTO_TEST_SUITE(MetricPlugin_test)
54 BOOST_AUTO_TEST_CASE(Constructor)
56 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case Constructor BEGIN";
57 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
58 fhicl::ParameterSet pset;
59 fhicl::make_ParameterSet(testConfig, pset);
61 BOOST_REQUIRE_EQUAL(mpta.get_pset().to_string(), pset.to_string());
62 BOOST_REQUIRE_EQUAL(mpta.get_accumulationTime_(), 0.0);
63 BOOST_REQUIRE_EQUAL(mpta.get_level_mask_()[8],
true);
64 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(8),
true);
65 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case Constructor END";
68 BOOST_AUTO_TEST_CASE(IsLevelEnabled)
70 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case IsLevelEnabled BEGIN";
71 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
72 fhicl::ParameterSet pset;
73 fhicl::make_ParameterSet(testConfig, pset);
76 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(0),
true);
77 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(1),
true);
78 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(2),
true);
79 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(3),
true);
80 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(4),
true);
81 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(5),
false);
82 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(6),
false);
83 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(7),
true);
84 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(8),
true);
85 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(9),
true);
86 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(10),
false);
87 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(11),
true);
88 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(12),
false);
89 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(13),
true);
90 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(14),
true);
91 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(15),
true);
92 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(16),
false);
93 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(17),
true);
94 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(18),
false);
95 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(19),
true);
96 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(20),
true);
97 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(21),
true);
98 BOOST_REQUIRE_EQUAL(mpta.IsLevelEnabled(22),
false);
100 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case IsLevelEnabled END";
103 BOOST_AUTO_TEST_CASE(LibraryName)
105 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case LibraryName BEGIN";
106 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
107 fhicl::ParameterSet pset;
108 fhicl::make_ParameterSet(testConfig, pset);
111 BOOST_REQUIRE_EQUAL(mpta.getLibName(),
"ERROR");
112 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case LibraryName END";
115 BOOST_AUTO_TEST_CASE(AddMetricData)
117 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case AddMetricData BEGIN";
118 std::string testConfig =
"reporting_interval: 1.0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
119 fhicl::ParameterSet pset;
120 fhicl::make_ParameterSet(testConfig, pset);
129 mpta.addMetricData(smd);
130 mpta.addMetricData(imd);
131 mpta.addMetricData(fmd);
132 mpta.addMetricData(dmd);
133 mpta.addMetricData(umd);
135 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
136 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
137 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
138 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
139 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
141 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case AddMetricData END";
144 BOOST_AUTO_TEST_CASE(SendMetrics)
146 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case SendMetrics BEGIN";
147 std::string testConfig =
"reporting_interval: 0.01 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
148 fhicl::ParameterSet pset;
149 fhicl::make_ParameterSet(testConfig, pset);
158 mpta.addMetricData(smd);
159 mpta.addMetricData(imd);
160 mpta.addMetricData(fmd);
161 mpta.addMetricData(dmd);
162 mpta.addMetricData(umd);
164 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
165 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
166 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
167 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
168 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
172 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
173 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
174 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
175 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
176 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
178 mpta.addMetricData(smd);
179 mpta.addMetricData(imd);
180 mpta.addMetricData(fmd);
181 mpta.addMetricData(dmd);
182 mpta.addMetricData(umd);
184 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
185 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
186 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
187 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
188 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
192 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
193 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 1);
194 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 1);
195 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 1);
196 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 1);
202 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 2);
203 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 2);
204 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 2);
205 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 2);
206 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 2);
208 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case SendMetrics END";
211 BOOST_AUTO_TEST_CASE(StartMetrics)
213 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StartMetrics BEGIN";
214 std::string testConfig =
"reporting_interval: 0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
215 fhicl::ParameterSet pset;
216 fhicl::make_ParameterSet(testConfig, pset);
220 BOOST_REQUIRE_EQUAL(mpta.startMetrics_calls, 1);
221 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StartMetrics END";
224 BOOST_AUTO_TEST_CASE(StopMetrics)
226 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StopMetrics BEGIN";
227 std::string testConfig =
"reporting_interval: 1.0 level: 4 metric_levels: [7,9,11] level_string: \"13-15,17,19-21,7-9\"";
228 fhicl::ParameterSet pset;
229 fhicl::make_ParameterSet(testConfig, pset);
238 mpta.addMetricData(smd);
239 mpta.addMetricData(imd);
240 mpta.addMetricData(fmd);
241 mpta.addMetricData(dmd);
242 mpta.addMetricData(umd);
244 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
245 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 0);
246 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 0);
247 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 0);
248 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 0);
252 BOOST_REQUIRE_EQUAL(mpta.stopMetrics_calls, 1);
253 BOOST_REQUIRE_EQUAL(mpta.sendMetric_string_calls, 1);
254 BOOST_REQUIRE_EQUAL(mpta.sendMetric_int_calls, 2);
255 BOOST_REQUIRE_EQUAL(mpta.sendMetric_float_calls, 2);
256 BOOST_REQUIRE_EQUAL(mpta.sendMetric_double_calls, 2);
257 BOOST_REQUIRE_EQUAL(mpta.sendMetric_unsigned_calls, 2);
259 TLOG(TLVL_INFO,
"MetricPlugin_t") <<
"Test Case StopMetrics END";
262 BOOST_AUTO_TEST_SUITE_END()
virtual void sendMetric_(const std::string &, const float &, const std::string &) override
Send a metric to the underlying metric storage (file, Graphite, Ganglia, etc.)
The MetricPlugin class defines the interface that MetricManager uses to send metric data to the vario...
virtual void sendMetric_(const std::string &, const std::string &, const std::string &) override
Send a metric to the underlying metric storage (file, Graphite, Ganglia, etc.)
virtual void sendMetric_(const std::string &, const int &, const std::string &) override
Send a metric to the underlying metric storage (file, Graphite, Ganglia, etc.)
fhicl::ParameterSet pset
The ParameterSet used to configure the MetricPlugin.
virtual void sendMetric_(const std::string &, const long unsigned int &, const std::string &) override
Send a metric to the underlying metric storage (file, Graphite, Ganglia, etc.)
virtual void startMetrics_() override
Perform any start-up actions necessary for the metric plugin.
std::string app_name_
Name of the application which is sending metrics to this plugin.
Report only the last value recorded. Useful for event counters, run numbers, etc. ...
virtual void sendMetric_(const std::string &, const double &, const std::string &) override
Send a metric to the underlying metric storage (file, Graphite, Ganglia, etc.)
std::bitset< 64 > level_mask_
Bitset indicating for each possible metric level, whether this plugin will receive those metrics...
virtual void stopMetrics_() override
Perform any shutdown actions necessary for the metric plugin.
double accumulationTime_
The amount of time to average metric values; except for accumulate=false metrics, will be the interva...
bool inhibit_
Flag to indicate that the MetricPlugin is being stopped, and any metric back-ends which do not have a...