MXS-1220: Add JSON return value to diagnostics entry points

The modules that implement a diagnostics entry point now return a JSON
type object. This removes the need to format data inside the modules.

The module implementations of these are not yet complete which means that
MaxScale will fail to compile.
This commit is contained in:
Markus Mäkelä
2017-04-18 04:56:37 +03:00
committed by Markus Mäkelä
parent 94ebef0703
commit bbe0620944
8 changed files with 113 additions and 21 deletions

View File

@ -21,6 +21,7 @@
#include <maxscale/cdefs.h> #include <maxscale/cdefs.h>
#include <maxscale/buffer.h> #include <maxscale/buffer.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
@ -81,7 +82,20 @@ typedef struct mxs_authenticator
void (*free)(struct dcb *); void (*free)(struct dcb *);
void (*destroy)(void *); void (*destroy)(void *);
int (*loadusers)(struct servlistener *); int (*loadusers)(struct servlistener *);
void (*diagnostic)(struct dcb*, struct servlistener *);
/**
* @brief Return diagnostic information about the authenticator
*
* The authenticator module should return information about its internal
* state when this function is called.
*
* @params Listener object
*
* @return JSON representation of the listener
*
* @see jansson.h
*/
json_t* (*diagnostic)(struct servlistener *listener);
/** This entry point was added to avoid calling authenticator functions /** This entry point was added to avoid calling authenticator functions
* directly when a COM_CHANGE_USER command is executed. */ * directly when a COM_CHANGE_USER command is executed. */

View File

