Some history:
- {T196609}
- {T202144}
- 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 [[ https://codesearch.wmcloud.org/search/?q=getPerDbNameStatsdDataFactory&files=&excludeFiles=&repos= | only used in 17 places ]].