Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OMON-661] Remove division by 0 log message #319

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ endif()

# Define project
project(Monitoring
VERSION 3.17.3
VERSION 3.17.4
DESCRIPTION "O2 Monitoring library"
LANGUAGES CXX
)
Expand Down
2 changes: 1 addition & 1 deletion src/DerivedMetrics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
bool DerivedMetrics::process(Metric& metric, DerivedMetricMode mode)
{
const std::map<DerivedMetricMode, std::function<bool(Metric&)>> map = {
{DerivedMetricMode::INCREMENT, [this](Metric& metric) {

Check warning on line 43 in src/DerivedMetrics.cxx

View check run for this annotation

Codecov / codecov/patch

src/DerivedMetrics.cxx#L43

Added line #L43 was not covered by tests
auto tags = metric.getTags();
std::string key = metric.getName();
std::for_each(tags.begin(), tags.end(), [&key](auto const& pair) {
key += pair.second;
});

Check warning on line 48 in src/DerivedMetrics.cxx

View check run for this annotation

Codecov / codecov/patch

src/DerivedMetrics.cxx#L47-L48

Added lines #L47 - L48 were not covered by tests
auto search = mStorage.find(key);
if (search != mStorage.end()) {
auto currentValue = metric.getFirstValue().second;
Expand All @@ -59,7 +59,7 @@
mStorage.insert(std::make_pair(key, metric));
return true;
}},
{DerivedMetricMode::RATE, [this](Metric& metric) {

Check warning on line 62 in src/DerivedMetrics.cxx

View check run for this annotation

Codecov / codecov/patch

src/DerivedMetrics.cxx#L62

Added line #L62 was not covered by tests
/// create pseudo unique key
auto tags = metric.getTags();
std::string key = metric.getName();
Expand All @@ -80,7 +80,7 @@
int timestampCount = timestampDifference.count();
// disallow dividing by 0
if (timestampCount == 0) {
throw MonitoringException("DerivedMetrics", "Division by 0 when calculating rate for: " + metric.getName() + "/" + metric.getFirstValue().first);
//throw MonitoringException("DerivedMetrics", "Division by 0 when calculating rate for: " + metric.getName() + "/" + metric.getFirstValue().first);
}

auto current = metric.getFirstValue().second;
Expand All @@ -90,7 +90,7 @@
// handle situation when a new run starts
auto isZero = std::visit(overloaded{
[](auto arg) { return arg == 0; },
[](const std::string& arg) { return arg == ""; }

Check warning on line 93 in src/DerivedMetrics.cxx

View check run for this annotation

Codecov / codecov/patch

src/DerivedMetrics.cxx#L93

Added line #L93 was not covered by tests
}, current);
if (rate < 0 && isZero) {
rate = 0;
Expand All @@ -103,7 +103,7 @@
metric.addValue(rate, metric.getFirstValue().first + "_rate");
return true;
}},
{DerivedMetricMode::SUPPRESS, [this](Metric& metric) {

Check warning on line 106 in src/DerivedMetrics.cxx

View check run for this annotation

Codecov / codecov/patch

src/DerivedMetrics.cxx#L106

Added line #L106 was not covered by tests
auto tags = metric.getTags();
std::string key = metric.getName();
std::for_each(tags.begin(), tags.end(), [&key](auto const& pair) {
Expand Down
4 changes: 2 additions & 2 deletions test/testDerived.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ bool exceptionCheck(const MonitoringException& e)
return false;
}

BOOST_AUTO_TEST_CASE(divisionByZero)
/*BOOST_AUTO_TEST_CASE(divisionByZero)
{
std::string name("test");
o2::monitoring::DerivedMetrics derivedHandler;
o2::monitoring::Metric metric(10, name);

derivedHandler.process(metric, DerivedMetricMode::RATE);
BOOST_CHECK_EXCEPTION(derivedHandler.process(metric, DerivedMetricMode::RATE), MonitoringException, exceptionCheck);
}
}*/

BOOST_AUTO_TEST_CASE(derivedIncrementInt)
{
Expand Down
Loading