Module: check_mk
Branch: master
Commit: 403efefc7e4eb60555c8b0eb9832f8ccc721dcbf
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=403efefc7e4eb6…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Apr 5 16:38:26 2016 +0200
Fetched livestatus from downstream.
---
livestatus/src/Query.cc | 33 +++++++++++++--------------------
livestatus/src/Query.h | 7 +++----
livestatus/src/Store.cc | 38 +++++++++++++++++---------------------
3 files changed, 33 insertions(+), 45 deletions(-)
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 91ad351..4f49d33 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -169,6 +169,13 @@ Query::Query(const list<string> &lines, OutputBuffer
*output, Table *table)
break;
}
}
+
+ if (_columns.empty() && !doStats()) {
+ table->addAllColumnsToQuery(this);
+ // TODO(sp) We overwrite the value from a possible ColumnHeaders: line
+ // here, is that really what we want?
+ _show_column_headers = true;
+ }
}
Query::~Query() {
@@ -199,8 +206,6 @@ void Query::setError(int error_code, const char *msg) {
_output->setError(error_code, msg);
}
-bool Query::hasNoColumns() { return _columns.empty() && !doStats(); }
-
int Query::lookupOperator(const char *opname) {
int opid;
int negate = 1;
@@ -382,10 +387,6 @@ void Query::parseStatsNegateLine(char *line) {
}
void Query::parseStatsLine(char *line) {
- if (_table == nullptr) {
- return;
- }
-
// first token is either aggregation operator or column name
char *col_or_op = next_field(&line);
if (col_or_op == nullptr) {
@@ -472,10 +473,6 @@ void Query::parseStatsLine(char *line) {
}
void Query::parseFilterLine(char *line, bool is_filter) {
- if (_table == nullptr) {
- return;
- }
-
char *column_name = next_field(&line);
if (column_name == nullptr) {
_output->setError(RESPONSE_CODE_INVALID_HEADER, "empty filter
line");
@@ -523,9 +520,6 @@ void Query::parseFilterLine(char *line, bool is_filter) {
}
void Query::parseAuthUserHeader(char *line) {
- if (_table == nullptr) {
- return;
- }
_auth_user = find_contact(line);
if (_auth_user == nullptr) {
// Do not handle this as error any more. In a multi site setup
@@ -544,9 +538,6 @@ void Query::parseStatsGroupLine(char *line) {
}
void Query::parseColumnsLine(char *line) {
- if (_table == nullptr) {
- return;
- }
char *column_name;
while (nullptr != (column_name = next_field(&line))) {
Column *column = _table->column(column_name);
@@ -758,10 +749,6 @@ void Query::parseWaitTriggerLine(char *line) {
}
void Query::parseWaitObjectLine(char *line) {
- if (_table == nullptr) {
- return;
- }
-
char *objectspec = lstrip(line);
_wait_object = _table->findObject(objectspec);
if (_wait_object == nullptr) {
@@ -811,6 +798,12 @@ void Query::parseLocaltimeLine(char *line) {
bool Query::doStats() { return !_stats_columns.empty(); }
+void Query::process() {
+ start();
+ _table->answerQuery(this);
+ finish();
+}
+
void Query::start() {
doWait();
diff --git a/livestatus/src/Query.h b/livestatus/src/Query.h
index d7af3c8..8eac4e6 100644
--- a/livestatus/src/Query.h
+++ b/livestatus/src/Query.h
@@ -93,15 +93,12 @@ class Query {
public:
Query(const std::list<std::string> &lines, OutputBuffer *output, Table *);
~Query();
+ void process();
bool processDataset(void *);
bool timelimitReached();
- void start();
- void finish();
void setDefaultColumns(const char *);
void addColumn(Column *column);
- void setShowColumnHeaders(bool x) { _show_column_headers = x; }
void setError(int error_code, const char *msg);
- bool hasNoColumns();
contact *authUser() { return _auth_user; }
void outputDatasetBegin();
void outputDatasetEnd();
@@ -160,6 +157,8 @@ private:
void parseWaitTriggerLine(char *line);
void parseWaitObjectLine(char *line);
void parseLocaltimeLine(char *line);
+ void start();
+ void finish();
int lookupOperator(const char *opname);
Column *createDummyColumn(const char *name);
};
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index c2f2d0d..c139d87 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -24,13 +24,12 @@
#include "Store.h"
#include <string.h>
-#include <sys/time.h>
#include <time.h>
+#include <chrono>
#include <utility>
#include "InputBuffer.h"
#include "OutputBuffer.h"
#include "Query.h"
-#include "Table.h"
#include "global_counters.h"
#include "logger.h"
#include "strutil.h"
@@ -43,12 +42,16 @@
#include "tables.h" // IWYU pragma: keep
#undef EXTERN
+using std::chrono::duration_cast;
+using std::chrono::microseconds;
+using std::chrono::system_clock;
using std::list;
using std::lock_guard;
using std::make_pair;
using std::mutex;
using std::pair;
using std::string;
+using std::to_string;
extern int g_debug_level;
extern unsigned long g_max_cached_messages;
@@ -188,34 +191,27 @@ void Store::answerCommandRequest(const char *command) {
void Store::answerGetRequest(const list<string> &lines, OutputBuffer *output,
const char *tablename) {
output->reset();
+
if (tablename[0] == 0) {
output->setError(RESPONSE_CODE_INVALID_REQUEST,
"Invalid GET request, missing tablename");
+ return;
}
+
Table *table = findTable(tablename);
if (table == nullptr) {
output->setError(RESPONSE_CODE_NOT_FOUND,
"Invalid GET request, no such table '%s'",
tablename);
+ return;
}
- Query query(lines, output, table);
- if ((table != nullptr) && !output->hasError()) {
- if (query.hasNoColumns()) {
- table->addAllColumnsToQuery(&query);
- query.setShowColumnHeaders(true);
- }
- struct timeval before, after;
- gettimeofday(&before, nullptr);
- query.start();
- table->answerQuery(&query);
- query.finish();
- gettimeofday(&after, nullptr);
- unsigned long ustime = (after.tv_sec - before.tv_sec) * 1000000 +
- (after.tv_usec - before.tv_usec);
- if (g_debug_level > 0) {
- logger(LG_INFO,
- "Time to process request: %lu us. Size of answer: %d
bytes",
- ustime, output->size());
- }
+ auto start = system_clock::now();
+ Query(lines, output, table).process();
+ if (g_debug_level > 0) {
+ auto elapsed = duration_cast<microseconds>(system_clock::now() - start);
+ logger(LG_INFO, "%s",
+ ("Time to process request: " + to_string(elapsed.count()) +
+ " us. Size of answer: " + to_string(output->size()) + "
bytes")
+ .c_str());
}
}