@ -23,6 +23,7 @@
#include <maxscale/dcb.h> #include <maxscale/dcb.h>
#include <maxscale/routing.h> #include <maxscale/routing.h>
#include <maxscale/session.h> #include <maxscale/session.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
@ -174,9 +175,12 @@ typedef struct mxs_filter_object
* *
* @param instance Filter instance * @param instance Filter instance
* @param fsession Filter session, NULL if general information about the filter is queried * @param fsession Filter session, NULL if general information about the filter is queried
* @param dcb DCB where the diagnostic information should be written *
* @return JSON formatted information about the filter
*
* @see jansson.h
*/ */
void (*diagnostics)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb); json_t* (*diagnostics)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
/** /**
* @brief Called to obtain the capabilities of the filter * @brief Called to obtain the capabilities of the filter

View File

@ -23,6 +23,7 @@
#include <maxscale/config.h> #include <maxscale/config.h>
#include <maxscale/dcb.h> #include <maxscale/dcb.h>
#include <maxscale/server.h> #include <maxscale/server.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
@ -54,9 +55,38 @@ typedef struct mxs_monitor MXS_MONITOR;
*/ */
typedef struct mxs_monitor_object typedef struct mxs_monitor_object
{ {
/**
* @brief Start the monitor
*
* This entry point is called when the monitor is started. If the monitor
* requires polling of the servers, it should create a separate monitoring
* thread.
*
* @param monitor The monitor object
* @param params Parameters for this monitor
*
* @return Pointer to the monitor specific data, stored in @c monitor->handle
*/
void *(*startMonitor)(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER *params); void *(*startMonitor)(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER *params);
/**
* @brief Stop the monitor
*
* This entry point is called when the monitor is stopped. If the monitor
* uses a polling thread, the thread should be stopped.
*
* @param monitor The monitor object
*/
void (*stopMonitor)(MXS_MONITOR *monitor); void (*stopMonitor)(MXS_MONITOR *monitor);
void (*diagnostics)(DCB *, const MXS_MONITOR *);
/**
* @brief Return diagnostic information about the monitor
*
* @return A JSON object representing the state of the monitor
*
* @see jansson.h
*/
json_t* (*diagnostics)(const MXS_MONITOR *monitor);
} MXS_MONITOR_OBJECT; } MXS_MONITOR_OBJECT;
/** /**

View File

@ -24,6 +24,7 @@
#include <maxscale/routing.h> #include <maxscale/routing.h>
#include <maxscale/service.h> #include <maxscale/service.h>
#include <maxscale/session.h> #include <maxscale/session.h>
#include <maxscale/jansson.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS
@ -144,14 +145,16 @@ typedef struct mxs_router_object
*/ */
int32_t (*routeQuery)(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queue); int32_t (*routeQuery)(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, GWBUF *queue);
/** /**
* @brief Called for diagnostic output * @brief Called for diagnostic output
* *
* @param instance Router instance * @param instance Router instance
* @param dcb DCB where the diagnostic information should be written *
* @return Diagnostic information in JSON format
*
* @see jansson.h
*/ */
void (*diagnostics)(MXS_ROUTER *instance, DCB *dcb); json_t* (*diagnostics)(MXS_ROUTER *instance);
/** /**
* @brief Called for each reply packet * @brief Called for each reply packet

View File

@ -206,7 +206,12 @@ dprintAllFilters(DCB *dcb)
} }
if (ptr->obj && ptr->filter) if (ptr->obj && ptr->filter)
{ {
ptr->obj->diagnostics(ptr->filter, NULL, dcb); json_t* json = ptr->obj->diagnostics(ptr->filter, NULL);
if (json)
{
json_decref(json);
}
} }
else else
{ {
@ -241,7 +246,12 @@ dprintFilter(DCB *dcb, const MXS_FILTER_DEF *filter)
} }
if (filter->obj && filter->filter) if (filter->obj && filter->filter)
{ {
filter->obj->diagnostics(filter->filter, NULL, dcb); json_t* json = filter->obj->diagnostics(filter->filter, NULL);
if (json)
{
json_decref(json);
}
} }
} }
@ -487,8 +497,12 @@ json_t* filter_to_json(const MXS_FILTER_DEF* filter)
if (filter->obj && filter->filter) if (filter->obj && filter->filter)
{ {
// TODO: Add filter diagnostics json_t* diag = filter->obj->diagnostics(filter->filter, NULL);
//filter->obj->diagnostics(filter->filter, NULL, dcb);
if (diag)
{
json_object_set_new(rval, "filter_diagnostics", diag);
}
} }
return rval; return rval;

View File

@ -482,7 +482,12 @@ monitorShow(DCB *dcb, MXS_MONITOR *monitor)
{ {
if (monitor->module->diagnostics) if (monitor->module->diagnostics)
{ {
monitor->module->diagnostics(dcb, monitor); json_t* json = monitor->module->diagnostics(monitor);
if (json)
{
json_decref(json);
}
} }
else else
{ {
@ -1563,8 +1568,12 @@ json_t* monitor_to_json(const MXS_MONITOR* monitor)
if (monitor->handle && monitor->module->diagnostics) if (monitor->handle && monitor->module->diagnostics)
{ {
// TODO: Add monitor diagnostics json_t* diag = monitor->module->diagnostics(monitor);
//monitor->module->diagnostics(dcb, monitor);
if (diag)
{
json_object_set_new(rval, "monitor_diagnostics", diag);
}
} }
return rval; return rval;

View File

@ -1439,7 +1439,12 @@ void dprintService(DCB *dcb, SERVICE *service)
} }
if (service->router && service->router_instance) if (service->router && service->router_instance)
{ {
service->router->diagnostics(service->router_instance, dcb); json_t* json = service->router->diagnostics(service->router_instance);
if (json)
{
json_decref(json);
}
} }
dcb_printf(dcb, "\tStarted: %s", dcb_printf(dcb, "\tStarted: %s",
asctime_r(localtime_r(&service->stats.started, &result), timebuf)); asctime_r(localtime_r(&service->stats.started, &result), timebuf));
@ -2317,7 +2322,12 @@ void service_print_users(DCB *dcb, const SERVICE *service)
{ {
if (port->listener && port->listener->authfunc.diagnostic) if (port->listener && port->listener->authfunc.diagnostic)
{ {
port->listener->authfunc.diagnostic(dcb, port); json_t* json = port->listener->authfunc.diagnostic(port);
if (json)
{
json_decref(json);
}
} }
} }
} }
@ -2382,8 +2392,12 @@ json_t* service_to_json(const SERVICE* service)
if (service->router && service->router_instance) if (service->router && service->router_instance)
{ {
// TODO: Add router diagnostics json_t* diag = service->router->diagnostics(service->router_instance);
//service->router->diagnostics(service->router_instance, dcb);
if (diag)
{
json_object_set_new(rval, "router_diagnostics", diag);
}
} }
struct tm result; struct tm result;

View File

@ -530,9 +530,13 @@ dprintSession(DCB *dcb, MXS_SESSION *print_session)
{ {
dcb_printf(dcb, "\tFilter: %s\n", dcb_printf(dcb, "\tFilter: %s\n",
print_session->filters[i].filter->name); print_session->filters[i].filter->name);
print_session->filters[i].filter->obj->diagnostics(print_session->filters[i].instance, json_t* json = print_session->filters[i].filter->obj->diagnostics(print_session->filters[i].instance,
print_session->filters[i].session, print_session->filters[i].session);
dcb);
if (json)
{
json_decref(json);
}
} }
} }
} }