Some history:
- T196609: Split wikidata dispatch-script metrics by wiki
- T202144: PerDbNameStatsdDataFactory will not submit its stats
- addStaticLabel() was introduced here: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/857061
Originally, addStaticLabel() was created to allow a replacement for perDbNameStatsdDataFactory. To use it as intended, there are several considerations:
- StatsCache must be a singleton instance shared by all instances of StatsFactory
- addStaticLabel() must not affect the global StatsFactory service
- A StatsFactory with static labels must be created prior to any metrics appearing in the cache
- Attempts to use it without a component or with metrics in the cache throw an unhandled IllegalOperationException
I question the wisdom of its current implementation for several reasons:
- It's unsafe to use outside of ServiceWiring
- It mutates the state of a StatsFactory instance
- It's not explicit about its behavior - to anyone looking later, usage looks identical to the "normal" StatsFactory instance when it really isn't
For impact measurement, PerDbNameStatsdDataFactory is only used in 17 places.
Pilot use case: