Merge "Record totals in categories in statsd"

This commit is contained in:
jenkins-bot 2016-12-15 00:03:42 +00:00 committed by Gerrit Code Review
commit 69fd50c811
2 changed files with 30 additions and 1 deletions

View file

@ -64,7 +64,8 @@
},
"LinterSubmitterWhitelist": {
"127.0.0.1": true
}
},
"LinterStatsdSampleFactor": false
},
"manifest_version": 1
}

View file

@ -21,6 +21,7 @@
namespace MediaWiki\Linter;
use Job;
use MediaWiki\MediaWikiServices;
use Title;
class RecordLintJob extends Job {
@ -62,7 +63,34 @@ class RecordLintJob extends Job {
}
$lintDb->setForPage( $toSet );
$this->updateStats( $lintDb );
return true;
}
/**
* Send stats to statsd
*
* @param Database $lintDb
*/
protected function updateStats( Database $lintDb ) {
global $wgLinterStatsdSampleFactor;
if ( $wgLinterStatsdSampleFactor === false ) {
// Not enabled at all
return;
} elseif ( mt_rand( 1, $wgLinterStatsdSampleFactor ) != 1 ) {
return;
}
$totals = $lintDb->getTotals();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
foreach ( $totals as $name => $count ) {
$stats->gauge( "linter.category.$name", $count );
}
$stats->gauge( "linter.totals", array_sum( $totals ) );
}
}