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: coredump when table name contains '_' and prometheus is enabled #828

Merged
merged 5 commits into from
Oct 19, 2021
Merged
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
20 changes: 11 additions & 9 deletions src/reporter/pegasus_counter_reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,19 @@ void pegasus_counter_reporter::update()
const dsn::perf_counters::counter_snapshot &cs) {
std::string metrics_name = cs.name;

// prometheus metric_name don't support characters like .*()@, it only support ":"
// and "_"
// so change the name to make it all right
format_metrics_name(metrics_name);

// split metric_name like "collector_app_pegasus_app_stat_multi_put_qps:1_0_p999" or
// "collector_app_pegasus_app_stat_multi_put_qps:1_0"
// Splits metric_name like:
// "collector*app.pegasus*[email protected]"
// "collector*app.pegasus*[email protected]"
// app[0] = "1" which is the app(app name or app id)
// app[1] = "0" which is the partition_index
// app[2] = "p999" or "" which represent the percent
std::string app[3] = {"", "", ""};
std::list<std::string> lv;
::dsn::utils::split_args(metrics_name.c_str(), lv, ':');
::dsn::utils::split_args(metrics_name.c_str(), lv, '@');
if (lv.size() > 1) {
std::list<std::string> lv1;
::dsn::utils::split_args(lv.back().c_str(), lv1, '_');
::dsn::utils::split_args(lv.back().c_str(), lv1, '.');
dcheck_le(lv1.size(), 3);
int i = 0;
for (auto &v : lv1) {
app[i] = v;
Expand All @@ -268,6 +265,11 @@ void pegasus_counter_reporter::update()

// create metrics that prometheus support to report data
metrics_name = lv.front() + app[2];

// prometheus metric_name doesn't support characters like .*()@, it only supports ":"
// and "_" so change the name to make it all right.
format_metrics_name(metrics_name);

std::map<std::string, prometheus::Family<prometheus::Gauge> *>::iterator it =
_gauge_family_map.find(metrics_name);
if (it == _gauge_family_map.end()) {
Expand Down