Page MenuHomePhabricator

Incorporate librarized Metrics Platform JS client into EventLogging
Closed, ResolvedPublic

Event Timeline

Mholloway created this task.

AIUI this'll require:

  1. Downloading the tarball of https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/libs/metrics-platform/+/refs/heads/master/js/ to, say, EventLogging/libs/metrics-platform/js/
  2. Update the ext.eventLogging Resource Loader module to
    1. require the library
    2. Define the MediaWikiMetricsClientIntegration integration, an implementation of IMetricsClientIntegration
    3. Construct an instance of MetricsClient with the the above integration and the stream configurations sent to the client
    4. Make mw.eventLog.submit defer to MetricsClient::submit():
EventLogging/modules/ext.eventLogging/core.js
var metricsClient = new MetricsClient( new MediaWikiMetricsClientIntegration(), config.streamConfigs );

// Later...

mw.eventLog.submit = metricsClient.submit.bind( metricsClient );

A couple of notes/questions that I made whilst exploring the above:

  • AssociationController's notion of a session ID differs from the current Event Platform client's notion of one – the latter persists the session ID in a session cookie and can have the value reset when the SessionLength instrument determines that the session has reset. For now, the simplest way to bring AssociationController and EventLogging/Event Platform in line here would be to have AssociationController defer to IMetricsClientIntegration::getSessionId()
  • "Debug mode" is somewhat ambiguous. In the context of the EventLogging and Event Platform, debug mode could refer to either:
    1. Resource Loader's debug mode; or
    2. The "client-side debug mode" enabled by setting your eventlogging-display-web user preference (see the comment at the top of https://gerrit.wikimedia.org/g/mediawiki/extensions/EventLogging/+/9859e766d7ace5b5c93723d00512cfc73a709b58/modules/ext.eventLogging.debug/debug.js)
  • There's a minor inconsistency between SamplingController::streamInSample() and mw.eventLog.streamInSample where the latter always returns true if debug mode 2 is enabled

Change 754002 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/EventLogging@master] WIP: Integrate mediawiki/libs/metrics-platform

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

@jlinehan and I agree that it's option 2. I've updated https://gerrit.wikimedia.org/r/754002 accordingly.

Change 759251 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/libs/metrics-platform@master] Get pageview/session ID from IMetricsClientIntegration

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

@Krinkle: I've been tasked with integrating the JS Metrics Platform client in EventLogging, which is tracked in this task. Would you be able to both a code-review and performance review of the integration patch?

You may or may not have seen Jason Linehan and Michael Holloway's work related to this in EventLogging or in lib/metrics-platform. If you haven't, a very high-level overview is that we're looking to move the collection of a lot of standardised data sent by all instruments into the stream configuration, thereby allowing instrument developers to focus solely on collecting data in their domain. Some more detail is available here (and more detail will be added in the near future).

@Krinkle: My apologies. I've had feedback on the in-flight work to introduce a schema to validate the events sent by the Metrics Platform clients. A number of properties have changed names and locations and so the patch to integrate the JavaScript Metrics Platform client with EventLogging hasn't settled. That said, the overall approach will remain the same and so I can still address feedback on it.

Change 762457 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/libs/metrics-platform@master] Add MetricsClient::dispatch()

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

Change 759251 merged by jenkins-bot:

[mediawiki/libs/metrics-platform@master] [JS] Get pageview/session ID from IMetricsClientIntegration

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

Change 769441 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/libs/metrics-platform@master] [JS] Add MetricsClientIntegration::onSubmit()

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

Change 769441 merged by jenkins-bot:

[mediawiki/libs/metrics-platform@master] [JS] Add MetricsClientIntegration::onSubmit()

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

Change 762457 merged by jenkins-bot:

[mediawiki/libs/metrics-platform@master] [JS] Add MetricsClient::dispatch()

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

Change 787006 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/libs/metrics-platform@master] [JS] Reduce library size

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

