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

Fix value on first fetch for connpool prometheus metrics #4620

Merged
merged 2 commits into from
Aug 21, 2024
Merged
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
6 changes: 4 additions & 2 deletions lib/MySQL_HostGroups_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3314,12 +3314,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool_update_counter(
counter_id->second->Increment(value - cur_val);
} else {
auto& new_counter = status.p_dyn_counter_array[idx];
m_map.insert(
const auto& new_counter_it = m_map.insert(
{
endpoint_id,
std::addressof(new_counter->Add(labels))
}
);
new_counter_it.first->second->Increment(value);
}
}

Expand All @@ -3332,12 +3333,13 @@ void MySQL_HostGroups_Manager::p_update_connection_pool_update_gauge(
counter_id->second->Set(value);
} else {
auto& new_counter = status.p_dyn_gauge_array[idx];
m_map.insert(
const auto& new_gauge_it = m_map.insert(
{
endpoint_id,
std::addressof(new_counter->Add(labels))
}
);
new_gauge_it.first->second->Set(value);
}
}

Expand Down
28 changes: 16 additions & 12 deletions test/tap/tap/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,23 +1607,27 @@ json fetch_internal_session(MYSQL* proxy, bool verbose) {
}
}

pair<string, string> split_line_by_last(const string& ln, char c) {
size_t pos = ln.find_last_of(c);

if (pos == string::npos) {
return { ln, "" };
} else {
const string f { ln.substr(0, pos) };
const string s { ln.substr(pos + 1) };

return { f, s };
}
}

map<string, double> parse_prometheus_metrics(const string& s) {
vector<string> lines { split(s, '\n') };
const 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())});
}
pair<string, string> p_line_val { split_line_by_last(ln, ' ') };
metrics_map.insert({p_line_val.first, stod(p_line_val.second)});
}
}

Expand Down
Loading
Loading