Module: check_mk
Branch: master
Commit: 0d3742667d1bdcbfb501b9af20e22ec5bbf09124
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0d3742667d1bdc…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Mar 5 11:44:27 2018 +0100
Centralized computation of partial filter.
This removes some (inconsistent) copy-n-paste. Note that the identical
treatment of conjuctions and disjunctions still looks wrong, but it isn't
more wrong than before, and at least we have only one place to fix this now.
Change-Id: I9cd6242904a79e05d40a747107db682578d73aff
---
livestatus/src/TableStateHistory.cc | 48 +++++++++++++++++++++++++++----------
livestatus/src/TableStateHistory.h | 3 +++
2 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index 89be3cc..be342bd 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -45,12 +45,12 @@
#include "OffsetSStringColumn.h"
#include "OffsetStringColumn.h"
#include "OffsetTimeColumn.h"
+#include "OringFilter.h" // IWYU pragma: keep
#include "Query.h"
#include "Row.h"
#include "StringUtils.h"
#include "TableHosts.h"
#include "TableServices.h"
-class OringFilter;
#ifdef CMC
// This seems to be an IWYU bug: If we remove the includes as suggested, we
@@ -239,8 +239,6 @@ LogEntry *TableStateHistory::getNextLogentry() {
return _it_entries->second.get();
}
-// TODO(sp) IsObjectFilter in TableCachedStatehist recurses into sub-filters,
-// while we don't. Is this really intentional?
namespace {
class IsObjectFilter : public FilterVisitor {
public:
@@ -252,8 +250,25 @@ public:
mk::starts_with(column_name, "service_");
}
}
- void visit(const AndingFilter & /*unused*/) override {}
- void visit(const OringFilter & /*unused*/) override {}
+
+ // TODO(sp): Handling and/or the same way looks suspicious...
+ void visit(const AndingFilter &f) override {
+ for (const auto &sub_filter : f) {
+ if (!_value) {
+ return;
+ }
+ sub_filter->accept(*this);
+ }
+ }
+
+ void visit(const OringFilter &f) override {
+ for (const auto &sub_filter : f) {
+ if (!_value) {
+ return;
+ }
+ sub_filter->accept(*this);
+ }
+ }
bool _value = true;
};
@@ -281,11 +296,14 @@ private:
};
} // namespace
-void TableStateHistory::answerQuery(Query *query) {
- // Create a partial filter, that contains only such filters that check
- // attributes of current hosts and services
+// Create a partial filter, that contains only such filters that check
+// attributes of current hosts and services
+
+// static
+std::unique_ptr<Filter> TableStateHistory::createPartialFilter(
+ const AndingFilter &f) {
std::vector<std::unique_ptr<Filter>> subfilters;
- for (const auto &filter : *query->filter()) {
+ for (const auto &filter : f) {
IsObjectFilter is_obj;
filter->accept(is_obj);
if (is_obj._value) {
@@ -293,8 +311,12 @@ void TableStateHistory::answerQuery(Query *query) {
}
}
std::reverse(subfilters.begin(), subfilters.end());
- AndingFilter object_filter(LogicalOperator::and_, std::move(subfilters));
+ return std::make_unique<AndingFilter>(LogicalOperator::and_,
+ std::move(subfilters));
+}
+void TableStateHistory::answerQuery(Query *query) {
+ auto object_filter = createPartialFilter(*query->filter());
std::lock_guard<std::mutex> lg(_log_cache->_lock);
if (!_log_cache->logCachePreChecks()) {
return;
@@ -464,9 +486,9 @@ void TableStateHistory::answerQuery(Query *query) {
// filtered out. Note: we currently do not filter out hosts
// since they might be needed for service states
if (!entry->_svc_desc.empty()) {
- if (!object_filter.accepts(Row(state),
- query->authUser(),
- query->timezoneOffset())) {
+ if (!object_filter->accepts(Row(state),
+ query->authUser(),
+ query->timezoneOffset())) {
object_blacklist.insert(key);
delete state;
continue;
diff --git a/livestatus/src/TableStateHistory.h b/livestatus/src/TableStateHistory.h
index db8d4b0..cf8492a 100644
--- a/livestatus/src/TableStateHistory.h
+++ b/livestatus/src/TableStateHistory.h
@@ -32,7 +32,9 @@
#include "LogCache.h"
#include "Logfile.h"
#include "Table.h"
+class AndingFilter;
class Column;
+class Filter;
class HostServiceState;
class LogEntry;
class MonitoringCore;
@@ -54,6 +56,7 @@ public:
void answerQuery(Query *query) override;
bool isAuthorized(Row row, const contact *ctc) const override;
std::shared_ptr<Column> column(std::string colname) const override;
+ static std::unique_ptr<Filter> createPartialFilter(const AndingFilter &f);
protected:
bool _abort_query;