fix(telemetry): CI Werror — registry .get() and unused fields

Two build failures surfaced by CI on the Phase 9 branch:

1. NetworkOPsImp stores the ServiceRegistry as
   std::reference_wrapper<ServiceRegistry> registry_, so calls must go
   through registry_.get().<method>(). The MetricsRegistry hooks added
   in setMode() and recvValidation() dereferenced the wrapper directly,
   which compiles against a pre-existing accessor on the wrapper type
   on some toolchains but fails on clang 16/17/20 and gcc 13/15 with
   "no member named 'getMetricsRegistry' in
   std::reference_wrapper<xrpl::ServiceRegistry>".

2. MetricsRegistry::app_ and MetricsRegistry::journal_ are only used
   inside XRPL_ENABLE_TELEMETRY-guarded code paths (gauge callbacks
   and JLOG). When telemetry is disabled, clang's
   -Werror=-Wunused-private-field tripped. Move the two fields under
   the same #ifdef and guard the constructor initialisers with
   [[maybe_unused]] so the no-op build continues to compile cleanly.
This commit is contained in:
Pratik Mankawde
2026-05-13 14:11:16 +01:00
parent db04120f74
commit 4cbb1be5b4
3 changed files with 18 additions and 10 deletions

View File

@@ -2536,7 +2536,7 @@ NetworkOPsImp::setMode(OperatingMode om)
accounting_.mode(om);
// Record state change for OTel dashboard parity counter.
if (auto* mr = registry_.getMetricsRegistry())
if (auto* mr = registry_.get().getMetricsRegistry())
mr->incrementStateChanges();
JLOG(m_journal.info()) << "STATE->" << strOperatingMode();
@@ -2547,7 +2547,7 @@ bool
NetworkOPsImp::recvValidation(std::shared_ptr<STValidation> const& val, std::string const& source)
{
JLOG(m_journal.trace()) << "recvValidation " << val->getLedgerHash() << " from " << source;
if (auto* mr = registry_.getMetricsRegistry())
if (auto* mr = registry_.get().getMetricsRegistry())
mr->incrementValidationsChecked();
std::unique_lock lock(validationsMutex_);

View File

@@ -65,8 +65,15 @@ namespace resource = opentelemetry::sdk::resource;
namespace xrpl {
namespace telemetry {
MetricsRegistry::MetricsRegistry(bool enabled, ServiceRegistry& app, beast::Journal journal)
: enabled_(enabled), app_(app), journal_(journal)
MetricsRegistry::MetricsRegistry(
[[maybe_unused]] bool enabled,
[[maybe_unused]] ServiceRegistry& app,
[[maybe_unused]] beast::Journal journal)
: enabled_(enabled)
#ifdef XRPL_ENABLE_TELEMETRY
, app_(app)
, journal_(journal)
#endif
{
}

View File

@@ -340,12 +340,6 @@ private:
/// Master enable flag; when false all methods are no-ops.
bool const enabled_;
/// Reference to Application services for gauge callbacks.
ServiceRegistry& app_;
/// Journal for logging.
beast::Journal const journal_;
/// Tracks validation agreement between this node and the network.
/// Lives outside the XRPL_ENABLE_TELEMETRY guard because it is
/// always safe to record events; the gauge callback simply won't
@@ -353,6 +347,13 @@ private:
ValidationTracker validationTracker_;
#ifdef XRPL_ENABLE_TELEMETRY
/// Reference to Application services for gauge callbacks.
/// Only needed when OTel is compiled in, since observable gauge
/// callbacks live entirely inside the XRPL_ENABLE_TELEMETRY guard.
ServiceRegistry& app_;
/// Journal for logging.
beast::Journal const journal_;
/// The SDK MeterProvider that owns the export pipeline.
std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider> provider_;