mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-14 18:15:19 +00:00
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. via mw.eventLog.submit()) and using the Metrics Platform Client (i.e. via mw.eventLog.dispatch()). The Metrics Platform Client can mix in additional information - so-called context attributes [1] - based on the stream configuration. The majority of the default values mixed into each event via the mw.eventLog.Schema defaults mechanism are already known to the Metrics Platform Client. Note well that the Metrics Platform Client will not log an event without one or more streams being configured to receive that event. Therefore, this change is a NOP. An example stream configuration is given in [2]. [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://phabricator.wikimedia.org/T309013#7953227 Bug: T309013 Change-Id: I7627f116cf32ceb3455a33f4f7bb55208ba92671
This commit is contained in:
parent
a707c803a2
commit
d1c8a6b1be
|
@ -93,6 +93,51 @@
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the equivalent of an EditAttemptStep event via
|
||||
* [the Metrics Platform](https://wikitech.wikimedia.org/wiki/Metrics_Platform).
|
||||
*
|
||||
* See https://phabricator.wikimedia.org/T309013.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {string} actionPrefix
|
||||
*/
|
||||
function logEditViaMetricsPlatform( data, actionPrefix ) {
|
||||
var eventName = 'eas.ve.' + actionPrefix;
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
var customData = ve.extendObject(
|
||||
{
|
||||
editor_interface: 'visualeditor',
|
||||
integration: ve.init && ve.init.target && ve.init.target.constructor.static.integrationType || 'page',
|
||||
editing_session_id: editingSessionId
|
||||
},
|
||||
data
|
||||
);
|
||||
|
||||
if ( !mw.config.get( 'wgRevisionId' ) ) {
|
||||
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
customData.revision_id = +$( 'input[name=parentRevId]' ).val() || 0;
|
||||
}
|
||||
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
delete customData.action;
|
||||
|
||||
// Sampling rate (and therefore whether a stream should oversample) is captured in the
|
||||
// stream config ($wgEventStreams).
|
||||
delete customData.is_oversample;
|
||||
|
||||
// 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.
|
||||
delete customData.platform;
|
||||
|
||||
mw.eventLog.dispatch( eventName, customData );
|
||||
}
|
||||
|
||||
function mwEditHandler( topic, data, timeStamp ) {
|
||||
var action = topic.split( '.' )[ 1 ],
|
||||
actionPrefix = actionPrefixMap[ action ] || action,
|
||||
|
@ -107,10 +152,6 @@
|
|||
firstInitDone = true;
|
||||
}
|
||||
|
||||
if ( !inSample() && !mw.config.get( 'wgWMESchemaEditAttemptStepOversample' ) && !trackdebug ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
action === 'abort' &&
|
||||
( data.type === 'unknown' || data.type === 'unknown-edited' )
|
||||
|
@ -150,6 +191,44 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Schema's kind of a mess of special properties
|
||||
if ( action === 'init' || action === 'abort' || action === 'saveFailure' ) {
|
||||
data[ actionPrefix + '_type' ] = data.type;
|
||||
}
|
||||
if ( action === 'init' || action === 'abort' ) {
|
||||
data[ actionPrefix + '_mechanism' ] = data.mechanism;
|
||||
}
|
||||
if ( action !== 'init' ) {
|
||||
// Schema actually does have an init_timing field, but we don't want to
|
||||
// store it because it's not meaningful.
|
||||
duration = Math.round( computeDuration( action, data, timeStamp ) );
|
||||
data[ actionPrefix + '_timing' ] = duration;
|
||||
}
|
||||
if ( action === 'saveFailure' ) {
|
||||
data[ actionPrefix + '_message' ] = data.message;
|
||||
}
|
||||
|
||||
// Remove renamed properties
|
||||
delete data.type;
|
||||
delete data.mechanism;
|
||||
delete data.timing;
|
||||
delete data.message;
|
||||
|
||||
if ( action === 'abort' ) {
|
||||
timing = {};
|
||||
} else {
|
||||
timing[ action ] = timeStamp;
|
||||
}
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
addABTestData( data );
|
||||
|
||||
logEditViaMetricsPlatform( data, actionPrefix );
|
||||
|
||||
if ( !inSample() && !mw.config.get( 'wgWMESchemaEditAttemptStepOversample' ) && !trackdebug ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
var event = ve.extendObject( {
|
||||
version: 1,
|
||||
|
@ -174,38 +253,6 @@
|
|||
event.user_class = 'IP';
|
||||
}
|
||||
|
||||
// Schema's kind of a mess of special properties
|
||||
if ( action === 'init' || action === 'abort' || action === 'saveFailure' ) {
|
||||
event[ actionPrefix + '_type' ] = event.type;
|
||||
}
|
||||
if ( action === 'init' || action === 'abort' ) {
|
||||
event[ actionPrefix + '_mechanism' ] = event.mechanism;
|
||||
}
|
||||
if ( action !== 'init' ) {
|
||||
// Schema actually does have an init_timing field, but we don't want to
|
||||
// store it because it's not meaningful.
|
||||
duration = Math.round( computeDuration( action, event, timeStamp ) );
|
||||
event[ actionPrefix + '_timing' ] = duration;
|
||||
}
|
||||
if ( action === 'saveFailure' ) {
|
||||
event[ actionPrefix + '_message' ] = event.message;
|
||||
}
|
||||
|
||||
// Remove renamed properties
|
||||
delete event.type;
|
||||
delete event.mechanism;
|
||||
delete event.timing;
|
||||
delete event.message;
|
||||
|
||||
if ( action === 'abort' ) {
|
||||
timing = {};
|
||||
} else {
|
||||
timing[ action ] = timeStamp;
|
||||
}
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
addABTestData( event );
|
||||
|
||||
if ( trackdebug ) {
|
||||
log( topic, duration + 'ms', event );
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue