Page MenuHomePhabricator

Replace PagePreviews Graphite metrics emitted via statsvTracker with Prometheus-compatible StatsLib metrics
Closed, ResolvedPublic3 Estimated Story Points

Description

⚠️ Heads up: Thanos PagePreviews Data for the week of May 19, 2025 are invalid.

Description:

We need to replace the PagePreviews* metrics currently emitted to Graphite via the legacy statsvTracker system with Prometheus-compatible instrumentation using StatsLib.

Metrics affected:

PagePreviewsApiResponse.sample_rate
PagePreviewsApiResponse.median
PagePreviewsApiFailure.rate
PagePreviewsPreviewShow.sample_rate
PagePreviewsPreviewShow.median

These power dashboards for:

  • API performance (response time, failures, rate)
  • Preview show rate and time-to-preview (TTP)
  • Utilization (e.g., previews shown ÷ API responses)

Current behavior:

Metrics are emitted via statsvTracker, initialized in src/index.js of the Popups extension, and triggered in src/reducers/statsv.js by action types:

FETCH_END
FETCH_FAILED
PREVIEW_SHOW
This path is Graphite-only and will stop working after Graphite is set to read-only on April 30, 2025.

Goal:

Re-instrument these metrics using StatsLib or another Prometheus-compatible system, using metric names that follow Prometheus conventions (snake_case, proper suffixes, etc.).

Example:

