-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
DB Integration & Observability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Build the process-wide MetricsRegistry for the unified metrics framework (epic SPM-4962), plus the registration codegen that feeds it. This ticket absorbs SERVER-138333 (registration codegen): the registration spec, the macro, and the generated initializers are one contract with the registry that consumes them.
Scope of Work
- One registry per process, created explicitly via materialize(ServiceContext*) and accessed via MetricsRegistry::get().
- Members: _sections, _scrapeBuckets, _ownedLeaves, _ownedLeafPaths, and the one-time _materialized flag.
- Materialization iterates every registration once, sorted by path: resolve stats, run MetricsRegistryTraits<Stats>::bind, validate and claim leaves.
- Enforce single-path ownership: a duplicate leaf path fails startup via invariant.
- Contributor forms in this ticket: generated leaves (default), the appender: C++ form (void(BSONObjBuilder*)) reachable via MONGO_REGISTER_METRICS, and isEnabled.
- Registration codegen: per-file MONGO_INITIALIZER (RegisterMetrics_<file_path>) in the generated _gen.cpp calling addMetricsRegistration directly, with a generated default state binding (stats instance) and leaves factory, bounded by the BeginMetricsRegistration/EndMetricsRegistration initializer groups.
- replaceMetricsRegistration for C++ overrides of a generated registration, pre-materialization only, with a catalog shape check.
- unmaterialize() returns the registry to an unmaterialized state for tests that construct repeated ServiceContexts; production code never calls it.
Out of scope
- Name governance build-time validator and metrics_name_exceptions.yml: owned by SERVER-139210, which plugs into the validation pass built in SERVER-138594.
- configAppender (RenderContext) and the IDL appender: override: SERVER-138334.
- OTel instrument binding and counter backfill: SERVER-138334.
- Startup wiring into mongod_main/mongos_main (observability::initialize): SERVER-138334.
Design source
Technical Design: Unified Metrics Framework, Registration and Process Lifecycle tab: "The MetricsRegistry", "Materialization", "Unmaterialization", "Registration Concurrency", "Grammar", "Registration", "Startup Ordering".
- blocks
-
SERVER-138334 Rendering: OTel bindings and serverStatus BSON export
-
- Needs Scheduling
-
- is blocked by
-
SERVER-138331 Codegen to create metrics structs (<file>_metrics_gen.h/cpp and metrics_sections.idl)
-
- In Code Review
-
- is duplicated by
-
SERVER-138333 Registration codegen: per-file MONGO_INITIALIZER metrics registration
-
- Closed
-
- is related to
-
SERVER-138594 Metrics grammar binder validation in the IDL compiler
-
- In Code Review
-
-
SERVER-139210 Enforce metric name governance in the IDL compiler (mongodb. prefix, component rules, OTel instrument names)
-
- Needs Scheduling
-