diff options
author | avanthakkar <avanjohn@gmail.com> | 2023-07-30 23:09:36 +0200 |
---|---|---|
committer | avanthakkar <avanjohn@gmail.com> | 2023-08-01 14:26:47 +0200 |
commit | ca5691834cc30c4f9175bb0b4730750ed9df59cc (patch) | |
tree | 01953f21b9bf527b621d81cae09b3e46c3b0199c | |
parent | Merge pull request #52526 from rhcs-dashboard/volume-create (diff) | |
download | ceph-ca5691834cc30c4f9175bb0b4730750ed9df59cc.tar.xz ceph-ca5691834cc30c4f9175bb0b4730750ed9df59cc.zip |
exporter: fix instance_id labeld value for rgw in exporter
Signed-off-by: avanthakkar <avanjohn@gmail.com>
-rw-r--r-- | src/exporter/DaemonMetricCollector.cc | 22 | ||||
-rw-r--r-- | src/test/exporter/test_exporter.cc | 13 |
2 files changed, 27 insertions, 8 deletions
diff --git a/src/exporter/DaemonMetricCollector.cc b/src/exporter/DaemonMetricCollector.cc index cb95fcaa966..464ec6fdc83 100644 --- a/src/exporter/DaemonMetricCollector.cc +++ b/src/exporter/DaemonMetricCollector.cc @@ -149,6 +149,10 @@ void DaemonMetricCollector::dump_asok_metrics() { if (counters_labels.empty()) { auto labels_and_name = get_labels_and_metric_name(daemon_name, counter_name); + if (labels_and_name.first.empty()) { + dout(1) << "Unable to parse instance_id from daemon_name: " << daemon_name << dendl; + continue; + } labels = labels_and_name.first; counter_name = labels_and_name.second; } @@ -306,13 +310,19 @@ DaemonMetricCollector::get_labels_and_metric_name(std::string daemon_name, labels["instance_id"] = quote(tmp); } else if (daemon_name.find("rgw") != std::string::npos) { - // fetch intance_id for e.g. "okbvtv" from daemon_name=rgw.foo.ceph-node-00.okbvtv - size_t pos = daemon_name.find_last_of("."); - std::string instance_id = ""; - if (pos != std::string::npos) { - instance_id = daemon_name.substr(pos+1); + // fetch intance_id for e.g. "hrgsea" from daemon_name=rgw.foo.ceph-node-00.hrgsea.2.94739968030880 + std::vector<std::string> elems; + std::stringstream ss; + ss.str(daemon_name); + std::string item; + while (std::getline(ss, item, '.')) { + elems.push_back(item); + } + if (elems.size() >= 4) { + labels["instance_id"] = quote(elems[3]); + } else { + return std::make_pair(labels_t(), ""); } - labels["instance_id"] = quote(instance_id); } else { labels.insert({"ceph_daemon", quote(daemon_name)}); } diff --git a/src/test/exporter/test_exporter.cc b/src/test/exporter/test_exporter.cc index 7bc44d9b321..03b2db91760 100644 --- a/src/test/exporter/test_exporter.cc +++ b/src/test/exporter/test_exporter.cc @@ -668,11 +668,11 @@ TEST(Exporter, promethize) { TEST(Exporter, check_labels_and_metric_name) { static std::vector<std::pair<std::string, std::string>> counters_data; counters_data.emplace_back("ceph-osd.0", "ceph_osd_numpg"); - counters_data.emplace_back("ceph-client.rgw.foo.ceph-node-00.okbvtv", "ceph_rgw_get"); + counters_data.emplace_back("ceph-client.rgw.foo.ceph-node-00.hrgsea.2.94739968030880", "ceph_rgw_get"); static std::vector<std::pair<labels_t, std::string>> labels_and_name; labels_and_name.emplace_back(labels_t{{"ceph_daemon", "\"osd.0\""}}, "ceph_osd_numpg"); - labels_and_name.emplace_back(labels_t{{"instance_id", "\"okbvtv\""}}, "ceph_rgw_get"); + labels_and_name.emplace_back(labels_t{{"instance_id", "\"hrgsea\""}}, "ceph_rgw_get"); auto counter_data_itr = counters_data.begin(); auto labels_and_name_itr = labels_and_name.begin(); for (; counter_data_itr != counters_data.end() && labels_and_name_itr != labels_and_name.end(); @@ -684,4 +684,13 @@ TEST(Exporter, check_labels_and_metric_name) { ASSERT_EQ(result.first, labels_and_name_itr->first); ASSERT_EQ(result.second, labels_and_name_itr->second); } + // test for fail case with daemon_name.size() < 4 + std::string short_daemon_name = "ceph-client.rgw.foo"; + std::string counter_name = "ceph_rgw_get"; + DaemonMetricCollector &collector = collector_instance(); + std::pair<labels_t, std::string> fail_result = collector.get_labels_and_metric_name(short_daemon_name, counter_name); + // This is a special case, the daemon name is not of the required size for fetching instance_id. + // So no labels should be added. + ASSERT_TRUE(fail_result.first.empty()); + ASSERT_TRUE(fail_result.second.empty()); } |