MXS-1220: Add old diagnostic interface for monitors and authenticators

Added back the old diagnostic entry point in the monitor and authenticator
interfaces.
This commit is contained in:
Markus Mäkelä 2017-04-21 12:14:12 +03:00 committed by Markus Mäkelä
parent 07175ed86b
commit b1294f083c
14 changed files with 158 additions and 16 deletions

View File

@ -167,6 +167,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /* No destroy entry point */
cdc_replace_users, /* Load CDC users */
users_default_diagnostic, /* Default diagnostic */
users_default_diagnostic_json, /* Default diagnostic */
NULL /* No user reauthentication */
};

View File

@ -666,6 +666,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
gssapi_auth_free, /* Free authenticator data */
gssapi_auth_load_users, /* Load database users */
users_default_diagnostic, /* Default user diagnostic */
users_default_diagnostic_json, /* Default user diagnostic */
NULL /* No user reauthentication */
};

View File

@ -278,6 +278,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
gssapi_backend_auth_free, /* Free authenticator data */
NULL, /* Load users from backend databases */
NULL, /* No diagnostic */
NULL,
NULL /* No user reauthentication */
};

View File

@ -68,6 +68,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /* No destroy entry point */
users_default_loadusers, /* Load generic users */
users_default_diagnostic, /* Default user diagnostic */
users_default_diagnostic_json, /* Default user diagnostic */
NULL /* No user reauthentication */
};

View File

@ -62,6 +62,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /* No destroy entry point */
users_default_loadusers, /* Load generic users */
users_default_diagnostic, /* Default user diagnostic */
users_default_diagnostic_json, /* Default user diagnostic */
NULL /* No user reauthentication */
};

View File

@ -58,7 +58,8 @@ static int mysql_auth_set_client_data(
MySQLProtocol *protocol,
GWBUF *buffer);
json_t* mysql_auth_diagnostic(const SERV_LISTENER *port);
void mysql_auth_diagnostic(DCB *dcb, SERV_LISTENER *port);
json_t* mysql_auth_diagnostic_json(const SERV_LISTENER *port);
int mysql_auth_reauthenticate(DCB *dcb, const char *user,
uint8_t *token, size_t token_len,
@ -85,6 +86,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
mysql_auth_destroy, /* Destroy entry point */
mysql_auth_load_users, /* Load users from backend databases */
mysql_auth_diagnostic,
mysql_auth_diagnostic_json,
mysql_auth_reauthenticate /* Handle COM_CHANGE_USER */
};
@ -681,6 +683,30 @@ int mysql_auth_reauthenticate(DCB *dcb, const char *user,
}
int diag_cb(void *data, int columns, char **row, char **field_names)
{
DCB *dcb = (DCB*)data;
dcb_printf(dcb, "%s@%s ", row[0], row[1]);
return 0;
}
void mysql_auth_diagnostic(DCB *dcb, SERV_LISTENER *port)
{
dcb_printf(dcb, "User names: ");
MYSQL_AUTH *instance = (MYSQL_AUTH*)port->auth_instance;
char *err;
if (sqlite3_exec(instance->handle, "SELECT user, host FROM " MYSQLAUTH_USERS_TABLE_NAME,
diag_cb, dcb, &err) != SQLITE_OK)
{
dcb_printf(dcb, "Failed to print users: %s\n", err);
MXS_ERROR("Failed to print users: %s", err);
sqlite3_free(err);
}
dcb_printf(dcb, "\n");
}
int diag_cb_json(void *data, int columns, char **row, char **field_names)
{
json_t* obj = json_object();
json_object_set_new(obj, "user", json_string(row[0]));
@ -691,7 +717,7 @@ int diag_cb(void *data, int columns, char **row, char **field_names)
return 0;
}
json_t* mysql_auth_diagnostic(const SERV_LISTENER *port)
json_t* mysql_auth_diagnostic_json(const SERV_LISTENER *port)
{
json_t* rval = json_array();

View File

@ -171,6 +171,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
auth_backend_destroy, /* Destroy authenticator */
NULL, /* We don't need to load users */
NULL, /* No diagnostic */
NULL,
NULL /* No user reauthentication */
};

