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; $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 ) ) { if ( !isset( $wgMediaViewerIsInBeta ) ) {
/** @var bool: If set, Media Viewer will try to use BetaFeatures. False if unset. **/ /** @var bool: If set, Media Viewer will try to use BetaFeatures. False if unset. **/
$wgMediaViewerIsInBeta = false; $wgMediaViewerIsInBeta = false;

View file

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

View file

@ -98,7 +98,10 @@
e.country = self.Geo.country; e.country = self.Geo.country;
} }
if ( self.isInSample() ) {
self.eventLog.logEvent( self.schema, e ); self.eventLog.logEvent( self.schema, e );
}
mw.log( message ); mw.log( message );
} ); } );
} }
@ -138,5 +141,14 @@
return waitForEventLog; 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(); mw.mmv.durationLogger = new DurationLogger();
}( mediaWiki, jQuery ) ); }( mediaWiki, jQuery ) );

View file

@ -75,7 +75,7 @@
mw.log( translatedAction ); mw.log( translatedAction );
if ( mw.eventLog && !skipEventLog ) { if ( mw.eventLog && !skipEventLog && this.isInSample() ) {
return mw.eventLog.logEvent( 'MediaViewer', { return mw.eventLog.logEvent( 'MediaViewer', {
version: '1.1', version: '1.1',
action: action action: action
@ -85,5 +85,14 @@
return $.Deferred().resolve(); 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(); mw.mmv.logger = new Logger();
}( mediaWiki, jQuery ) ); }( mediaWiki, jQuery ) );

View file

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