Module: check_mk
Branch: master
Commit: a8f257da8558043c98b8749cc6333b3c9d2afe3f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a8f257da855804…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Mar 20 16:22:53 2018 +0100
Fully encapsulate the filter in Query. Improve logging.
Change-Id: I176b0095c80098e86109681785c182789c3ab8c8
---
livestatus/src/Query.cc | 8 ++++++++
livestatus/src/Query.h | 5 ++++-
livestatus/src/TableStateHistory.cc | 15 ++++++++-------
livestatus/src/TableStateHistory.h | 2 +-
4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index b97e071..d2e8528 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -712,6 +712,14 @@ void Query::finish(QueryRenderer &q) {
}
}
+std::unique_ptr<Filter> Query::partialFilter(
+ const std::string &message,
+ std::function<bool(const Column &)> predicate) const {
+ auto result = _filter->partialFilter(predicate);
+ Debug(_logger) << "partial filter for " << message <<
": " << *result;
+ return result;
+}
+
std::optional<std::string> Query::stringValueRestrictionFor(
const std::string &column_name) const {
auto result = _filter->stringValueRestrictionFor(column_name);
diff --git a/livestatus/src/Query.h b/livestatus/src/Query.h
index 21ff169..f86c5a8 100644
--- a/livestatus/src/Query.h
+++ b/livestatus/src/Query.h
@@ -70,6 +70,9 @@ public:
const contact *authUser() const { return _auth_user; }
std::chrono::seconds timezoneOffset() const { return _timezone_offset; }
+ std::unique_ptr<Filter> partialFilter(
+ const std::string &message,
+ std::function<bool(const Column &)> predicate) const;
std::optional<std::string> stringValueRestrictionFor(
const std::string &column_name) const;
std::optional<int32_t> greatestLowerBoundFor(
@@ -78,7 +81,7 @@ public:
const std::string &column_name) const;
std::optional<std::bitset<32>> valueSetLeastUpperBoundFor(
const std::string &column_name) const;
- const Filter *filter() const { return _filter.get(); }
+
const std::unordered_set<std::shared_ptr<Column>> &allColumns() const
{
return _all_columns;
}
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index 55a2560..53385bf 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -266,16 +266,17 @@ private:
// static
std::unique_ptr<Filter> TableStateHistory::createPartialFilter(
- const Filter &f) {
- return f.partialFilter([](const Column &column) {
- return mk::starts_with(column.name(), "current_") ||
- mk::starts_with(column.name(), "host_") ||
- mk::starts_with(column.name(), "service_");
- });
+ const Query &query) {
+ return query.partialFilter(
+ "current host/service columns", [](const Column &column) {
+ return mk::starts_with(column.name(), "current_") ||
+ mk::starts_with(column.name(), "host_") ||
+ mk::starts_with(column.name(), "service_");
+ });
}
void TableStateHistory::answerQuery(Query *query) {
- auto object_filter = createPartialFilter(*query->filter());
+ auto object_filter = createPartialFilter(*query);
std::lock_guard<std::mutex> lg(_log_cache->_lock);
if (!_log_cache->logCachePreChecks()) {
return;
diff --git a/livestatus/src/TableStateHistory.h b/livestatus/src/TableStateHistory.h
index 29ddc87..ad6fbbb 100644
--- a/livestatus/src/TableStateHistory.h
+++ b/livestatus/src/TableStateHistory.h
@@ -55,7 +55,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 Filter &f);
+ static std::unique_ptr<Filter> createPartialFilter(const Query &query);
protected:
bool _abort_query;