From f0760c1e0bce673c76ad2f5a23122bff410cc84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=B3=E6=80=9D=E6=BE=9C?= Date: Fri, 15 Oct 2021 19:01:38 +0800 Subject: [PATCH 1/5] fix coredump when table name contains '_' and prometheus is enabled --- src/reporter/pegasus_counter_reporter.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp index f3a823167d..8776d4a540 100644 --- a/src/reporter/pegasus_counter_reporter.cpp +++ b/src/reporter/pegasus_counter_reporter.cpp @@ -234,22 +234,18 @@ 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" + // 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" // 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 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 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; @@ -268,6 +264,13 @@ void pegasus_counter_reporter::update() // create metrics that prometheus support to report data metrics_name = lv.front() + app[2]; + + // 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); + + std::map *>::iterator it = _gauge_family_map.find(metrics_name); if (it == _gauge_family_map.end()) { From aef6088ddf6fb58b8bf1e2969240156b0d155bf8 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Tue, 19 Oct 2021 11:14:29 +0800 Subject: [PATCH 2/5] Update src/reporter/pegasus_counter_reporter.cpp --- src/reporter/pegasus_counter_reporter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp index 8776d4a540..fd588bf428 100644 --- a/src/reporter/pegasus_counter_reporter.cpp +++ b/src/reporter/pegasus_counter_reporter.cpp @@ -266,8 +266,7 @@ void pegasus_counter_reporter::update() metrics_name = lv.front() + app[2]; // prometheus metric_name don't support characters like .*()@, it only support ":" - // and "_" - // so change the name to make it all right + // and "_" so change the name to make it all right. format_metrics_name(metrics_name); From b189ba0ff6137d254a2f362623298d96b3962185 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Tue, 19 Oct 2021 11:14:41 +0800 Subject: [PATCH 3/5] Update src/reporter/pegasus_counter_reporter.cpp --- src/reporter/pegasus_counter_reporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp index fd588bf428..8282dad3ba 100644 --- a/src/reporter/pegasus_counter_reporter.cpp +++ b/src/reporter/pegasus_counter_reporter.cpp @@ -265,7 +265,7 @@ void pegasus_counter_reporter::update() // create metrics that prometheus support to report data metrics_name = lv.front() + app[2]; - // prometheus metric_name don't support characters like .*()@, it only support ":" + // 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); From 4e249332dfeb902b2e8e885bdae7cc525bf9bde1 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Tue, 19 Oct 2021 11:14:49 +0800 Subject: [PATCH 4/5] Update src/reporter/pegasus_counter_reporter.cpp --- src/reporter/pegasus_counter_reporter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp index 8282dad3ba..bf77e14cb4 100644 --- a/src/reporter/pegasus_counter_reporter.cpp +++ b/src/reporter/pegasus_counter_reporter.cpp @@ -269,7 +269,6 @@ void pegasus_counter_reporter::update() // and "_" so change the name to make it all right. format_metrics_name(metrics_name); - std::map *>::iterator it = _gauge_family_map.find(metrics_name); if (it == _gauge_family_map.end()) { From ffc3def0d2a631a0cebdcf1875438d677d51a92a Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Tue, 19 Oct 2021 11:14:59 +0800 Subject: [PATCH 5/5] Update src/reporter/pegasus_counter_reporter.cpp --- src/reporter/pegasus_counter_reporter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp index bf77e14cb4..507fdd169d 100644 --- a/src/reporter/pegasus_counter_reporter.cpp +++ b/src/reporter/pegasus_counter_reporter.cpp @@ -234,8 +234,9 @@ void pegasus_counter_reporter::update() const dsn::perf_counters::counter_snapshot &cs) { std::string metrics_name = cs.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*app_stat_multi_put_qps@1.0.p999" + // "collector*app.pegasus*app_stat_multi_put_qps@1.0" // 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