Page MenuHomePhabricator

Support emitting a single sample to multiple statsd namespaces
Closed, ResolvedPublic

Description

  1. copyToStatsdAt() accepts a singular statsd namespace as a string.
  2. Subsequent calls will overwrite the previous namespace.
  3. There are instances in the codebase where we emit the same value toward multiple statsd namespaces.

I propose we create some feature that allows us to emit the same sample toward multiple statsd namespaces.
Providing a happy path for this use case will hopefully reduce errors in the migration.

Some previous discussion here.

Event Timeline

I see a few options for the api:

# multiple cached calls
getCounter('name')
    ->copyToStatsdAt('this.namespace')
    ->copyToStatsdAt('this.namespace.too')
    ->copyToStatsdAt('and.this.namespace')
    ->increment();
# change from string to array<str>
getCounter('name')
    ->copyToStatsdAt(['this.namespace', 'this.namespace.too', 'and.this.namespace'])
    ->increment();
# support both with different methods?
getCounter('name')
    ->copyToStatsdAt('this.namespace')
    ->increment();

getCounter('name')
    ->copyToStatsdAtMultiple(['this.namespace', 'this.namespace.too', 'and.this.namespace'])
    ->increment();

@DAlangi_WMF do you have a preference or want to propose another idea?

colewhite moved this task from Backlog to Up Next on the MediaWiki-libs-Stats board.

@colewhite, I like option 3. We already have plenty of places in our code bases where we support this kind of API for methods/functions (e.g. our config system and query builder - [1][2][3]) and also, I prefer it over option 1 which is purely fluent because we don't have to repeat calls/let the developer know they have to do this 3 times for the same method call. So option 3 would just take an array of keys and the magic will happen in the underground implementation.

I see option 2 is already covered by option 3, so option 3 wins I guess.

[1] https://gerrit.wikimedia.org/g/mediawiki/core/+/9e9d76a8200f159101e1eb034e5a324aa2c7a9ce/tests/phpunit/MediaWikiIntegrationTestCase.php#990
[2] https://gerrit.wikimedia.org/g/mediawiki/core/+/9e9d76a8200f159101e1eb034e5a324aa2c7a9ce/tests/phpunit/MediaWikiIntegrationTestCase.php#928
[3] https://gerrit.wikimedia.org/g/mediawiki/core/+/9e9d76a8200f159101e1eb034e5a324aa2c7a9ce/includes/libs/rdbms/querybuilder/SelectQueryBuilder.php#233

Change 992172 had a related patch set uploaded (by Cwhite; author: Cwhite):

[mediawiki/core@master] stats: add copyToStatsdAtMultiple() feature

https://gerrit.wikimedia.org/r/992172

colewhite changed the task status from Open to In Progress.Jan 22 2024, 4:40 PM
colewhite claimed this task.

Change 992172 merged by jenkins-bot:

[mediawiki/core@master] stats: allow passing a single/multiple namespaces to copyToStatsdAt()

https://gerrit.wikimedia.org/r/992172