Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "demuxed" status to proxysql_connection_pool_conn to track connections with multiplexing disabled #4474

Open
wants to merge 1 commit into
base: v2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/MySQL_HostGroups_Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ class MySrvConnList {
MySQL_Connection * get_random_MyConn(MySQL_Session *sess, bool ff);
void get_random_MyConn_inner_search(unsigned int start, unsigned int end, unsigned int& conn_found_idx, unsigned int& connection_quality_level, unsigned int& number_of_matching_session_variables, const MySQL_Connection * client_conn);
unsigned int conns_length() { return conns->len; }
unsigned int conns_with_multiplexing_disabled();
void drop_all_connections();
MySQL_Connection *index(unsigned int);
};
Expand Down Expand Up @@ -509,6 +510,7 @@ struct p_hg_dyn_gauge {
enum metric {
connection_pool_conn_free = 0,
connection_pool_conn_used,
connection_pool_conn_demuxed,
connection_pool_latency_us,
connection_pool_status,
__size
Expand Down Expand Up @@ -888,6 +890,7 @@ class MySQL_HostGroups_Manager {
std::map<std::string, prometheus::Gauge*> p_connection_pool_conn_free_map {};
std::map<std::string, prometheus::Counter*> p_connection_pool_conn_ok_map {};
std::map<std::string, prometheus::Gauge*> p_connection_pool_conn_used_map {};
std::map<std::string, prometheus::Gauge*> p_connection_pool_conn_demuxed_map {};
std::map<std::string, prometheus::Gauge*> p_connection_pool_latency_us_map {};
std::map<std::string, prometheus::Counter*> p_connection_pool_queries_map {};
std::map<std::string, prometheus::Gauge*> p_connection_pool_status_map {};
Expand Down
34 changes: 32 additions & 2 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,18 @@ void MySrvList::remove(MySrvC *s) {
servers->remove_index_fast((unsigned int)i);
}

unsigned int MySrvConnList::conns_with_multiplexing_disabled()
{
unsigned int multiplexing_disabled_count = 0;
for (unsigned int i = 0; i < conns_length(); ++i) {
MySQL_Connection* conn = static_cast<MySQL_Connection*>(conns->index(i));
if (conn->MultiplexDisabled()) {
multiplexing_disabled_count++;
}
}
return multiplexing_disabled_count;
}

void MySrvConnList::drop_all_connections() {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Dropping all connections (%u total) on MySrvConnList %p for server %s:%d , hostgroup=%d , status=%d\n", conns_length(), this, mysrvc->address, mysrvc->port, mysrvc->myhgc->hid, mysrvc->status);
while (conns_length()) {
Expand Down Expand Up @@ -1267,19 +1279,27 @@ hg_metrics_map = std::make_tuple(
std::make_tuple (
p_hg_dyn_gauge::connection_pool_conn_free,
"proxysql_connpool_conns",
"How many backend connections are currently (free|used).",
"How many backend connections are currently (free|used|demuxed).",
metric_tags {
{ "status", "free" }
}
),
std::make_tuple (
p_hg_dyn_gauge::connection_pool_conn_used,
"proxysql_connpool_conns",
"How many backend connections are currently (free|used).",
"How many backend connections are currently (free|used|demuxed).",
metric_tags {
{ "status", "used" }
}
),
std::make_tuple (
p_hg_dyn_gauge::connection_pool_conn_demuxed,
"proxysql_connpool_conns",
"How many backend connections are currently (free|used|demuxed).",
metric_tags {
{ "status", "demuxed" }
}
),
std::make_tuple (
p_hg_dyn_gauge::connection_pool_latency_us,
"proxysql_connpool_conns_latency_us",
Expand Down Expand Up @@ -4352,6 +4372,12 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
p_update_connection_pool_update_gauge(endpoint_id, pool_conn_used_labels,
status.p_connection_pool_conn_used_map, mysrvc->ConnectionsUsed->conns_length(), p_hg_dyn_gauge::connection_pool_conn_used);

// proxysql_connection_pool_conn_demuxed metric
std::map<std::string, std::string> pool_conn_demuxed_labels = common_labels;
pool_conn_demuxed_labels.insert({"status", "demuxed"});
p_update_connection_pool_update_gauge(endpoint_id, pool_conn_demuxed_labels,
status.p_connection_pool_conn_demuxed_map, mysrvc->ConnectionsUsed->conns_with_multiplexing_disabled(), p_hg_dyn_gauge::connection_pool_conn_demuxed);

// proxysql_connection_pool_latency_us metric
p_update_connection_pool_update_gauge(endpoint_id, common_labels,
status.p_connection_pool_latency_us_map, mysrvc->current_latency_us, p_hg_dyn_gauge::connection_pool_latency_us);
Expand Down Expand Up @@ -4388,6 +4414,10 @@ void MySQL_HostGroups_Manager::p_update_connection_pool() {
status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_conn_used]->Remove(gauge);
status.p_connection_pool_conn_used_map.erase(key);

gauge = status.p_connection_pool_conn_demuxed_map[key];
status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_conn_demuxed]->Remove(gauge);
status.p_connection_pool_conn_demuxed_map.erase(key);

gauge = status.p_connection_pool_latency_us_map[key];
status.p_dyn_gauge_array[p_hg_dyn_gauge::connection_pool_latency_us]->Remove(gauge);
status.p_connection_pool_latency_us_map.erase(key);
Expand Down
Loading