From 8956b672f430fa5586ef4a6f6c63a367a260ef67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 14 Feb 2022 13:20:21 +0100 Subject: [PATCH] Remove 'admin_mysql_ifaces' from metrics labels for 'proxysql_servers_clients_status' --- include/proxysql_admin.h | 2 +- lib/ProxySQL_Admin.cpp | 32 ++++++-------------------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 7bed3b817..86088f6e9 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -208,7 +208,7 @@ class ProxySQL_Admin { std::array p_gauge_array {}; std::array*, p_admin_dyn_gauge::__size> p_dyn_gauge_array {}; - std::map> p_proxysql_servers_clients_status_map {}; + std::map p_proxysql_servers_clients_status_map {}; } metrics; ProxySQL_External_Scheduler *scheduler; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index d9990770a..547100f40 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -5052,34 +5052,14 @@ __run_query: q += std::to_string(now) + ")"; SPA->statsdb->execute(q.c_str()); - std::map m_labels { - { "uuid", uuid }, { "hostname", hostname }, { "port", port }, { "admin_mysql_ifaces", mysql_ifaces } - }; + std::map m_labels { { "uuid", uuid }, { "hostname", hostname }, { "port", port } }; const string m_id { uuid + ":" + hostname + ":" + port }; - auto& m_client_status_map = SPA->metrics.p_proxysql_servers_clients_status_map; - auto* gauge_family = SPA->metrics.p_dyn_gauge_array[p_admin_dyn_gauge::proxysql_servers_clients_status_last_seen_at]; - - // NOTE: Since 'admin_mysql_ifaces' is part of the metric labels, we need to delete the metric in - // case it doesn't match the current value, in order to match table behavior. - // TODO: Check if 'admin_mysql_ifaces' should be removed as label, as it's not really part of the - // metric definition and it's a dynamic configuration. - auto entry_it = m_client_status_map.find(m_id); - if (entry_it != m_client_status_map.end()) { - if (entry_it->second.first != mysql_ifaces) { - gauge_family->Remove(entry_it->second.second); - m_client_status_map.erase(entry_it); - } - } - const auto& id_val = m_client_status_map.find(m_id); - if (id_val != m_client_status_map.end()) { - id_val->second.second->Set(now); - } else { - prometheus::Gauge* new_counter = std::addressof(gauge_family->Add(m_labels)); - m_client_status_map.insert({m_id, { mysql_ifaces, new_counter }}); - - new_counter->Set(now); - } + p_update_map_gauge( + SPA->metrics.p_proxysql_servers_clients_status_map, + SPA->metrics.p_dyn_gauge_array[p_admin_dyn_gauge::proxysql_servers_clients_status_last_seen_at], + m_id, m_labels, now + ); } } if (run_query) {