Set TransactionProfiler expectations in the API
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 16 Dec 2015 23:46:43 +0000 (15:46 -0800)
committerOri.livneh <ori@wikimedia.org>
Mon, 28 Dec 2015 23:34:20 +0000 (23:34 +0000)
This is similar to the main() method for index.php but also
makes use of write mode checks to more granular.

Change-Id: I40fbaef0f5eaefaf2c6d0937d49016a17da532da

includes/DefaultSettings.php
includes/api/ApiMain.php

index 0d4ecac..a6d34b0 100644 (file)
@@ -5556,6 +5556,11 @@ $wgTrxProfilerLimits = array(
                'writeQueryTime' => 1,
                'maxAffected' => 500
        ),
+       'POST-nonwrite' => array(
+               'masterConns' => 0,
+               'writes' => 0,
+               'readQueryTime' => 5
+       ),
        // Background job runner
        'JobRunner' => array(
                'readQueryTime' => 30,
index 49b9786..89ff19a 100644 (file)
@@ -1253,6 +1253,8 @@ class ApiMain extends ApiBase {
                $module = $this->setupModule();
                $this->mModule = $module;
 
+               $this->setRequestExpectations( $module );
+
                $this->checkExecutePermissions( $module );
 
                if ( !$this->checkMaxLag( $module, $params ) ) {
@@ -1284,6 +1286,24 @@ class ApiMain extends ApiBase {
                }
        }
 
+       /**
+        * Set database connection, query, and write expectations given this module request
+        * @param ApiBase $module
+        */
+       protected function setRequestExpectations( ApiBase $module ) {
+               $limits = $this->getConfig()->get( 'TrxProfilerLimits' );
+               $trxProfiler = Profiler::instance()->getTransactionProfiler();
+               if ( $this->getRequest()->wasPosted() ) {
+                       if ( $module->isWriteMode() ) {
+                               $trxProfiler->setExpectations( $limits['POST'], __METHOD__ );
+                       } else {
+                               $trxProfiler->setExpectations( $limits['POST-nonwrite'], __METHOD__ );
+                       }
+               } else {
+                       $trxProfiler->setExpectations( $limits['GET'], __METHOD__ );
+               }
+       }
+
        /**
         * Log the preceding request
         * @param float $time Time in seconds