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;
}
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)});
}
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();
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());
}