Change 787006 merged by jenkins-bot:

[mediawiki/libs/metrics-platform@master] [JS] Reduce library size

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

Change 754002 merged by jenkins-bot:

[mediawiki/extensions/EventLogging@master] Integrate mediawiki/libs/metrics-platform

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

Change 793810 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/EventLogging@master] Do not throw when calling MediaWikiMetricsClientIntegration::getContextAttributes()

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

Change 793824 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/WikimediaEvents@master] DNM: *WebUIActions: Migrate to Metrics Platform

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

Change 793835 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/WikimediaEvents@master] DNM: WebUIScroll: Migrate to Metrics Platform

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

Change 793810 merged by jenkins-bot:

[mediawiki/extensions/EventLogging@master] Do not throw when calling MediaWikiMetricsClientIntegration::getContextAttributes()

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

Change 793835 abandoned by Phuedx:

[mediawiki/extensions/WikimediaEvents@master] DNM: WebUIScroll: Migrate to Metrics Platform

Reason:

This was only a demonstration.

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

Here's the example stream configuration that I landed on while working through the migration:

LocalSettings.php
$wgEventLoggingStreamNames = [
  'web_ui_actions_tracking',
  'web_ui_actions_tracking.logged_in',
];

$wgEventStreams = [
  [
    'stream' => 'web_ui_actions_tracking',
    'schema_title' => '/analytics/mediawiki/client/metrics_event',
    'destination_event_service' => 'eventgate-analytics-external',

// NOTE: The DesktopWebUIActionsTracking and MobileWebUIActionsTracking instruments both implement
// their own sampling. The last step of migrating those instruments to the Metrics Platform will be
// to leverage the per-stream sampling built into the Metrics Platform client.
//
//    'sample' => [
//      'unit' => 'pageview',
//      'rate' => $wgWMEDesktopWebUIActionsTracking,
//    ],
    'producers' => [
      'metrics_platform_client' => [
        'events' => [
          'web.ui.init',
          'web.ui.click',
        ],
        'provide_values' => [
          'performer_is_logged_in',
          'performer_session_id',
          'performer_edit_count_bucket',
          'mediawiki_skin',
        ],
        'curation' => [
          'mediawiki_skin' => [
            'in' => [ 'minerva', 'vector', 'vector-2022' ],
          ],
          'performer_is_logged_in' => [
            'equals' => false,
          ],
        ],
      ],
    ],
  ],
  [
    'stream' => 'web_ui_actions_tracking.logged_in',
    'schema_title' => '/analytics/mediawiki/client/metrics_event',
    'destination_event_service' => 'eventgate-analytics-external',
//    'sample' => [
//      'unit' => 'pageview',
//      'pageview' => $wgWMEDesktopWebUIActionsTrackingOversampleLoggedInUsers ? 1 : $wgWMEDesktopWebUIActionsTracking
//    ],
    'producers' => [
      'metrics_platform_client' => [
        'events' => [
          'web.ui.init',
          'web.ui.click',
        ],
        'provide_values' => [
          'performer_is_logged_in',
          'performer_session_id',
          'performer_edit_count_bucket',
          'mediawiki_skin',
        ],
        'curation' => [
          'mediawiki_skin' => [
            'in' => [ 'minerva', 'vector', 'vector-2022' ],
          ],
          'performer_is_logged_in' => [
            'equals' => true,
          ],
        ],
      ],
    ],
  ],
];

Change 799353 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/WikimediaEvents@master] *WebUIActionsTracking: Also log events via Metrics Platform

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

Change 793824 abandoned by Phuedx:

[mediawiki/extensions/WikimediaEvents@master] DNM: *WebUIActions: Migrate to Metrics Platform

Reason:

This was only a demonstration. I9385d615ee3e610ba3407085acccd3d41ac3504f is the first step to migrating the instruments to the Metrics Platform.

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