Module: check_mk
Branch: master
Commit: 2f91a8e60cd3f23b9eacbeb548b6c00a564c5ff9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2f91a8e60cd3f2…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Feb 26 10:09:55 2019 +0100
Moved code for answering log queries to the right place.
Not really perfect yet, but much better.
Change-Id: Ice49c272574d40acfd8187041e4d482c23b36d18
---
livestatus/src/Logfile.cc | 19 +------------------
livestatus/src/Logfile.h | 7 ++-----
livestatus/src/TableLog.cc | 18 +++++++++++++++++-
livestatus/src/TableLog.h | 5 +++--
4 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/livestatus/src/Logfile.cc b/livestatus/src/Logfile.cc
index 56b7884..2a7df57 100644
--- a/livestatus/src/Logfile.cc
+++ b/livestatus/src/Logfile.cc
@@ -34,8 +34,6 @@
#include "LogEntry.h"
#include "Logger.h"
#include "MonitoringCore.h"
-#include "Query.h"
-#include "Row.h"
#ifdef CMC
#include "cmc.h"
@@ -211,22 +209,7 @@ const logfile_entries_t *Logfile::getEntriesFor(unsigned logclasses)
{
return &_entries;
}
-bool Logfile::answerQueryReverse(Query *query, time_t since, time_t until,
- unsigned logclasses) {
- auto entries = getEntriesFor(logclasses);
- // TODO(sp) Move the stuff below out of this class. Tricky part: makeKey
- auto it = entries->upper_bound(makeKey(until, 999999999));
- while (it != entries->begin()) {
- --it;
- // end found or limit exceeded?
- if (it->second->_time < since ||
- !query->processDataset(Row(it->second.get()))) {
- return false;
- }
- }
- return true;
-}
-
+// static
uint64_t Logfile::makeKey(time_t t, size_t lineno) {
return (static_cast<uint64_t>(t) << 32) |
static_cast<uint64_t>(lineno);
}
diff --git a/livestatus/src/Logfile.h b/livestatus/src/Logfile.h
index 5f07068..17e6662 100644
--- a/livestatus/src/Logfile.h
+++ b/livestatus/src/Logfile.h
@@ -37,7 +37,6 @@ class LogCache;
class LogEntry;
class Logger;
class MonitoringCore;
-class Query;
#ifdef CMC
class World;
@@ -58,12 +57,11 @@ public:
size_t size() const { return _entries.size(); }
long freeMessages(unsigned logclasses);
- // for TableStateHistory
+ // for TableStateHistory and TableLog
const logfile_entries_t *getEntriesFor(unsigned logclasses);
// for TableLog::answerQuery
- bool answerQueryReverse(Query *query, time_t since, time_t until,
- unsigned logclasses);
+ static uint64_t makeKey(time_t t, size_t lineno);
private:
MonitoringCore *const _mc;
@@ -82,7 +80,6 @@ private:
void load(unsigned logclasses);
void loadRange(FILE *file, unsigned missing_types, unsigned logclasses);
bool processLogLine(size_t lineno, std::string line, unsigned logclasses);
- uint64_t makeKey(time_t t, size_t lineno);
void updateReferences();
Logger *logger() const;
};
diff --git a/livestatus/src/TableLog.cc b/livestatus/src/TableLog.cc
index ea2ecb1..e4d1e2d 100644
--- a/livestatus/src/TableLog.cc
+++ b/livestatus/src/TableLog.cc
@@ -167,7 +167,8 @@ void TableLog::answerQuery(Query *query) {
}
while (true) {
- if (!it->second->answerQueryReverse(query, since, until, classmask)) {
+ auto entries = it->second->getEntriesFor(classmask);
+ if (!answerQueryReverse(entries, query, since, until)) {
break; // end of time range found
}
if (it == _log_cache->begin()) {
@@ -177,6 +178,21 @@ void TableLog::answerQuery(Query *query) {
}
}
+// static
+bool TableLog::answerQueryReverse(const logfile_entries_t *entries,
+ Query *query, time_t since, time_t until) {
+ auto it = entries->upper_bound(Logfile::makeKey(until, 999999999));
+ while (it != entries->begin()) {
+ --it;
+ // end found or limit exceeded?
+ if (it->second->_time < since ||
+ !query->processDataset(Row(it->second.get()))) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool TableLog::isAuthorized(Row row, const contact *ctc) const {
auto entry = rowData<LogEntry>(row);
service *svc = entry->_service;
diff --git a/livestatus/src/TableLog.h b/livestatus/src/TableLog.h
index 95bf8e7..f2cbb84 100644
--- a/livestatus/src/TableLog.h
+++ b/livestatus/src/TableLog.h
@@ -29,10 +29,10 @@
#include <ctime>
#include <memory>
#include <string>
+#include "Logfile.h"
#include "Table.h"
#include "contact_fwd.h"
class Column;
-class Logfile;
class LogCache;
class MonitoringCore;
class Query;
@@ -50,7 +50,8 @@ public:
private:
LogCache *_log_cache;
- bool answerQuery(Query *, Logfile *, time_t, time_t);
+ static bool answerQueryReverse(const logfile_entries_t *entries,
+ Query *query, time_t since, time_t until);
};
#endif // TableLog_h