`
Stats.timer( 'page_previews_api_response_time_seconds' ).observe( durationMs / 1000 );
Stats.counter( 'page_previews_api_failures_total' ).inc();
Stats.timer( 'page_previews_time_to_preview_seconds' ).observe( durationMs / 1000 );

Suggested steps:

Identify all statsvTracker calls in the Popups extension
Replace them with StatsLib-based metrics
Ensure the new metrics are collected
Update Grafana dashboards to use the new Prometheus metrics

Testing instructions

See also T392319#10766865

Docker setup
  • Make sure WikimediaEvents, EventLogging, Popups, EventBus are installed.
  • Add following to LocalSettings.php
$wgStatsdServer = 'statsd';
$wgStatsFormat = 'dogstatsd';
$wgStatsTarget = 'udp://statsd-exporter:9125';
$wgStatsPrefix = 'mediawiki';
$wgWMEStatsBeaconUri = 'http://localhost:8127/beacon/statsv';

$wgPopupsStatsvSamplingRate = 1;
$wgPopupsGateway = 'restbaseHTML';
$wgPopupsRestGatewayEndpoint = 'https://en.wikipedia.org/api/rest_v1/page/summary/';

Edit docker-compose.override.yml and add:

statsd-exporter:
  ports:
    - "9112:9112"
  image: prom/statsd-exporter:v0.22.2
  command: "--web.listen-address=:9112"
statsv:
  build: ./extensions/WikimediaEvents/devserver/
  ports:
    - "8127:8127"
Launch Statsv beacon service
cd extensions/WikimediaEvents/devserver
composer start-statsv

In another terminal window run

watch 'curl -s localhost:9112/metrics| grep Popups'
Check events are firing
mw.track( 'stats.mediawiki_Popups_api_response_seconds', 321 );

Check the watch tab to confirm the event showed up.

Test the patch
  • Create a page with a link to [[Barcelona]] and create a Barcelona page so it doesn't show as red link.
  • Refresh page and hover over Barcelona link.
  • Change tab
  • Check event showed up in the start-statsv devserver

Notes

To migrate the metrics, you can refer to the following resources:

Once your metrics are migrated to Prometheus, you can switch the datasource to Thanos for any widget you would like to keep and update the query accordingly.

Event Timeline

LMora-WMF set the point value for this task to 3.Apr 21 2025, 5:16 PM

Change #1137820 had a related patch set uploaded (by Kimberly Sarabia; author: Kimberly Sarabia):

[mediawiki/extensions/Popups@master] Migrate PagePreviews metrics to StatsLib

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

Testing Instructions

In devtools

mw.track( 'stats.mediawiki_Popups_api_response_seconds', 321 );
mw.track( 'stats.mediawiki_Popups_preview_render_seconds', 200 );
mw.track( 'stats.mediawiki_Popups_api_failure_total', 1 );

These fire into StatsD, and you can verify with:

curl -s http://localhost:9112/metrics | grep mediawiki_Popups

Sample Result:

 curl -s http://localhost:9112/metrics | grep mediawiki_Popups
# HELP mediawiki_Popups_test_metric_total Metric autogenerated by statsd_exporter.
# TYPE mediawiki_Popups_test_metric_total counter
mediawiki_Popups_test_metric_total{env="dev"} 5

Explanation:
Fire the metric, get it through StatsD, show up in Prometheus format at /metrics. The mediawiki_Popups_test_metric_total counter incremented to 5, which means it captured every mw.track() call.
This should mean we are emitting Prometheus-compatible metrics from Popups.

Kim should hopefully be able to rebase and update the patch so it doesn't fail CI and then will need another review.
I will try to make space this afternoon to review.

Change #1137820 abandoned by Kimberly Sarabia:

[mediawiki/extensions/Popups@master] Migrate PagePreviews metrics to StatsLib

Reason:

This doesn't work. No mw.stats. Switching to PHP

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

Change #1147902 had a related patch set uploaded (by Kimberly Sarabia; author: Kimberly Sarabia):

[mediawiki/extensions/Popups@master] Migrate Popups metrics to Prometheus

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

I updated metrics via mw.track( 'stats.mediawiki_Popups_*' )
I made sure those metrics land in DogStatsD / Prometheus by configuring StatsPrefix, StatsTarget, StatsFormat and ensuring these values get exposed to client-side code via PopupsHooks::onResourceLoaderGetConfigVars() → injected into mw.config

I believe we needed to change PopupsHooks.php like so The instrumentation actually show up in Thanos without silently erroring out.

This conversation here mentions that Popups has to be modified for Prometheus, so we are waiting from observability about feedback.
I was able to run mw.track and the desired values are now appearing on Prometheus.

Screenshot 2025-05-20 at 5.04.32 PM.png (2,842×1,296 px, 236 KB)

cc @Jdlrobson-WMF

Change #1147902 merged by jenkins-bot:

[mediawiki/extensions/Popups@master] Migrate Popups metrics to Prometheus

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

  • I've been able to verify events are sent to composer start-statsvcd (WikimediaEvents devserver)
  • I've not been able to verify they show up in watch 'curl -s localhost:9112/metrics| grep Popups'

However, I can confirm that in production that a call to mw.track( 'stats.mediawiki_Popups_api_response_seconds', 2000 ); made the event show up in https://thanos.wikimedia.org/graph?g0.expr=mediawiki_Popups_api_response_seconds_bucket&g0.tab=0&g0.stacked=0&g0.range_input=12h&g0.max_source_resolution=0s&g0.deduplicate=1&g0.partial_response=1&g0.store_matches=%5B%5D&g0.engine=prometheus&g0.analyze=0&g0.tenant=&g0.end_input=2025-05-20%2022%3A30%3A19&g0.moment_input=2025-05-20%2022%3A30%3A19 so I don't see any reason this shouldn't work end to end.

I've updated the description with the test steps I took to aid replication and I've reached out separately to find information on how to verify this end to end.

@KSarabia-WMF since this is hard to QA I suggest we wait until Tuesday/Wednesday next week when we should have data coming in and update one of the Grafana graphs on https://grafana.wikimedia.org/d/000000340/page-previews?orgId=1&from=now-24h&to=now&timezone=utc&refresh=1m before resolving this to ensure it is working end to end. Does that make sense?

Jdlrobson-WMF updated the task description. (Show Details)

Wonderful. Those numbers look very reassuring! Very grateful that we have this data back.
I've unstalled T389988: Migrate page previews dashboard from Graphite which is queued up for the next sprint.

Thanks Kim for getting us back online!

Change #1251459 had a related patch set uploaded (by Reedy; author: Kimberly Sarabia):

[mediawiki/extensions/Popups@REL1_44] Migrate Popups metrics to Prometheus

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

Change #1251459 merged by jenkins-bot:

[mediawiki/extensions/Popups@REL1_44] Migrate Popups metrics to Prometheus

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

Change #1251472 had a related patch set uploaded (by Reedy; author: Kimberly Sarabia):

[mediawiki/extensions/Popups@REL1_43] Migrate Popups metrics to Prometheus

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

Change #1251472 abandoned by Reedy:

[mediawiki/extensions/Popups@REL1_43] Migrate Popups metrics to Prometheus

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