Hooks: Also log EditAttemptStep events via Metrics Platform

The EditAttemptStep instrument is a candidate for migration to the
Metrics Platform [0]. The first step of the migration is to log events
both using the Event Platform (i.e. EventLogging::submit()) and using
the Metrics Platform Client (i.e. via
EventLogging::submitMetricsEvent()).

The Metrics Platform Client can mix in additional information -
so-called context attributes [1] - based on the stream configuration.
Since the majority of the default values mixed into each event in
Hooks::doEventLogging() are already known to the Metrics Platform
Client, the majority of Hooks::doMetricsPlatformLogging() is concerned
with remove those values from the event.

[0] https://wikitech.wikimedia.org/wiki/Metrics_Platform
[1] https://gerrit.wikimedia.org/g/mediawiki/libs/metrics-platform/+/aed6738b845/js/src/StreamConfig.d.ts#31
[2] https://wikitech.wikimedia.org/wiki/Metrics_Platform/Creating_a_Stream_Configuration

Bug: T309985
Change-Id: I052159884a9a8b21b3dc9ee01e2cafdbb173ca26
This commit is contained in:
Sam Smith 2023-03-23 17:18:20 +00:00 committed by Clare Ming
parent fb3b49b8e9
commit 457366c2cf

View file

@ -107,25 +107,25 @@ class Hooks implements
} }
/** /**
* Log stuff to EventLogging's Schema:EditAttemptStep - * Log stuff to the eventlogging_EditAttemptStep stream in a shape that conforms to the
* see https://meta.wikimedia.org/wiki/Schema:EditAttemptStep * analytics/legacy/editattemptstep schema.
* If you don't have EventLogging and WikimediaEvents installed, does nothing. *
* If the EventLogging extension is not loaded, then this is a NOP.
*
* @see https://meta.wikimedia.org/wiki/Schema:EditAttemptStep
* *
* @param string $action * @param string $action
* @param Article $article Which article (with full context, page, title, etc.) * @param Article $article Which article (with full context, page, title, etc.)
* @param array $data Data to log for this action * @param array $data Data to log for this action
* @return bool Whether the event was logged or not. * @return void
*/ */
public function doEventLogging( $action, $article, $data = [] ) { public function doEventLogging( $action, $article, $data = [] ) {
$extensionRegistry = ExtensionRegistry::getInstance(); $extensionRegistry = ExtensionRegistry::getInstance();
if ( !$extensionRegistry->isLoaded( 'EventLogging' ) || !$extensionRegistry->isLoaded( 'WikimediaEvents' ) ) { if ( !$extensionRegistry->isLoaded( 'EventLogging' ) || !$extensionRegistry->isLoaded( 'WikimediaEvents' ) ) {
return false; return;
} }
$inSample = $this->inEventSample( $data['editing_session_id'] ); $inSample = $this->inEventSample( $data['editing_session_id'] );
$shouldOversample = WikimediaEventsHooks::shouldSchemaEditAttemptStepOversample( $article->getContext() ); $shouldOversample = WikimediaEventsHooks::shouldSchemaEditAttemptStepOversample( $article->getContext() );
if ( !$inSample && !$shouldOversample ) {
return false;
}
$user = $article->getContext()->getUser(); $user = $article->getContext()->getUser();
$page = $article->getPage(); $page = $article->getPage();
@ -161,10 +161,55 @@ class Hooks implements
$data['user_class'] = 'IP'; $data['user_class'] = 'IP';
} }
// NOTE: The 'EditAttemptStep' event was migrated to the Event Platform and is no longer $this->doMetricsPlatformLogging( $action, $data );
// using the legacy EventLogging schema from metawiki. $revId is actually overriden by
// the EventLoggingSchemas extension attribute in WikimediaEvents/extension.json. if ( !$inSample && !$shouldOversample ) {
return EventLogging::logEvent( 'EditAttemptStep', -1, $data ); return;
}
EventLogging::submit(
'eventlogging_EditAttemptStep',
[
'$schema' => '/analytics/legacy/editattemptstep/1.4.1',
'event' => $data,
]
);
}
/**
* @see https://phabricator.wikimedia.org/T309013
* @see https://phabricator.wikimedia.org/T309985
*/
private function doMetricsPlatformLogging( string $action, array $data ): void {
unset( $data['version'] );
unset( $data['action'] );
// Sampling rate (and therefore whether a stream should oversample) is captured in
// the stream config ($wgEventStreams).
unset( $data['is_oversample'] );
unset( $data['session_token'] );
// Platform can be derived from the agent_client_platform_family context attribute
// mixed in by the JavaScript Metrics Platform Client. The context attribute will be
// "desktop_browser" or "mobile_browser" depending on whether the MobileFrontend
// extension has signalled that it is enabled.
unset( $data['platform'] );
unset( $data['page_id'] );
unset( $data['page_title'] );
unset( $data['page_ns'] );
// If the revision ID can be fetched (i.e. it is a positive integer), then it will be
//mixed in by the Metrics Platform Client.
if ( $data['revision_id'] ) {
unset( $data['revision_id'] );
}
unset( $data['user_id'] );
unset( $data['user_editcount'] );
unset( $data['mw_version'] );
EventLogging::submitMetricsEvent( 'eas.wt.' . $action, $data );
} }
/** /**