Merge branch '2.3' into 2.4

This commit is contained in:
Marko
2019-07-28 21:43:58 +03:00
20 changed files with 199 additions and 34 deletions

View File

@ -62,11 +62,13 @@ struct
uint64_t next_session_id;
uint32_t retain_last_statements;
session_dump_statements_t dump_statements;
uint32_t session_trace;
} this_unit =
{
1,
0,
SESSION_DUMP_STATEMENTS_NEVER
SESSION_DUMP_STATEMENTS_NEVER,
0
};
}
@ -803,6 +805,9 @@ json_t* session_json_data(const Session* session, const char* host, bool rdns)
json_t* queries = session->queries_as_json();
json_object_set_new(attr, "queries", queries);
json_t* log = session->log_as_json();
json_object_set_new(attr, "log", log);
json_object_set_new(data, CN_ATTRIBUTES, attr);
json_object_set_new(data, CN_LINKS, mxs_json_self_link(host, CN_SESSIONS, ss.str().c_str()));
@ -1012,6 +1017,28 @@ void session_dump_statements(MXS_SESSION* session)
pSession->dump_statements();
}
void session_set_session_trace(uint32_t value)
{
this_unit.session_trace = value;
}
uint32_t session_get_session_trace()
{
return this_unit.session_trace;
}
void session_append_log(MXS_SESSION* pSession, std::string log)
{
{
static_cast<Session*>(pSession)->append_session_log(log);
}
}
void session_dump_log(MXS_SESSION* pSession)
{
static_cast<Session*>(pSession)->dump_session_log();
}
class DelayedRoutingTask
{
DelayedRoutingTask(const DelayedRoutingTask&) = delete;
@ -1277,6 +1304,18 @@ json_t* Session::queries_as_json() const
return pQueries;
}
json_t* Session::log_as_json() const
{
json_t* pLog = json_array();
for (const auto& i : m_log)
{
json_array_append_new(pLog, json_string(i.c_str()));
}
return pLog;
}
bool Session::setup_filters(Service* service)
{
for (const auto& a : service->get_filters())
@ -1635,3 +1674,28 @@ void Session::QueryInfo::reset_server_bookkeeping()
m_completed.tv_nsec = 0;
m_complete = false;
}
void Session::append_session_log(std::string log)
{
m_log.push_front(log);
if (m_log.size() >= this_unit.session_trace)
{
m_log.pop_back();
}
}
void Session::dump_session_log()
{
if (!(m_log.empty()))
{
std::string log;
for (const auto& s : m_log)
{
log += s;
}
MXS_NOTICE("Session log for session (%" PRIu64"): \n%s ", ses_id, log.c_str());
}
}