-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
ALL
-
Service Arch 2022-05-30, Service Arch 2022-06-13, Service Arch 2022-06-27, Service Arch 2022-07-11, Service Arch 2022-07-25
The ServerStatusMetric class manipulates the MetricTree singleton directly, passing an incomplete this pointer from the base class constructor. This is a violation of separation of concern. The singleton's state is not ServerStatusMetric's job.
We have better registry/registration patterns we could use here, including MONGO_INITIALIZER or a more specialized registration API.
Creation of new ServerStatusMetric instances should be done with a factory that creates them and then registers them only when the instance is fully created. Registering before that is to pass an incomplete object, which is an unnecessary risk.
What happens now:
ServerStatusMetric::ServerStatusMetric(const string& nameIn) : _name(nameIn), _leafName(_parseLeafName(nameIn)) { if (MetricTree::theMetricTree == nullptr) MetricTree::theMetricTree = new MetricTree(); MetricTree::theMetricTree->add(this); }
This is a quick cleanup that will make this subsystem cleaner and safer.
- is duplicated by
-
SERVER-67333 ServerStatusMetric API refresh follow-up
- Closed
- related to
-
SERVER-67764 Coverity analysis defect 122495: Resource leak in object
- Closed
-
SERVER-67647 Potentially optimize mongo::MetricTree internal representation
- Open
-
SERVER-65984 Move ServerStatusMetricField specialization out of histogram.h
- Closed
-
SERVER-67644 Certain ServerStatusMetricFields can lead to a data race
- Closed