From c4cd2399390f7922c88bb521c39bfbefe000338e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Tue, 21 Jul 2015 16:31:22 -0700 Subject: [PATCH] Count API and hook calls, with 1:1000 sampling Re-adds I6f807adc9cbf71c5d7b83c7eec43965dce1d2a16 and Ic04daf475b936b942833362c7a979dde671b3ef4 (reverted in 35ccd9c2fe058ed76be905d9efe06c31c11fd696) with 1:1000 sampling to avoid swamping the statsd hosts. Also fixes query module logging. Bug: T102079 Bug: T106450 Change-Id: I8b9366407c0d1713790d08e69aaa518130f01977 --- includes/Hooks.php | 4 ++++ includes/api/ApiMain.php | 6 ++++++ includes/api/ApiQuery.php | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/includes/Hooks.php b/includes/Hooks.php index 036d65c71e..c726538c99 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -135,6 +135,10 @@ class Hooks { * returning null) is equivalent to returning true. */ public static function run( $event, array $args = array(), $deprecatedVersion = null ) { + $stats = RequestContext::getMain()->getStats(); + $metric = $stats->increment( 'hooks.' . $event ); + $metric->setSampleRate( 0.001 ); + foreach ( self::getHandlers( $event ) as $hook ) { // Turn non-array values into an array. (Can't use casting because of objects.) if ( !is_array( $hook ) ) { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index f2059d759e..8ce505a0d7 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1089,8 +1089,14 @@ class ApiMain extends ApiBase { $this->checkAsserts( $params ); + $stats = $this->getContext()->getStats(); + $statsPath = 'api.modules.' . strtr( $module->getModulePath(), '+', '.' ); + $metric = $stats->increment( $statsPath ); + $metric->setSampleRate( 0.001 ); + // Execute $module->execute(); + Hooks::run( 'APIAfterExecute', array( &$module ) ); $this->reportUnusedParams(); diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 5378e9259f..8959a46820 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -276,6 +276,7 @@ class ApiQuery extends ApiBase { } $cacheMode = $this->mPageSet->getCacheMode(); + $stats = $this->getContext()->getStats(); // Execute all unfinished modules /** @var $module ApiQueryBase */ @@ -283,6 +284,11 @@ class ApiQuery extends ApiBase { $params = $module->extractRequestParams(); $cacheMode = $this->mergeCacheMode( $cacheMode, $module->getCacheMode( $params ) ); + + $statsPath = 'api.modules.' . strtr( $module->getModulePath(), '+', '.' ); + $metric = $stats->increment( $statsPath ); + $metric->setSampleRate( 0.001 ); + $module->execute(); Hooks::run( 'APIQueryAfterExecute', array( &$module ) ); } -- 2.20.1