Oversample Schema:Edit events when configured to do so

Respect the config var exported by WikimediaEvents that, if set to true,
forces oversampling. When oversampling, all events are logged even if
they would have been sampled out. The isOversample property is set to
true if the event was oversampled and would not otherwise have been
logged.

Bug: T206543
Depends-On: I5fdf5fdd2dc0d99a0a0d7eb7ab2e3dce4798009b
Change-Id: I7e504884a888c4d080cd4762549b72489126ed65
This commit is contained in:
Roan Kattouw 2018-10-16 22:43:12 -07:00
parent e54a4420ca
commit 55b89c1ede
3 changed files with 16 additions and 9 deletions

View file

@ -26,12 +26,16 @@ class WikiEditorHooks {
*/
public static function doEventLogging( $action, $article, $data = [] ) {
global $wgVersion, $wgWMESchemaEditSamplingRate;
if ( !ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ) ) {
$extensionRegistry = ExtensionRegistry::getInstance();
if ( !$extensionRegistry->isLoaded( 'EventLogging' ) ) {
return false;
}
// Sample 6.25%
$samplingRate = $wgWMESchemaEditSamplingRate ?? 0.0625;
if ( !EventLogging::sessionInSample( 1 / $samplingRate, $data['editingSessionId'] ) ) {
$inSample = EventLogging::sessionInSample( 1 / $samplingRate, $data['editingSessionId'] );
$shouldOversample = $extensionRegistry->isLoaded( 'WikimediaEvents' ) &&
WikimediaEventsHooks::shouldSchemaEditOversample( $article->getContext() );
if ( !$inSample && !$shouldOversample ) {
return false;
}
@ -42,6 +46,7 @@ class WikiEditorHooks {
$data = [
'action' => $action,
'version' => 1,
'isOversample' => !$inSample,
'editor' => 'wikitext',
'platform' => 'desktop', // FIXME
'integration' => 'page',
@ -58,7 +63,7 @@ class WikiEditorHooks {
$data['user.class'] = 'IP';
}
return EventLogging::logEvent( 'Edit', 17541122, $data );
return EventLogging::logEvent( 'Edit', 18476212, $data );
}
/**

View file

@ -15,18 +15,18 @@
// We have to do this on the client too because the unload handler
// can cause an editingSessionId to be generated on the client
// 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
)
) {
var inSample = mw.eventLog.randomTokenMatch(
1 / mw.config.get( 'wgWMESchemaEditSamplingRate' ),
editingSessionId
);
if ( !inSample && !mw.config.get( 'wgWMESchemaEditOversample' ) ) {
return;
}
data = $.extend( {
version: 1,
action: action,
isOversample: !inSample,
editingSessionId: editingSessionId,
editor: 'wikitext',
platform: 'desktop', // FIXME

View file

@ -6,6 +6,7 @@ $cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[
'./../../extensions/EventLogging',
'./../../extensions/WikimediaEvents',
]
);
@ -13,6 +14,7 @@ $cfg['exclude_analysis_directory_list'] = array_merge(
$cfg['exclude_analysis_directory_list'],
[
'./../../extensions/EventLogging',
'./../../extensions/WikimediaEvents',
]
);