Skip to content

Commit

Permalink
Merge pull request #4602 from sysown/v2.x-backend_conns_ssl_err_clear
Browse files Browse the repository at this point in the history
Fix SSL error queue cleanup for backend conns
  • Loading branch information
renecannao authored Aug 13, 2024
2 parents 050907e + 1fdaad0 commit 1f4b088
Show file tree
Hide file tree
Showing 7 changed files with 1,033 additions and 34 deletions.
9 changes: 9 additions & 0 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,15 @@ MySQL_Connection * MySQL_HostGroups_Manager::get_MyConn_from_pool(unsigned int _
}

void MySQL_HostGroups_Manager::destroy_MyConn_from_pool(MySQL_Connection *c, bool _lock) {
// 'libmariadbclient' only performs a cleanup of SSL error queue during connect when making use of
// 'auth_caching_sha2_client|auth_sha256_client' during connect. If any SSL errors took place during the
// previous operation, we must cleanup the queue to avoid polluting other backend conns.
int myerr=mysql_errno(c->mysql);
if (myerr >= 2000 && myerr < 3000 && c->mysql->options.use_ssl) {
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 5, "Client error %d detected on SSL connection, cleaning SSL error queue\n", myerr);
ERR_clear_error();
}

bool to_del=true; // the default, legacy behavior
MySrvC *mysrvc=(MySrvC *)c->parent;
if (mysrvc->get_status() == MYSQL_SERVER_STATUS_ONLINE && c->send_quit && queue.size() < __sync_fetch_and_add(&GloMTH->variables.connpoll_reset_queue_length, 0)) {
Expand Down
35 changes: 32 additions & 3 deletions test/tap/tap/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,10 +1586,16 @@ sq3_res_t sqlite3_execute_stmt(sqlite3* db, const string& query) {
return res;
}

json fetch_internal_session(MYSQL* proxy) {
int rc = mysql_query_t(proxy, "PROXYSQL INTERNAL SESSION");
json fetch_internal_session(MYSQL* proxy, bool verbose) {
int rc = 0;

if (verbose) {
rc = mysql_query_t(proxy, "PROXYSQL INTERNAL SESSION");
} else {
rc = mysql_query(proxy, "PROXYSQL INTERNAL SESSION");
}

if (rc ) {
if (rc) {
return json {};
} else {
MYSQL_RES* myres = mysql_store_result(proxy);
Expand All @@ -1601,6 +1607,29 @@ json fetch_internal_session(MYSQL* proxy) {
}
}

map<string, double> parse_prometheus_metrics(const string& s) {
vector<string> lines { split(s, '\n') };
map<string, double> metrics_map {};

for (const string ln : lines) {
const vector<string> line_values { split(ln, ' ') };

if (ln.empty() == false && ln[0] != '#') {
if (line_values.size() > 2) {
size_t delim_pos_st = ln.rfind("} ");
string metric_key = ln.substr(0, delim_pos_st);
string metric_val = ln.substr(delim_pos_st + 2);

metrics_map.insert({metric_key, stod(metric_val)});
} else {
metrics_map.insert({line_values.front(), stod(line_values.back())});
}
}
}

return metrics_map;
}

struct cols_table_info_t {
vector<string> names;
vector<size_t> widths;
Expand Down
12 changes: 11 additions & 1 deletion test/tap/tap/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,18 @@ int64_t get_elem_idx(const T& e, const std::vector<T>& v) {
/**
* @brief Returns a 'JSON' object holding 'PROXYSQL INTERNAL SESSION' contents.
* @param proxy And already openned connection to ProxySQL.
* @param verbose Wether to log or not the issued queries.
*/
nlohmann::json fetch_internal_session(MYSQL* proxy);
nlohmann::json fetch_internal_session(MYSQL* proxy, bool verbose=true);

/**
* @brief Extract the metrics values from the output of:
* - The admin command 'SHOW PROMETHEUS METRICS'.
* - Querying the RESTAPI metrics endpoint.
* @param s ProxySQL prometheus exporter output.
* @return A map of metrics identifiers and values.
*/
std::map<std::string, double> parse_prometheus_metrics(const std::string& s);

/**
* @brief Returns a string table representation of the supplied resultset.
Expand Down
Loading

0 comments on commit 1f4b088

Please sign in to comment.