MXS-1220: Implement JSON diagnostics entry point all filters
The second and final part of the filters now implement the JSON version of the diagnostics function.
This commit is contained in:
parent
12baa304e6
commit
25c8fb8556
@ -37,7 +37,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
|
||||
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
|
||||
static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *session, MXS_UPSTREAM *upstream);
|
||||
static int32_t routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
|
||||
static uint64_t getCapabilities(MXS_FILTER *instance);
|
||||
static int32_t clientReply(MXS_FILTER* instance, MXS_FILTER_SESSION *session, GWBUF *reply);
|
||||
static bool extract_insert_target(GWBUF *buffer, char* target, int len);
|
||||
@ -497,20 +497,24 @@ static int32_t clientReply(MXS_FILTER* instance, MXS_FILTER_SESSION *session, GW
|
||||
*
|
||||
* @param instance The filter instance
|
||||
* @param fsession Filter session, may be NULL
|
||||
* @param dcb The DCB for diagnostic output
|
||||
*/
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
|
||||
{
|
||||
DS_INSTANCE *my_instance = (DS_INSTANCE *) instance;
|
||||
DS_INSTANCE *my_instance = (DS_INSTANCE*)instance;
|
||||
|
||||
json_t* rval = json_object();
|
||||
|
||||
if (my_instance->source)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tReplacement limited to connections from %s\n", my_instance->source);
|
||||
json_object_set_new(rval, "source", json_string(my_instance->source));
|
||||
}
|
||||
|
||||
if (my_instance->user)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tReplacement limit to user %s\n", my_instance->user);
|
||||
json_object_set_new(rval, "user", json_string(my_instance->user));
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,9 +138,9 @@ MaskingFilterSession* MaskingFilter::newSession(MXS_SESSION* pSession)
|
||||
}
|
||||
|
||||
// static
|
||||
void MaskingFilter::diagnostics(DCB* pDcb)
|
||||
json_t* MaskingFilter::diagnostics()
|
||||
{
|
||||
dcb_printf(pDcb, "Hello, World!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
|
||||
MaskingFilterSession* newSession(MXS_SESSION* pSession);
|
||||
|
||||
void diagnostics(DCB* pDcb);
|
||||
json_t* diagnostics();
|
||||
|
||||
uint64_t getCapabilities();
|
||||
|
||||
|
@ -142,9 +142,9 @@ NullFilterSession* NullFilter::newSession(MXS_SESSION* pSession)
|
||||
}
|
||||
|
||||
// static
|
||||
void NullFilter::diagnostics(DCB* pDcb)
|
||||
json_t* NullFilter::diagnostics()
|
||||
{
|
||||
dcb_printf(pDcb, "Hello, World!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint64_t NullFilter::getCapabilities()
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
|
||||
NullFilterSession* newSession(MXS_SESSION* pSession);
|
||||
|
||||
void diagnostics(DCB* pDcb);
|
||||
json_t* diagnostics();
|
||||
|
||||
uint64_t getCapabilities();
|
||||
|
||||
|
@ -81,7 +81,7 @@ static void closeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
|
||||
static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
|
||||
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
|
||||
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
|
||||
static uint64_t getCapabilities(MXS_FILTER* instance);
|
||||
|
||||
/**
|
||||
@ -578,39 +578,40 @@ routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *queue)
|
||||
*
|
||||
* @param instance The filter instance
|
||||
* @param fsession Filter session, may be NULL
|
||||
* @param dcb The DCB for diagnostic output
|
||||
*/
|
||||
static void
|
||||
diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
|
||||
{
|
||||
QLA_INSTANCE *my_instance = (QLA_INSTANCE *) instance;
|
||||
QLA_SESSION *my_session = (QLA_SESSION *) fsession;
|
||||
QLA_INSTANCE *my_instance = (QLA_INSTANCE*)instance;
|
||||
QLA_SESSION *my_session = (QLA_SESSION*)fsession;
|
||||
|
||||
json_t* rval = json_object();
|
||||
|
||||
if (my_session)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLogging to file %s.\n",
|
||||
my_session->filename);
|
||||
json_object_set_new(rval, "session_filename", json_string(my_session->filename));
|
||||
}
|
||||
|
||||
if (my_instance->source)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLimit logging to connections from %s\n",
|
||||
my_instance->source);
|
||||
json_object_set_new(rval, "source", json_string(my_instance->source));
|
||||
}
|
||||
|
||||
if (my_instance->user_name)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLimit logging to user %s\n",
|
||||
my_instance->user_name);
|
||||
json_object_set_new(rval, "user", json_string(my_instance->user_name));
|
||||
}
|
||||
|
||||
if (my_instance->match)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
||||
my_instance->match);
|
||||
json_object_set_new(rval, "match", json_string(my_instance->match));
|
||||
}
|
||||
|
||||
if (my_instance->nomatch)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
||||
my_instance->nomatch);
|
||||
json_object_set_new(rval, "exclude", json_string(my_instance->nomatch));
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ static void closeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
|
||||
static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
|
||||
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
|
||||
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
|
||||
static uint64_t getCapabilities(MXS_FILTER* instance);
|
||||
|
||||
static char *regex_replace(const char *sql, pcre2_code *re, pcre2_match_data *study,
|
||||
@ -376,35 +376,34 @@ routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *queue)
|
||||
*
|
||||
* @param instance The filter instance
|
||||
* @param fsession Filter session, may be NULL
|
||||
* @param dcb The DCB for diagnostic output
|
||||
*/
|
||||
static void
|
||||
diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
|
||||
{
|
||||
REGEX_INSTANCE *my_instance = (REGEX_INSTANCE *) instance;
|
||||
REGEX_SESSION *my_session = (REGEX_SESSION *) fsession;
|
||||
REGEX_INSTANCE *my_instance = (REGEX_INSTANCE*)instance;
|
||||
REGEX_SESSION *my_session = (REGEX_SESSION*)fsession;
|
||||
|
||||
json_t* rval = json_object();
|
||||
|
||||
json_object_set_new(rval, "match", json_string(my_instance->match));
|
||||
json_object_set_new(rval, "replace", json_string(my_instance->replace));
|
||||
|
||||
dcb_printf(dcb, "\t\tSearch and replace: s/%s/%s/\n",
|
||||
my_instance->match, my_instance->replace);
|
||||
if (my_session)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tNo. of queries unaltered by filter: %d\n",
|
||||
my_session->no_change);
|
||||
dcb_printf(dcb, "\t\tNo. of queries altered by filter: %d\n",
|
||||
my_session->replacements);
|
||||
json_object_set_new(rval, "altered", json_integer(my_session->no_change));
|
||||
json_object_set_new(rval, "unaltered", json_integer(my_session->replacements));
|
||||
}
|
||||
|
||||
if (my_instance->source)
|
||||
{
|
||||
dcb_printf(dcb,
|
||||
"\t\tReplacement limited to connections from %s\n",
|
||||
my_instance->source);
|
||||
json_object_set_new(rval, "source", json_string(my_instance->source));
|
||||
}
|
||||
|
||||
if (my_instance->user)
|
||||
{
|
||||
dcb_printf(dcb,
|
||||
"\t\tReplacement limit to user %s\n",
|
||||
my_instance->user);
|
||||
json_object_set_new(rval, "user", json_string(my_instance->user));
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,7 @@ static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MX
|
||||
static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_UPSTREAM *upstream);
|
||||
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
|
||||
static uint64_t getCapabilities(MXS_FILTER* instance);
|
||||
|
||||
/**
|
||||
@ -697,43 +697,43 @@ clientReply(MXS_FILTER* instance, MXS_FILTER_SESSION *session, GWBUF *reply)
|
||||
*
|
||||
* @param instance The filter instance
|
||||
* @param fsession Filter session, may be NULL
|
||||
* @param dcb The DCB for diagnostic output
|
||||
*/
|
||||
static void
|
||||
diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
|
||||
{
|
||||
TEE_INSTANCE *my_instance = (TEE_INSTANCE *) instance;
|
||||
TEE_SESSION *my_session = (TEE_SESSION *) fsession;
|
||||
TEE_INSTANCE *my_instance = (TEE_INSTANCE*)instance;
|
||||
TEE_SESSION *my_session = (TEE_SESSION*)fsession;
|
||||
|
||||
json_t* rval = json_object();
|
||||
|
||||
if (my_instance->source)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLimit to connections from %s\n",
|
||||
my_instance->source);
|
||||
json_object_set_new(rval, "source", json_string(my_instance->source));
|
||||
}
|
||||
dcb_printf(dcb, "\t\tDuplicate statements to service %s\n",
|
||||
my_instance->service->name);
|
||||
|
||||
json_object_set_new(rval, "service", json_string(my_instance->service->name));
|
||||
|
||||
if (my_instance->userName)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLimit to user %s\n",
|
||||
my_instance->userName);
|
||||
json_object_set_new(rval, "user", json_string(my_instance->userName));
|
||||
}
|
||||
|
||||
if (my_instance->match)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
||||
my_instance->match);
|
||||
json_object_set_new(rval, "match", json_string(my_instance->match));
|
||||
}
|
||||
|
||||
if (my_instance->nomatch)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
||||
my_instance->nomatch);
|
||||
json_object_set_new(rval, "exclude", json_string(my_instance->nomatch));
|
||||
}
|
||||
|
||||
if (my_session)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tNo. of statements duplicated: %d.\n",
|
||||
my_session->n_duped);
|
||||
dcb_printf(dcb, "\t\tNo. of statements rejected: %d.\n",
|
||||
my_session->n_rejected);
|
||||
json_object_set_new(rval, "duplicated", json_integer(my_session->n_duped));
|
||||
json_object_set_new(rval, "rejected", json_integer(my_session->n_duped));
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,7 +58,7 @@ static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MX
|
||||
static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_UPSTREAM *upstream);
|
||||
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
|
||||
static uint64_t getCapabilities(MXS_FILTER* instance);
|
||||
|
||||
/**
|
||||
@ -573,55 +573,62 @@ clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *reply)
|
||||
*
|
||||
* @param instance The filter instance
|
||||
* @param fsession Filter session, may be NULL
|
||||
* @param dcb The DCB for diagnostic output
|
||||
*/
|
||||
static void
|
||||
diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
|
||||
{
|
||||
TOPN_INSTANCE *my_instance = (TOPN_INSTANCE *) instance;
|
||||
TOPN_SESSION *my_session = (TOPN_SESSION *) fsession;
|
||||
int i;
|
||||
TOPN_INSTANCE *my_instance = (TOPN_INSTANCE*)instance;
|
||||
TOPN_SESSION *my_session = (TOPN_SESSION*)fsession;
|
||||
|
||||
json_t* rval = json_object();
|
||||
|
||||
json_object_set_new(rval, "report_size", json_integer(my_instance->topN));
|
||||
|
||||
dcb_printf(dcb, "\t\tReport size %d\n",
|
||||
my_instance->topN);
|
||||
if (my_instance->source)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLimit logging to connections from %s\n",
|
||||
my_instance->source);
|
||||
json_object_set_new(rval, "source", json_string(my_instance->source));
|
||||
}
|
||||
if (my_instance->user)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLimit logging to user %s\n",
|
||||
my_instance->user);
|
||||
json_object_set_new(rval, "user", json_string(my_instance->user));
|
||||
}
|
||||
|
||||
if (my_instance->match)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
||||
my_instance->match);
|
||||
json_object_set_new(rval, "match", json_string(my_instance->match));
|
||||
}
|
||||
|
||||
if (my_instance->exclude)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
||||
my_instance->exclude);
|
||||
json_object_set_new(rval, "exclude", json_string(my_instance->exclude));
|
||||
}
|
||||
|
||||
if (my_session)
|
||||
{
|
||||
dcb_printf(dcb, "\t\tLogging to file %s.\n",
|
||||
my_session->filename);
|
||||
dcb_printf(dcb, "\t\tCurrent Top %d:\n", my_instance->topN);
|
||||
for (i = 0; i < my_instance->topN; i++)
|
||||
json_object_set_new(rval, "session_filename", json_string(my_session->filename));
|
||||
|
||||
json_t* arr = json_array();
|
||||
|
||||
for (int i = 0; i < my_instance->topN; i++)
|
||||
{
|
||||
if (my_session->top[i]->sql)
|
||||
{
|
||||
dcb_printf(dcb, "\t\t%d place:\n", i + 1);
|
||||
dcb_printf(dcb, "\t\t\tExecution time: %.3f seconds\n",
|
||||
(double) ((my_session->top[i]->duration.tv_sec * 1000)
|
||||
+ (my_session->top[i]->duration.tv_usec / 1000)) / 1000);
|
||||
dcb_printf(dcb, "\t\t\tSQL: %s\n",
|
||||
my_session->top[i]->sql);
|
||||
double exec_time = ((my_session->top[i]->duration.tv_sec * 1000.0)
|
||||
+ (my_session->top[i]->duration.tv_usec / 1000.0)) / 1000.0;
|
||||
|
||||
json_t* obj = json_object();
|
||||
|
||||
json_object_set_new(obj, "rank", json_integer(i + 1));
|
||||
json_object_set_new(obj, "time", json_real(exec_time));
|
||||
json_object_set_new(obj, "sql", json_string(my_session->top[i]->sql));
|
||||
|
||||
json_array_append(arr, obj);
|
||||
}
|
||||
}
|
||||
|
||||
json_object_set_new(rval, "top_queries", arr);
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,7 +85,7 @@ static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession
|
||||
static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_UPSTREAM *upstream);
|
||||
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
|
||||
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
|
||||
static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
|
||||
static uint64_t getCapabilities(MXS_FILTER* instance);
|
||||
static void checkNamedPipe(void *args);
|
||||
|
||||
@ -572,30 +572,40 @@ clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *reply)
|
||||
*
|
||||
* @param instance The filter instance
|
||||
* @param fsession Filter session, may be NULL
|
||||
* @param dcb The DCB for diagnostic output
|
||||
*/
|
||||
static void
|
||||
diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
|
||||
static json_t*
|
||||
diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
|
||||
{
|
||||
TPM_INSTANCE *my_instance = (TPM_INSTANCE *)instance;
|
||||
TPM_SESSION *my_session = (TPM_SESSION *)fsession;
|
||||
int i;
|
||||
TPM_INSTANCE *my_instance = (TPM_INSTANCE*)instance;
|
||||
|
||||
json_t* rval = json_object();
|
||||
|
||||
if (my_instance->source)
|
||||
dcb_printf(dcb, "\t\tLimit logging to connections from %s\n",
|
||||
my_instance->source);
|
||||
{
|
||||
json_object_set_new(rval, "source", json_string(my_instance->source));
|
||||
}
|
||||
|
||||
if (my_instance->user)
|
||||
dcb_printf(dcb, "\t\tLimit logging to user %s\n",
|
||||
my_instance->user);
|
||||
{
|
||||
json_object_set_new(rval, "user", json_string(my_instance->user));
|
||||
}
|
||||
|
||||
if (my_instance->filename)
|
||||
dcb_printf(dcb, "\t\tLogging to file %s.\n",
|
||||
my_instance->filename);
|
||||
{
|
||||
json_object_set_new(rval, "filename", json_string(my_instance->filename));
|
||||
}
|
||||
|
||||
if (my_instance->delimiter)
|
||||
dcb_printf(dcb, "\t\tLogging with delimiter %s.\n",
|
||||
my_instance->delimiter);
|
||||
{
|
||||
json_object_set_new(rval, "delimiter", json_string(my_instance->delimiter));
|
||||
}
|
||||
|
||||
if (my_instance->query_delimiter)
|
||||
dcb_printf(dcb, "\t\tLogging with query delimiter %s.\n",
|
||||
my_instance->query_delimiter);
|
||||
{
|
||||
json_object_set_new(rval, "query_delimiter", json_string(my_instance->query_delimiter));
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user