Skip to content

Commit 6dc3224

Browse files
committed
common: Allow PerfCounters to return a provided service ID
Dashboard has asked for a unique identifier that can be associated with services. This commit provides a component of that functionality. Enforcing uniqueness is beyond the scope of this PR and is the responsibility of cluster setup and orchestration. The scope of uniqueness is a matter of policy and up to the design of cluster setup and orchestration software. We provide the `--service_unique_id` argument that can be passed on the command line when executing a Ceph service that uses `global_init`. If non-empty, a `service_unique_id` section is added to the PerfCounters dump for that service. This section has a single entry whose name is set to the argument of `service_unique_id` and whose value is arbitrary. If unspecified or empty, no `service_unique_id` section is added. Signed-off-by: Adam C. Emerson <[email protected]>
1 parent bbda58e commit 6dc3224

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/common/ceph_context.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,17 @@ void CephContext::_enable_perf_counter()
987987
}
988988
_mempool_perf = plb2.create_perf_counters();
989989
_perf_counters_collection->add(_mempool_perf);
990+
991+
service_unique_id = _conf.get_val<std::string>("service_unique_id");
992+
if (!service_unique_id.empty()) {
993+
PerfCountersBuilder plb(this, "service_unique_id", l_service_first,
994+
l_service_last);
995+
plb.add_u64(l_service_unique_id, service_unique_id.c_str(),
996+
"Unique ID for this service");
997+
_service_perf = plb.create_perf_counters();
998+
_perf_counters_collection->add(_service_perf);
999+
_service_perf->set(l_service_unique_id, 0);
1000+
}
9901001
}
9911002

9921003
void CephContext::_disable_perf_counter()
@@ -1003,6 +1014,12 @@ void CephContext::_disable_perf_counter()
10031014
_mempool_perf = nullptr;
10041015
_mempool_perf_names.clear();
10051016
_mempool_perf_descriptions.clear();
1017+
1018+
if (_service_perf) {
1019+
_perf_counters_collection->remove(_service_perf);
1020+
delete _service_perf;
1021+
_service_perf = nullptr;
1022+
}
10061023
}
10071024

10081025
void CephContext::_refresh_perf_values()

src/common/ceph_context.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,19 @@ class CephContext {
407407
l_mempool_items,
408408
l_mempool_last
409409
};
410+
// This is just how PerfCounters indices work, we have a bunch of
411+
// bare enums all over.
412+
enum {
413+
// Picked by grepping for the current highest value and adding 1000
414+
l_service_first = 1001000,
415+
l_service_unique_id,
416+
l_service_last
417+
};
410418
PerfCounters *_cct_perf = nullptr;
411419
PerfCounters* _mempool_perf = nullptr;
412420
std::vector<std::string> _mempool_perf_names, _mempool_perf_descriptions;
421+
std::string service_unique_id;
422+
PerfCounters* _service_perf = nullptr;
413423

414424
/**
415425
* Enable the performance counters.

src/common/config.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ int md_config_t::parse_argv(ConfigValues& values,
715715
else if (ceph_argparse_witharg(args, i, &val, "--client_mountpoint", "-r", (char*)NULL)) {
716716
set_val_or_die(values, tracker, "client_mountpoint", val.c_str());
717717
}
718+
else if (ceph_argparse_witharg(args, i, &val, "--service_unique_id", (char*)NULL)) {
719+
set_val_or_die(values, tracker, "service_unique_id", val.c_str());
720+
}
718721
else {
719722
int r = parse_option(values, tracker, args, i, NULL, level);
720723
if (r < 0) {

src/common/options/global.yaml.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6875,3 +6875,20 @@ options:
68756875
level: dev
68766876
default: 0
68776877
desc: When EC writes should generate PDWs (development only) 0=optimal 1=never 2=when possible
6878+
- name: service_unique_id
6879+
type: str
6880+
level: advanced
6881+
desc: Unique string to be returned in PerfCounters
6882+
fmt_desc: A unique id to be created by orchestration software or the
6883+
administrator upon initial setup of a service. Enforcing uniqueness
6884+
is entirely the responsibility of the process used to create and
6885+
manage the cluster. A unique id will be unique within the scope of
6886+
the entire cluster across all services if they are chosen to be so.
6887+
note: If this is empty no uniquifier is provided.
6888+
tags:
6889+
- service
6890+
services:
6891+
- common
6892+
flags:
6893+
- no_mon_update
6894+
- startup

0 commit comments

Comments
 (0)