You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by yu...@apache.org on 2021/10/27 08:41:39 UTC

[incubator-pegasus] 03/03: fix: coredump when table name contains '_' and prometheus is enabled (#828)

This is an automated email from the ASF dual-hosted git repository.

yuchenhe pushed a commit to branch v2.3
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git

commit cd4402382e3f3be1afcf8f8b88699b08725c9014
Author: padmejin <89...@users.noreply.github.com>
AuthorDate: Tue Oct 19 12:27:26 2021 +0800

    fix: coredump when table name contains '_' and prometheus is enabled (#828)
---
 src/reporter/pegasus_counter_reporter.cpp | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp
index f3a8231..507fdd1 100644
--- a/src/reporter/pegasus_counter_reporter.cpp
+++ b/src/reporter/pegasus_counter_reporter.cpp
@@ -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*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
             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;
@@ -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()) {

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org