From 6b9918fdcc4088746f7291213f066396c14c187d Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sat, 7 Mar 2026 19:31:12 +0000 Subject: [PATCH] chore: refine guard structures and fix indentation - Fixed indentation for TSDB methods in include/proxysql_admin.h. - Refined PROXYSQLTSDB guard structure in lib/Admin_FlushVariables.cpp. - Cleaned up indentation and redundant code in lib/ProxySQL_RESTAPI_Server.cpp. - Ensured consistent formatting across modified files. --- include/proxysql_admin.h | 12 ++++++------ lib/Admin_FlushVariables.cpp | 8 ++------ lib/ProxySQL_RESTAPI_Server.cpp | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 13f019067..42e371533 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -750,12 +750,12 @@ class ProxySQL_Admin { void save_admin_variables_from_runtime() { flush_admin_variables___runtime_to_database(admindb, true, true, false); } #ifdef PROXYSQLTSDB -// TSDB -void init_tsdb_variables(); -void flush_tsdb_variables___runtime_to_database(SQLite3DB *db, bool replace, bool del, bool onlyifempty, bool runtime=false); -void flush_tsdb_variables___database_to_runtime(SQLite3DB *db, bool replace); -void load_tsdb_variables_to_runtime() { flush_tsdb_variables___database_to_runtime(admindb, true); } -void save_tsdb_variables_from_runtime() { flush_tsdb_variables___runtime_to_database(admindb, true, true, false); } + // TSDB + void init_tsdb_variables(); + void flush_tsdb_variables___runtime_to_database(SQLite3DB *db, bool replace, bool del, bool onlyifempty, bool runtime=false); + void flush_tsdb_variables___database_to_runtime(SQLite3DB *db, bool replace); + void load_tsdb_variables_to_runtime() { flush_tsdb_variables___database_to_runtime(admindb, true); } + void save_tsdb_variables_from_runtime() { flush_tsdb_variables___runtime_to_database(admindb, true, true, false); } #endif void load_or_update_global_settings(SQLite3DB *); diff --git a/lib/Admin_FlushVariables.cpp b/lib/Admin_FlushVariables.cpp index 1918b3596..190affb89 100644 --- a/lib/Admin_FlushVariables.cpp +++ b/lib/Admin_FlushVariables.cpp @@ -199,11 +199,9 @@ void ProxySQL_Admin::flush_GENERIC_variables__process__database_to_runtime( #endif // PROXYSQLCLICKHOUSE } else if (modname == "ldap") { rc = GloMyLdapAuth->set_variable(r->fields[0],r->fields[1]); - } else if (modname == "tsdb") { #ifdef PROXYSQLTSDB + } else if (modname == "tsdb") { rc = GloProxyStats->set_variable(r->fields[0],r->fields[1]); -#else - rc = false; #endif } const string v = string(r->fields[0]); @@ -223,11 +221,9 @@ void ProxySQL_Admin::flush_GENERIC_variables__process__database_to_runtime( #endif // PROXYSQLCLICKHOUSE } else if (modname == "ldap") { val = GloMyLdapAuth->get_variable(r->fields[0]); - } else if (modname == "tsdb") { #ifdef PROXYSQLTSDB + } else if (modname == "tsdb") { val = GloProxyStats->get_variable(r->fields[0]); -#else - val = NULL; #endif } char q[1000]; diff --git a/lib/ProxySQL_RESTAPI_Server.cpp b/lib/ProxySQL_RESTAPI_Server.cpp index e37500fe5..0dcef6ce4 100644 --- a/lib/ProxySQL_RESTAPI_Server.cpp +++ b/lib/ProxySQL_RESTAPI_Server.cpp @@ -416,7 +416,7 @@ public: } } - SQLite3_result *res = GloProxyStats->query_tsdb_metrics(metric, labels, from, to, agg); + SQLite3_result *res = GloProxyStats->query_tsdb_metrics(metric, labels, from, to, agg); if (!res) { j_resp = json::array(); } else { @@ -434,19 +434,19 @@ public: } delete res; } - } else if (req_path == "/api/tsdb/status") { - if (!GloProxyStats) { - j_resp = json {{"error", "TSDB not initialized"}}; - auto response = std::shared_ptr(new string_response(j_resp.dump(), http::http_utils::http_internal_server_error)); - add_headers(response); - return response; - } - ProxySQL_Statistics::tsdb_status_t status = GloProxyStats->get_tsdb_status(); - j_resp["total_series"] = status.total_series; - j_resp["total_datapoints"] = status.total_datapoints; - j_resp["disk_size_bytes"] = status.disk_size_bytes; - j_resp["oldest_datapoint"] = status.oldest_datapoint; - j_resp["newest_datapoint"] = status.newest_datapoint; + } else if (req_path == "/api/tsdb/status") { + if (!GloProxyStats) { + j_resp = json {{"error", "TSDB not initialized"}}; + auto response = std::shared_ptr(new string_response(j_resp.dump(), http::http_utils::http_internal_server_error)); + add_headers(response); + return response; + } + ProxySQL_Statistics::tsdb_status_t status = GloProxyStats->get_tsdb_status(); + j_resp["total_series"] = status.total_series; + j_resp["total_datapoints"] = status.total_datapoints; + j_resp["disk_size_bytes"] = status.disk_size_bytes; + j_resp["oldest_datapoint"] = status.oldest_datapoint; + j_resp["newest_datapoint"] = status.newest_datapoint; } else { return std::shared_ptr(new string_response("Not Found", http::http_utils::http_not_found)); }