Skip to content

Commit b925f66

Browse files
authored
[OMON-327] Provide metric type as int in StdOut backend (#194)
* Provide metric type as int in StdOut backend * Add metric type tests
1 parent c169cc5 commit b925f66

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

include/Monitoring/Metric.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ class Metric
143143
/// Whether timestamp should be included or not
144144
static bool includeTimestamp;
145145

146+
/// This is required for backward compability with boost::variant and old StdOut format
147+
int getFirstValueType() const;
148+
146149
protected:
147150
/// Allow DerivedMetrics access to setTags
148151
friend class o2::monitoring::DerivedMetrics;

src/Backends/StdOut.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void StdOut::send(const Metric& metric)
7272
[](auto value) -> std::string { return std::to_string(value); }
7373
}, value.second);
7474
if (metric.getValuesSize() == 1) {
75-
mStream << ",0 " << stringValue;
75+
mStream << ',' << metric.getFirstValueType() << ' ' << stringValue;
7676
} else {
7777
mStream << ' ' << value.first << '=' << stringValue;
7878
}

src/Metric.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ std::size_t Metric::getValuesSize() const noexcept
159159
return mValues.size();
160160
}
161161

162+
int Metric::getFirstValueType() const
163+
{
164+
if (std::holds_alternative<int>(mValues.front().second))
165+
return 0;
166+
else if (std::holds_alternative<std::string>(mValues.front().second))
167+
return 1;
168+
else if (std::holds_alternative<double>(mValues.front().second))
169+
return 2;
170+
else
171+
return 3;
172+
}
173+
162174
bool Metric::includeTimestamp = true;
163175
Verbosity Metric::DefaultVerbosity = Verbosity::Info;
164176
std::map<std::underlying_type<Verbosity>::type, std::regex> Metric::mRegexPolicy;

test/testMetric.cxx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,46 @@ BOOST_AUTO_TEST_CASE(tags)
111111
BOOST_CHECK_EQUAL(sum, 45);
112112
}
113113

114+
BOOST_AUTO_TEST_CASE(retrieveIntType)
115+
{
116+
int value = 10;
117+
std::string name("metric name");
118+
Metric metricInstance(value, name);
119+
120+
BOOST_CHECK_EQUAL(std::get<int>(metricInstance.getFirstValue().second), 10);
121+
BOOST_CHECK_EQUAL(metricInstance.getFirstValueType(), 0);
122+
}
123+
124+
BOOST_AUTO_TEST_CASE(retrieveDoubleType)
125+
{
126+
double value = 1.11;
127+
std::string name("metric name");
128+
Metric metricInstance(value, name);
129+
130+
BOOST_CHECK_EQUAL(std::get<double>(metricInstance.getFirstValue().second), 1.11);
131+
BOOST_CHECK_EQUAL(metricInstance.getFirstValueType(), 2);
132+
}
133+
134+
BOOST_AUTO_TEST_CASE(retrieveStringType)
135+
{
136+
std::string value = "testString";
137+
std::string name("metric name");
138+
Metric metricInstance(value, name);
139+
140+
BOOST_CHECK_EQUAL(std::get<std::string>(metricInstance.getFirstValue().second), "testString");
141+
BOOST_CHECK_EQUAL(metricInstance.getFirstValueType(), 1);
142+
}
143+
144+
BOOST_AUTO_TEST_CASE(retrieveUnsignedLongLongType)
145+
{
146+
uint64_t value = 10000000000000LL;
147+
std::string name("metric name");
148+
Metric metricInstance(value, name);
149+
150+
BOOST_CHECK_EQUAL(std::get<uint64_t>(metricInstance.getFirstValue().second), 10000000000000LL);
151+
BOOST_CHECK_EQUAL(metricInstance.getFirstValueType(), 3);
152+
}
153+
114154
BOOST_AUTO_TEST_CASE(regexVerbosityPolicy)
115155
{
116156
Metric::setVerbosityPolicy(Verbosity::Prod, std::regex("myMetric", std::regex::optimize));

0 commit comments

Comments
 (0)