diff --git a/include/maxscale/config.hh b/include/maxscale/config.hh index ca3557a5d..61536831c 100644 --- a/include/maxscale/config.hh +++ b/include/maxscale/config.hh @@ -105,6 +105,7 @@ extern const char CN_AUTH_CONNECT_TIMEOUT[]; extern const char CN_AUTH_READ_TIMEOUT[]; extern const char CN_AUTH_WRITE_TIMEOUT[]; extern const char CN_AUTO[]; +extern const char CN_CACHE[]; extern const char CN_CACHE_SIZE[]; extern const char CN_CLASSIFY[]; extern const char CN_CONNECTION_TIMEOUT[]; diff --git a/include/maxscale/json_api.hh b/include/maxscale/json_api.hh index c35df0535..e07d30441 100644 --- a/include/maxscale/json_api.hh +++ b/include/maxscale/json_api.hh @@ -36,6 +36,7 @@ #define MXS_JSON_API_QC_STATS "/maxscale/qc_stats/" #define MXS_JSON_API_QC "/maxscale/query_classifier/" #define MXS_JSON_API_QC_CLASSIFY "/maxscale/query_classifier/classify" +#define MXS_JSON_API_QC_CACHE "/maxscale/query_classifier/cache" #define MXS_JSON_API_USERS "/users/" /** diff --git a/server/core/config.cc b/server/core/config.cc index 61a350af9..ce5d01400 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -92,6 +92,7 @@ const char CN_AUTH_CONNECT_TIMEOUT[] = "auth_connect_timeout"; const char CN_AUTH_READ_TIMEOUT[] = "auth_read_timeout"; const char CN_AUTH_WRITE_TIMEOUT[] = "auth_write_timeout"; const char CN_AUTO[] = "auto"; +const char CN_CACHE[] = "cache"; const char CN_CACHE_SIZE[] = "cache_size"; const char CN_CLASSIFY[] = "classify"; const char CN_CLUSTER[] = "cluster"; diff --git a/server/core/internal/query_classifier.hh b/server/core/internal/query_classifier.hh index 5520159e7..428ba6c1e 100644 --- a/server/core/internal/query_classifier.hh +++ b/server/core/internal/query_classifier.hh @@ -66,4 +66,13 @@ bool qc_alter_from_json(json_t* pJson); */ std::unique_ptr qc_classify_as_json(const char* zHost, const std::string& statement); +/** + * Return query classifier cache content. + * + * @param zHost The MaxScale host. + * + * @return A json object containing information about the query classifier cache. + */ +std::unique_ptr qc_cache_as_json(const char* zHost); + MXS_END_DECLS diff --git a/server/core/query_classifier.cc b/server/core/query_classifier.cc index 13a91534f..b60ecc4d2 100644 --- a/server/core/query_classifier.cc +++ b/server/core/query_classifier.cc @@ -1504,3 +1504,15 @@ std::unique_ptr qc_classify_as_json(const char* zHost, const std::string return std::unique_ptr(mxs_json_resource(zHost, MXS_JSON_API_QC_CLASSIFY, pSelf)); } + +std::unique_ptr qc_cache_as_json(const char* zHost) +{ + json_t* pAttributes = json_object(); + + json_t* pSelf = json_object(); + json_object_set_new(pSelf, CN_ID, json_string(CN_CACHE)); + json_object_set_new(pSelf, CN_TYPE, json_string(CN_CACHE)); + json_object_set_new(pSelf, CN_ATTRIBUTES, pAttributes); + + return std::unique_ptr(mxs_json_resource(zHost, MXS_JSON_API_QC_CACHE, pSelf)); +} diff --git a/server/core/resource.cc b/server/core/resource.cc index 0178a8899..4084050a2 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -691,6 +691,11 @@ HttpResponse cb_qc_classify(const HttpRequest& request) return HttpResponse(MHD_HTTP_OK, qc_classify_as_json(request.host(), sql).release()); } +HttpResponse cb_qc_cache(const HttpRequest& request) +{ + return HttpResponse(MHD_HTTP_OK, qc_cache_as_json(request.host()).release()); +} + HttpResponse cb_thread(const HttpRequest& request) { int id = atoi(request.last_uri_part().c_str()); @@ -969,6 +974,8 @@ public: m_get.push_back(SResource(new Resource(cb_qc, 2, "maxscale", "query_classifier"))); m_get.push_back(SResource(new Resource(cb_qc_classify, 3, "maxscale", "query_classifier", "classify"))); + m_get.push_back(SResource(new Resource(cb_qc_cache, 3, + "maxscale", "query_classifier", "cache"))); m_get.push_back(SResource(new Resource(cb_all_threads, 2, "maxscale", "threads"))); m_get.push_back(SResource(new Resource(cb_thread, 3, "maxscale", "threads", ":thread"))); m_get.push_back(SResource(new Resource(cb_logs, 2, "maxscale", "logs")));