]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: Allow PerfCounters to return a provided service ID
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 5 Sep 2025 15:31:40 +0000 (11:31 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 18 Sep 2025 16:46:47 +0000 (12:46 -0400)
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 <aemerson@redhat.com>
(cherry picked from commit 6dc322421f7a3758251fe29e3f35934231358011)
Conflicts:
src/common/options/global.yaml.in
 - Preceding options not in Squid

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/ceph_context.cc
src/common/ceph_context.h
src/common/config.cc
src/common/options/global.yaml.in

index 1fe1281e79fdd2b8409e6e654d762188a70b8b3d..7f92211455fa5d22ff999e21c8122105810f1884 100644 (file)
@@ -968,6 +968,17 @@ void CephContext::_enable_perf_counter()
   }
   _mempool_perf = plb2.create_perf_counters();
   _perf_counters_collection->add(_mempool_perf);
+
+  service_unique_id = _conf.get_val<std::string>("service_unique_id");
+  if (!service_unique_id.empty()) {
+    PerfCountersBuilder plb(this, "service_unique_id", l_service_first,
+                           l_service_last);
+    plb.add_u64(l_service_unique_id, service_unique_id.c_str(),
+               "Unique ID for this service");
+    _service_perf = plb.create_perf_counters();
+    _perf_counters_collection->add(_service_perf);
+    _service_perf->set(l_service_unique_id, 0);
+  }
 }
 
 void CephContext::_disable_perf_counter()
@@ -984,6 +995,12 @@ void CephContext::_disable_perf_counter()
   _mempool_perf = nullptr;
   _mempool_perf_names.clear();
   _mempool_perf_descriptions.clear();
+
+  if (_service_perf) {
+    _perf_counters_collection->remove(_service_perf);
+    delete _service_perf;
+    _service_perf = nullptr;
+  }
 }
 
 void CephContext::_refresh_perf_values()
index f1877647877ab590e063ab588ae8aae984ab18e6..24cc7e7f07f32d3836440aa2bf4c78b49bf48ff6 100644 (file)
@@ -382,9 +382,19 @@ private:
     l_mempool_items,
     l_mempool_last
   };
+  // This is just how PerfCounters indices work, we have a bunch of
+  // bare enums all over.
+  enum {
+    // Picked by grepping for the current highest value and adding 1000
+    l_service_first = 1001000,
+    l_service_unique_id,
+    l_service_last
+  };
   PerfCounters *_cct_perf = nullptr;
   PerfCounters* _mempool_perf = nullptr;
   std::vector<std::string> _mempool_perf_names, _mempool_perf_descriptions;
+  std::string service_unique_id;
+  PerfCounters* _service_perf = nullptr;
 
   /**
    * Enable the performance counters.
index e151e94bb90fdbf418a5b3643df305ad182acd3f..062fda5f5532ef67626077614b08c6806f7184d8 100644 (file)
@@ -714,6 +714,9 @@ int md_config_t::parse_argv(ConfigValues& values,
     else if (ceph_argparse_witharg(args, i, &val, "--client_mountpoint", "-r", (char*)NULL)) {
       set_val_or_die(values, tracker, "client_mountpoint", val.c_str());
     }
+    else if (ceph_argparse_witharg(args, i, &val, "--service_unique_id", (char*)NULL)) {
+      set_val_or_die(values, tracker, "service_unique_id", val.c_str());
+    }
     else {
       int r = parse_option(values, tracker, args, i, NULL, level);
       if (r < 0) {
index 58fa15b98ce0316839d1c85cf3d22f6073700927..ddbd12d1f5c9091aad5ca02066df2eb2e926353f 100644 (file)
@@ -6598,3 +6598,20 @@ options:
   desc: Enables exception throwing instead of process abort on transaction submission error.
   default: false
   with_legacy: false
+- name: service_unique_id
+  type: str
+  level: advanced
+  desc: Unique string to be returned in PerfCounters
+  fmt_desc: A unique id to be created by orchestration software or the
+    administrator upon initial setup of a service. Enforcing uniqueness
+    is entirely the responsibility of the process used to create and
+    manage the cluster. A unique id will be unique within the scope of
+    the entire cluster across all services if they are chosen to be so.
+  note: If this is empty no uniquifier is provided.
+  tags:
+  - service
+  services:
+  - common
+  flags:
+  - no_mon_update
+  - startup