The `numCommandsTargetingSystemBuckets` metric is initialized differently to most metrics. While most metrics are registered at file scope, this metric is initialized during the constructor of the SystemBucketsMetricsCommandHooks. That constructor runs when initializeCommandHooks() builds MongodCommandInvocationHooks which is called from _initAndListen().
This triggers an invariant on Windows when the mongod binary is run as a service because metrics are required to all be registered on the main thread. In this mode, rather than main() calling _initAndListen directly, main() calls ntservice::startService(), which uses StartServiceCtrlDispatcherW. That hands off to the SCM service thread, meaning that the timeseries metric is registered from a different thread than the main thread, thus triggering the invariant. We have never seen this in the server testing corpus because we never run windows binaries in this way.
- is caused by
-
SERVER-112599 Introduce server status metrics to track user commands targeting system buckets collections
-
- Closed
-
-
SERVER-123241 Allow adding metric to global metric trees during server initialization only
-
- Closed
-
- related to
-
SERVER-131872 Add test coverage for metric initialization on different threads with Windows
-
- Needs Scheduling
-