View File

@ -64,6 +64,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /* No destroy entry point */
users_default_loadusers, /* Load generic users */
NULL, /* No diagnostic */
NULL,
NULL /* No user reauthentication */
};

View File

@ -61,6 +61,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /* No destroy entry point */
users_default_loadusers, /* Load generic users */
NULL, /* No diagnostic */
NULL,
NULL /* No user reauthentication */
};

View File

@ -245,7 +245,18 @@ stopMonitor(MXS_MONITOR *mon)
* @param dcb DCB to send output
* @param mon The monitor
*/
static json_t* diagnostics(const MXS_MONITOR *mon)
static void
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
{
}
/**
* Diagnostic interface
*
* @param dcb DCB to send output
* @param mon The monitor
*/
static json_t* diagnostics_json(const MXS_MONITOR *mon)
{
return NULL;
}
@ -263,7 +274,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
{
startMonitor,
stopMonitor,
diagnostics
diagnostics,
diagnostics_json
};
static MXS_MODULE info =

View File

@ -49,7 +49,8 @@ static bool warn_erange_on_local_index = true;
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params);
static void stopMonitor(MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *);
static MXS_MONITOR_SERVERS *get_candidate_master(MXS_MONITOR*);
static MXS_MONITOR_SERVERS *set_cluster_master(MXS_MONITOR_SERVERS *, MXS_MONITOR_SERVERS *, int);
static void disableMasterFailback(void *, int);
@ -80,7 +81,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
{
startMonitor,
stopMonitor,
diagnostics
diagnostics,
diagnostics_json
};
static MXS_MODULE info =
@ -218,9 +220,36 @@ stopMonitor(MXS_MONITOR *mon)
/**
* Diagnostic interface
*
* @param dcb DCB to send output
* @param arg The monitor handle
*/
static json_t* diagnostics(const MXS_MONITOR *mon)
static void
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
{
const GALERA_MONITOR *handle = (const GALERA_MONITOR *) mon->handle;
dcb_printf(dcb, "Master Failback:\t%s\n", (handle->disableMasterFailback == 1) ? "off" : "on");
dcb_printf(dcb, "Available when Donor:\t%s\n", (handle->availableWhenDonor == 1) ? "on" : "off");
dcb_printf(dcb, "Master Role Setting Disabled:\t%s\n",
handle->disableMasterRoleSetting ? "on" : "off");
dcb_printf(dcb, "Set wsrep_sst_donor node list:\t%s\n", (handle->set_donor_nodes == 1) ? "on" : "off");
if (handle->cluster_info.c_uuid)
{
dcb_printf(dcb, "Galera Cluster UUID:\t%s\n", handle->cluster_info.c_uuid);
dcb_printf(dcb, "Galera Cluster size:\t%d\n", handle->cluster_info.c_size);
}
else
{
dcb_printf(dcb, "Galera Cluster NOT set:\tno member nodes\n");
}
}
/**
* Diagnostic interface
*
* @param arg The monitor handle
*/
static json_t* diagnostics_json(const MXS_MONITOR *mon)
{
json_t* rval = json_object();
const GALERA_MONITOR *handle = (const GALERA_MONITOR *)mon->handle;

View File

@ -39,7 +39,8 @@ MXS_MODULE info =
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *);
static void stopMonitor(MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *);
static void detectStaleMaster(void *, int);
static MXS_MONITOR_SERVERS *get_current_master(MXS_MONITOR *);
static bool isMySQLEvent(mxs_monitor_event_t event);
@ -60,7 +61,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
{
startMonitor,
stopMonitor,
diagnostics
diagnostics,
diagnostics_json
};
static MXS_MODULE info =
@ -166,9 +168,22 @@ stopMonitor(MXS_MONITOR *mon)
/**
* Diagnostic interface
*
* @param dcb DCB to print diagnostics
* @param arg The monitor handle
*/
static json_t* diagnostics(const MXS_MONITOR *mon)
static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
{
const MM_MONITOR *handle = (const MM_MONITOR *) mon->handle;
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
}
/**
* Diagnostic interface
*
* @param arg The monitor handle
*/
static json_t* diagnostics_json(const MXS_MONITOR *mon)
{
const MM_MONITOR *handle = (const MM_MONITOR *)mon->handle;

View File

@ -48,7 +48,8 @@ static void monitorMain(void *);
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER*);
static void stopMonitor(MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *);
static MXS_MONITOR_SERVERS *getServerByNodeId(MXS_MONITOR_SERVERS *, long);
static MXS_MONITOR_SERVERS *getSlaveOfNodeId(MXS_MONITOR_SERVERS *, long);
static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *, int);
@ -76,7 +77,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
{
startMonitor,
stopMonitor,
diagnostics
diagnostics,
diagnostics_json
};
static MXS_MODULE info =
@ -310,12 +312,49 @@ stopMonitor(MXS_MONITOR *mon)
thread_wait(handle->thread);
}
/**
* Daignostic interface
*
* @param dcb DCB to print diagnostics
* @param arg The monitor handle
*/
static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
{
const MYSQL_MONITOR *handle = (const MYSQL_MONITOR *)mon->handle;
dcb_printf(dcb, "MaxScale MonitorId:\t%lu\n", handle->id);
dcb_printf(dcb, "Replication lag:\t%s\n", (handle->replicationHeartbeat == 1) ? "enabled" : "disabled");
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
dcb_printf(dcb, "Server information\n\n");
for (MXS_MONITOR_SERVERS *db = mon->databases; db; db = db->next)
{
MYSQL_SERVER_INFO *serv_info = hashtable_fetch(handle->server_info, db->server->unique_name);
dcb_printf(dcb, "Server: %s\n", db->server->unique_name);
dcb_printf(dcb, "Server ID: %d\n", serv_info->server_id);
dcb_printf(dcb, "Read only: %s\n", serv_info->read_only ? "ON" : "OFF");
dcb_printf(dcb, "Slave configured: %s\n", serv_info->slave_configured ? "YES" : "NO");
dcb_printf(dcb, "Slave IO running: %s\n", serv_info->slave_io ? "YES" : "NO");
dcb_printf(dcb, "Slave SQL running: %s\n", serv_info->slave_sql ? "YES" : "NO");
dcb_printf(dcb, "Master ID: %d\n", serv_info->master_id);
dcb_printf(dcb, "Master binlog file: %s\n", serv_info->binlog_name);
dcb_printf(dcb, "Master binlog position: %lu\n", serv_info->binlog_pos);
if (handle->multimaster)
{
dcb_printf(dcb, "Master group: %d\n", serv_info->group);
}
dcb_printf(dcb, "\n");
}
}
/**
* Diagnostic interface
*
* @param arg The monitor handle
*/
static json_t* diagnostics(const MXS_MONITOR *mon)
static json_t* diagnostics_json(const MXS_MONITOR *mon)
{
json_t* rval = json_object();

View File

@ -41,7 +41,8 @@ static void monitorMain(void *);
static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params);
static void stopMonitor(MXS_MONITOR *);
static json_t* diagnostics(const MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *);
bool isNdbEvent(mxs_monitor_event_t event);
@ -62,7 +63,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
{
startMonitor,
stopMonitor,
diagnostics
diagnostics,
diagnostics_json
};
static MXS_MODULE info =
@ -170,7 +172,18 @@ stopMonitor(MXS_MONITOR *mon)
* @param dcb DCB to send output
* @param arg The monitor handle
*/
static json_t* diagnostics(const MXS_MONITOR *mon)
static void
diagnostics(DCB *dcb, const MXS_MONITOR *mon)
{
}
/**
* Diagnostic interface
*
* @param dcb DCB to send output
* @param arg The monitor handle
*/
static json_t* diagnostics_json(const MXS_MONITOR *mon)
{
return NULL;
}