Merge "Add sampling to unsampled event logging"

This commit is contained in:
jenkins-bot 2014-05-16 20:45:30 +00:00 committed by Gerrit Code Review
commit d19fcf60d2
5 changed files with 38 additions and 4 deletions

View file

@ -25,6 +25,17 @@ if ( !isset( $wgNetworkPerformanceSamplingFactor ) ) {
$wgNetworkPerformanceSamplingFactor = false;
}
if ( !isset( $wgMediaViewerSamplingFactor ) ) {
/**
* If set, records user activity and loading times. A value of 1000 means there will be an
* 1:1000 chance to enable logging on page load; for that page, either all or none of the
* events will be logged.
* False if unset.
* @var int|bool
*/
$wgMediaViewerSamplingFactor = false;
}
if ( !isset( $wgMediaViewerIsInBeta ) ) {
/** @var bool: If set, Media Viewer will try to use BetaFeatures. False if unset. **/
$wgMediaViewerIsInBeta = false;

View file

@ -144,8 +144,8 @@ class MultimediaViewerHooks {
* @return bool
*/
public static function resourceLoaderGetConfigVars( &$vars ) {
global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor, $wgMediaViewerIsInBeta,
$wgMediaViewerUseThumbnailGuessing, $wgMediaViewerShowSurvey;
global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor, $wgMediaViewerSamplingFactor,
$wgMediaViewerIsInBeta, $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerShowSurvey;
$vars['wgMultimediaViewer'] = array(
'infoLink' => self::$infoLink,
'discussionLink' => self::$discussionLink,
@ -153,6 +153,7 @@ class MultimediaViewerHooks {
'globalUsageAvailable' => isset( $wgAPIPropModules['globalusage'] ),
'useThumbnailGuessing' => (bool)$wgMediaViewerUseThumbnailGuessing,
'showSurvey' => (bool)$wgMediaViewerShowSurvey,
'samplingFactor' => $wgMediaViewerSamplingFactor,
);
$vars['wgNetworkPerformanceSamplingFactor'] = $wgNetworkPerformanceSamplingFactor;
$vars['wgMediaViewer'] = true;

View file

@ -98,7 +98,10 @@
e.country = self.Geo.country;
}
self.eventLog.logEvent( self.schema, e );
if ( self.isInSample() ) {
self.eventLog.logEvent( self.schema, e );
}
mw.log( message );
} );
}
@ -138,5 +141,14 @@
return waitForEventLog;
};
L.isInSample = function () {
var factor = mw.config.get( 'wgMultimediaViewer' ).samplingFactor;
if ( !$.isNumeric( factor ) || factor < 1 ) {
return false;
}
return Math.floor( Math.random() * factor ) === 0;
};
mw.mmv.durationLogger = new DurationLogger();
}( mediaWiki, jQuery ) );

View file

@ -75,7 +75,7 @@
mw.log( translatedAction );
if ( mw.eventLog && !skipEventLog ) {
if ( mw.eventLog && !skipEventLog && this.isInSample() ) {
return mw.eventLog.logEvent( 'MediaViewer', {
version: '1.1',
action: action
@ -85,5 +85,14 @@
return $.Deferred().resolve();
};
L.isInSample = function () {
var factor = mw.config.get( 'wgMultimediaViewer' ).samplingFactor;
if ( !$.isNumeric( factor ) || factor < 1 ) {
return false;
}
return Math.floor( Math.random() * factor ) === 0;
};
mw.mmv.logger = new Logger();
}( mediaWiki, jQuery ) );

View file

@ -2,6 +2,7 @@
QUnit.module( 'mmv.DurationLogger', QUnit.newMwEnvironment({
setup: function () {
this.clock = this.sandbox.useFakeTimers();
mw.config.get( 'wgMultimediaViewer' ).samplingFactor = 1;
}
} ) );