Metric instances do not check to ensure label compatibility when adding a sample
Closed, ResolvedPublic

Description

https://prometheus.io/docs/instrumenting/writing_clientlibs/#labels

Client libraries MUST NOT allow users to have different label names for the same 
metric for Gauge/Counter/Summary/Histogram or any other Collector offered by the 
library.

This check is not occurring and enabling the following behavior:

# initialize metric 'foo' and cache it
$m = getStatsFactory()->getCounter('foo')->setLabel('bar', 'a');
$m->increment(); # MediaWiki_foo{bar=a} 1

# now fetch same metric from cache, but forget to set the label
$m = getStatsFactory()->getCounter('foo');
$m->getLabelKeys(); # ['bar']
$m->increment();  # MediaWiki_foo{} 1

# now set a new label on the same metric
# this is caught by setLabel() disallowing adding labels when samples are recorded
$m = getStatsFactory()->getCounter('foo')->setLabel('baz', 'a'); # NullMetric
$m->increment();  # no effect

Event Timeline

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

[mediawiki/core@master] stats: add check for expected label usage when requesting label values

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

Change 991460 merged by jenkins-bot:

[mediawiki/core@master] stats: add check for expected label usage when requesting label values

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

colewhite changed the task status from Open to In Progress.Jan 19 2024, 9:14 PM
colewhite claimed this task.
colewhite triaged this task as High priority.
colewhite moved this task from Backlog to Up Next on the MediaWiki-libs-Stats board.

With the linked patch merged, I'd say this is resolved.