Module: check_mk
Branch: master
Commit: fb405e3ede4741f6f96f11600a42916908cb2382
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fb405e3ede4741…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Nov 17 13:35:15 2017 +0100
Simplifications. Removed dead code.
Change-Id: I301ec95118f048ab261d77ee8fa7710395261376
---
livestatus/src/Query.cc | 12 +-----------
livestatus/src/Query.h | 2 --
livestatus/src/StatsColumn.cc | 19 ++++++++++++-------
livestatus/src/StatsColumn.h | 5 ++---
4 files changed, 15 insertions(+), 23 deletions(-)
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 3e2b50b..e0dd095 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -675,23 +675,13 @@ void Query::optimizeBitmask(const std::string &column_name,
_filter->optimizeBitmask(column_name, bitmask, timezoneOffset());
}
-std::unique_ptr<Aggregator> Query::createAggregator(
- const StatsColumn &sc) const {
- try {
- return sc.createAggregator();
- } catch (const std::runtime_error &e) {
- Informational(_logger) << e.what() << ", falling back to
counting";
- return sc.createCountAggregator();
- }
-}
-
const std::vector<std::unique_ptr<Aggregator>>
&Query::getAggregatorsFor(
const RowFragment &groupspec) {
auto it = _stats_groups.find(groupspec);
if (it == _stats_groups.end()) {
std::vector<std::unique_ptr<Aggregator>> aggrs;
for (const auto &sc : _stats_columns) {
- aggrs.push_back(createAggregator(*sc));
+ aggrs.push_back(sc->createAggregator(_logger));
}
it = _stats_groups.emplace(groupspec, move(aggrs)).first;
}
diff --git a/livestatus/src/Query.h b/livestatus/src/Query.h
index 79a8465..c4dae5a 100644
--- a/livestatus/src/Query.h
+++ b/livestatus/src/Query.h
@@ -134,8 +134,6 @@ private:
void start(QueryRenderer &q);
void finish(QueryRenderer &q);
- std::unique_ptr<Aggregator> createAggregator(const StatsColumn &sc) const;
-
// NOTE: We cannot make this 'const' right now, it adds entries into
// _stats_groups.
const std::vector<std::unique_ptr<Aggregator>> &getAggregatorsFor(
diff --git a/livestatus/src/StatsColumn.cc b/livestatus/src/StatsColumn.cc
index 3cd614b..bd75909 100644
--- a/livestatus/src/StatsColumn.cc
+++ b/livestatus/src/StatsColumn.cc
@@ -24,21 +24,26 @@
#include "StatsColumn.h"
#include <algorithm>
+#include <ostream>
+#include <stdexcept>
#include "Column.h"
#include "CountAggregator.h"
#include "Filter.h"
+#include "Logger.h"
StatsColumn::StatsColumn(Column *c, std::unique_ptr<Filter> f, StatsOperation o)
: _column(c), _filter(std::move(f)), _operation(o) {}
std::unique_ptr<Filter> StatsColumn::stealFilter() { return move(_filter); }
-std::unique_ptr<Aggregator> StatsColumn::createAggregator() const {
- return _operation == StatsOperation::count
- ? createCountAggregator()
- : _column->createAggregator(_operation);
-}
-
-std::unique_ptr<Aggregator> StatsColumn::createCountAggregator() const {
+std::unique_ptr<Aggregator> StatsColumn::createAggregator(
+ Logger *logger) const {
+ if (_operation != StatsOperation::count) {
+ try {
+ return _column->createAggregator(_operation);
+ } catch (const std::runtime_error &e) {
+ Informational(logger) << e.what() << ", falling back to
counting";
+ }
+ }
return std::make_unique<CountAggregator>(_filter.get());
}
diff --git a/livestatus/src/StatsColumn.h b/livestatus/src/StatsColumn.h
index b89b79c..55af8f4 100644
--- a/livestatus/src/StatsColumn.h
+++ b/livestatus/src/StatsColumn.h
@@ -30,15 +30,14 @@
#include "Aggregator.h"
#include "Filter.h"
class Column;
+class Logger;
class StatsColumn {
public:
StatsColumn(Column *c, std::unique_ptr<Filter> f, StatsOperation o);
- Column *column() const { return _column; }
StatsOperation operation() const { return _operation; }
std::unique_ptr<Filter> stealFilter();
- std::unique_ptr<Aggregator> createAggregator() const;
- std::unique_ptr<Aggregator> createCountAggregator() const;
+ std::unique_ptr<Aggregator> createAggregator(Logger *logger) const;
private:
Column *_column;