Add support for multiple runtime error messages

Storing all the runtime errors makes it possible to return all of them
them via the REST API. MaxAdmin will still only show the latest error but
MaxCtrl will now show all errors if more than one error occurs.
This commit is contained in:
Markus Mäkelä
2019-03-21 11:47:21 +02:00
parent 74eeb64fba
commit 203bba0e1d
24 changed files with 57 additions and 165 deletions

View File

@ -26,7 +26,7 @@
#include <maxscale/users.h>
#include <maxscale/adminusers.h>
#include <maxscale/paths.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
/**
* @file adminusers.c - Administration user account management

View File

@ -46,7 +46,7 @@
#include <maxscale/clock.h>
#include <maxscale/housekeeper.h>
#include <maxscale/http.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/limits.h>
#include <maxscale/maxscale.h>
#include <maxscale/maxadmin.h>

View File

@ -29,7 +29,7 @@
#include <maxbase/atomic.h>
#include <maxscale/clock.h>
#include <maxscale/jansson.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/paths.h>
#include <maxscale/router.hh>
#include <maxscale/users.h>
@ -50,23 +50,31 @@ using maxscale::Monitor;
static std::mutex crt_lock;
#define RUNTIME_ERRMSG_BUFSIZE 512
thread_local char runtime_errmsg[RUNTIME_ERRMSG_BUFSIZE];
thread_local std::vector<std::string> runtime_errmsg;
typedef std::function<bool (const std::string&, const std::string&)> JsonValidator;
typedef std::pair<const char*, JsonValidator> Relationship;
void config_runtime_error(const char* fmt, ...)
{
char errmsg[RUNTIME_ERRMSG_BUFSIZE];
va_list list;
va_start(list, fmt);
vsnprintf(runtime_errmsg, sizeof(runtime_errmsg), fmt, list);
vsnprintf(errmsg, sizeof(errmsg), fmt, list);
va_end(list);
runtime_errmsg.push_back(errmsg);
}
static std::string runtime_get_error()
{
std::string rval(runtime_errmsg);
runtime_errmsg[0] = '\0';
std::string rval;
if (!runtime_errmsg.empty())
{
rval = runtime_errmsg.back();
runtime_errmsg.clear();
}
return rval;
}
@ -2779,11 +2787,11 @@ bool runtime_create_listener_from_json(Service* service, json_t* json)
json_t* runtime_get_json_error()
{
json_t* obj = NULL;
std::string errmsg = runtime_get_error();
if (errmsg.length())
if (!runtime_errmsg.empty())
{
obj = mxs_json_error(errmsg.c_str());
obj = mxs_json_error(runtime_errmsg);
runtime_errmsg.clear();
}
return obj;

View File

@ -35,7 +35,7 @@
#include <maxscale/session.hh>
#include <maxscale/service.hh>
#include <maxscale/filter.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include "internal/config.hh"
#include "internal/modules.hh"

View File

@ -25,7 +25,7 @@
#include <maxscale/clock.h>
#include <maxscale/config.hh>
#include <maxscale/housekeeper.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/query_classifier.hh>
/**

View File

@ -11,7 +11,7 @@
* Public License.
*/
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <string>
@ -207,6 +207,24 @@ json_t* mxs_json_error(const char* format, ...)
return json_error(message);
}
json_t* mxs_json_error(const std::vector<std::string>& errors)
{
json_t* rval = nullptr;
if (!errors.empty())
{
auto it = errors.begin();
rval = json_error(it->c_str());
for (it = std::next(it); it != errors.end(); ++it)
{
rval = mxs_json_error_append(rval, it->c_str());
}
}
return rval;
}
static json_t* json_error_append(json_t* obj, const char* message)
{
json_t* err = json_error_detail(message);

View File

@ -28,7 +28,7 @@
#include <maxscale/version.h>
#include <maxscale/paths.h>
#include <maxscale/alloc.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/modulecmd.hh>
#include <maxscale/protocol.hh>
#include <maxscale/router.hh>

View File

@ -23,7 +23,7 @@
#include <maxbase/logger.hh>
#include <maxscale/config.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/session.hh>
namespace

View File

@ -32,7 +32,7 @@
#include <maxscale/alloc.h>
#include <maxbase/atomic.hh>
#include <maxscale/clock.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/mariadb.hh>
#include <maxscale/mysql_utils.hh>
#include <maxscale/paths.h>
@ -40,7 +40,7 @@
#include <maxscale/routingworker.hh>
#include <maxscale/secrets.h>
#include <maxscale/utils.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <mysqld_error.h>
#include "internal/config.hh"

View File

@ -21,7 +21,7 @@
#include <maxbase/atomic.h>
#include <maxbase/format.hh>
#include <maxscale/config.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/modutil.hh>
#include <maxscale/pcre2.h>
#include <maxscale/utils.h>

View File

@ -21,7 +21,7 @@
#include <maxscale/housekeeper.h>
#include <maxscale/http.hh>
#include <maxscale/jansson.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/modulecmd.hh>
#include <maxscale/routingworker.hh>

View File

@ -30,7 +30,7 @@
#include <maxscale/config.hh>
#include <maxscale/clock.h>
#include <maxscale/limits.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/utils.hh>
#include <maxscale/statistics.hh>

View File

@ -38,7 +38,7 @@
#include <maxscale/alloc.h>
#include <maxscale/paths.h>
#include <maxscale/utils.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/clock.h>
#include <maxscale/http.hh>
#include <maxscale/maxscale.h>

View File

@ -51,7 +51,7 @@
#include <maxscale/utils.h>
#include <maxscale/utils.hh>
#include <maxscale/version.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/routingworker.hh>
#include <maxscale/routingworker.hh>

View File

@ -31,7 +31,7 @@
#include <maxscale/clock.h>
#include <maxscale/dcb.hh>
#include <maxscale/housekeeper.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/modutil.hh>
#include <maxscale/poll.hh>
#include <maxscale/router.hh>

View File

@ -16,7 +16,7 @@
#include <string>
#include <maxscale/jansson.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
using std::string;

View File

@ -21,7 +21,7 @@
#include <maxscale/paths.h>
#include <maxscale/modulecmd.hh>
#include <maxscale/session.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include "../internal/monitor.hh"

View File

@ -14,7 +14,7 @@
#define MXS_MODULE_NAME "masking"
#include "maskingfilter.hh"
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/modulecmd.hh>
#include <maxscale/paths.h>
#include <maxscale/utils.h>

View File

@ -22,7 +22,7 @@
#include <maxscale/mysql_utils.hh>
#include <maxscale/pcre2.hh>
#include <maxscale/utils.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
using std::auto_ptr;
using std::string;

View File

@ -45,7 +45,7 @@
#include <maxscale/service.hh>
#include <maxscale/utils.h>
#include <maxscale/modulecmd.hh>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
using std::string;
@ -100,7 +100,6 @@ void print_string_replace_newlines(const char* sql_string, size_t sql_str_len,
const char* rep_newline, std::stringstream* output);
bool check_replace_file(const string& filename, FILE** ppFile);
}
QlaInstance::QlaInstance(const string& name, MXS_CONFIG_PARAMETER* params)

View File

@ -8,7 +8,7 @@
#include <maxscale/ccdefs.hh>
#include <maxscale/utils.h>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include <maxscale/jansson.hh>
#include "throttlefilter.hh"

View File

@ -14,7 +14,7 @@
#include "clustrixmonitor.hh"
#include <algorithm>
#include <set>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
#include "../../../core/internal/config_runtime.hh"
#include "../../../core/internal/service.hh"

View File

@ -21,7 +21,7 @@
#include <maxscale/ccdefs.hh>
#include <string>
#include <maxscale/json_api.h>
#include <maxscale/json_api.hh>
/** Utility macros for printing both MXS_ERROR and json error */
#define PRINT_MXS_JSON_ERROR(err_out, format, ...) \