Merge "Use Schema:Edit sampling rate config from WikimediaEvents"

This commit is contained in:
jenkins-bot 2018-10-24 21:37:24 +00:00 committed by Gerrit Code Review
commit c31bffdb17
2 changed files with 18 additions and 13 deletions

View file

@ -25,12 +25,13 @@ class WikiEditorHooks {
* @return bool Whether the event was logged or not. * @return bool Whether the event was logged or not.
*/ */
public static function doEventLogging( $action, $article, $data = [] ) { public static function doEventLogging( $action, $article, $data = [] ) {
global $wgVersion; global $wgVersion, $wgWMESchemaEditSamplingRate;
if ( !ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ) ) { if ( !ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ) ) {
return false; return false;
} }
// Sample 6.25% (via hex digit) // Sample 6.25%
if ( $data['editingSessionId'][0] > '0' ) { $samplingRate = $wgWMESchemaEditSamplingRate ?? 0.0625;
if ( !EventLogging::sessionInSample( 1 / $samplingRate, $data['editingSessionId'] ) ) {
return false; return false;
} }

View file

@ -10,17 +10,24 @@
return; return;
} }
// Sample 6.25% (via hex digit) mw.loader.using( [ 'schema.Edit', 'ext.eventLogging.subscriber' ] ).done( function () {
// Sampling
// We have to do this on the client too because the unload handler // We have to do this on the client too because the unload handler
// can cause an editingSessionId to be generated on the client // can cause an editingSessionId to be generated on the client
if ( editingSessionId.charAt( 0 ) > '0' ) { // Not using mw.eventLog.inSample() because we need to be able to pass our own editingSessionId
if (
!mw.eventLog.randomTokenMatch(
1 / mw.config.get( 'wgWMESchemaEditSamplingRate' ),
editingSessionId
)
) {
return; return;
} }
mw.loader.using( 'schema.Edit' ).done( function () {
data = $.extend( { data = $.extend( {
version: 1, version: 1,
action: action, action: action,
editingSessionId: editingSessionId,
editor: 'wikitext', editor: 'wikitext',
platform: 'desktop', // FIXME platform: 'desktop', // FIXME
integration: 'page', integration: 'page',
@ -66,12 +73,10 @@
// that don't, we just ignore them, so as to not skew the // that don't, we just ignore them, so as to not skew the
// results towards better-performance in those cases. // results towards better-performance in those cases.
logEditEvent( 'ready', { logEditEvent( 'ready', {
editingSessionId: editingSessionId,
timing: Date.now() - window.performance.timing.navigationStart timing: Date.now() - window.performance.timing.navigationStart
} ); } );
$textarea.on( 'wikiEditor-toolbar-doneInitialSections', function () { $textarea.on( 'wikiEditor-toolbar-doneInitialSections', function () {
logEditEvent( 'loaded', { logEditEvent( 'loaded', {
editingSessionId: editingSessionId,
timing: Date.now() - window.performance.timing.navigationStart timing: Date.now() - window.performance.timing.navigationStart
} ); } );
} ); } );
@ -105,7 +110,6 @@
if ( !submitting ) { if ( !submitting ) {
logEditEvent( 'abort', { logEditEvent( 'abort', {
editingSessionId: editingSessionId,
type: abortType type: abortType
} ); } );
} }