Count API and hook calls, with 1:1000 sampling
authorGergő Tisza <tgr.huwiki@gmail.com>
Tue, 21 Jul 2015 23:31:22 +0000 (16:31 -0700)
committerOri.livneh <ori@wikimedia.org>
Mon, 10 Aug 2015 22:57:59 +0000 (22:57 +0000)
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
includes/api/ApiMain.php
includes/api/ApiQuery.php

index 036d65c..c726538 100644 (file)
@@ -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 ) ) {
index f2059d7..8ce505a 100644 (file)
@@ -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();
index 5378e92..8959a46 100644 (file)
@@ -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 ) );
                }