Replace deprecated Context::getStats() with MWServices::getStatsdDataFactory()

Change-Id: I1756f69ca2ebd301a5049bf758d1a87c37771fe6
This commit is contained in:
WMDE-Fisch 2017-03-17 11:57:37 +01:00
parent bd96b3092d
commit 7b5f08e703
11 changed files with 24 additions and 13 deletions

View file

@ -26,6 +26,7 @@
*/
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Wikimedia\Timestamp\TimestampException;
/**
@ -544,7 +545,7 @@ class ApiMain extends ApiBase {
$runTime = microtime( true ) - $t;
$this->logRequest( $runTime );
if ( $this->mModule->isWriteMode() && $this->getRequest()->wasPosted() ) {
$this->getStats()->timing(
MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
'api.' . $this->mModule->getModuleName() . '.executeTiming', 1000 * $runTime
);
}

View file

@ -19,6 +19,7 @@
* @file
*/
use Liuggio\StatsdClient\Factory\StatsdDataFactory;
use MediaWiki\MediaWikiServices;
/**
* The simplest way of implementing IContextSource is to hold a RequestContext as a
@ -172,7 +173,7 @@ abstract class ContextSource implements IContextSource {
* @return StatsdDataFactory
*/
public function getStats() {
return $this->getContext()->getStats();
return MediaWikiServices::getInstance()->getStatsdDataFactory();
}
/**

View file

@ -17,6 +17,7 @@
*
* @file
*/
use MediaWiki\MediaWikiServices;
use Wikimedia\Assert\Assert;
/**
@ -169,7 +170,7 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
}
protected function doUpdateContextStats() {
$stats = RequestContext::getMain()->getStats();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
foreach ( [ 'edits', 'articles', 'pages', 'users', 'images' ] as $type ) {
$delta = $this->$type;
if ( $delta !== 0 ) {

View file

@ -20,6 +20,7 @@
* @file
* @ingroup DifferenceEngine
*/
use MediaWiki\MediaWikiServices;
/** @deprecated use class constant instead */
define( 'MW_DIFF_VERSION', '1.11a' );
@ -852,7 +853,7 @@ class DifferenceEngine extends ContextSource {
$result = $this->textDiff( $otext, $ntext );
$time = intval( ( microtime( true ) - $time ) * 1000 );
$this->getStats()->timing( 'diff_time', $time );
MediaWikiServices::getInstance()->getStatsdDataFactory()->timing( 'diff_time', $time );
// Log requests slower than 99th percentile
if ( $time > 100 && $this->mOldPage && $this->mNewPage ) {
wfDebugLog( 'diff',

View file

@ -5,6 +5,7 @@
*
* Represents files in a repository.
*/
use MediaWiki\MediaWikiServices;
/**
* Base code for files.
@ -436,7 +437,7 @@ abstract class File implements IDBAccessObject {
$this->fsFile = $this->repo->getLocalReference( $this->getPath() );
$statTiming = microtime( true ) - $starttime;
RequestContext::getMain()->getStats()->timing(
MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
'media.thumbnail.generate.fetchoriginal', 1000 * $statTiming );
if ( !$this->fsFile ) {
@ -1117,7 +1118,7 @@ abstract class File implements IDBAccessObject {
public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
global $wgIgnoreImageErrors;
$stats = RequestContext::getMain()->getStats();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
$handler = $this->getHandler();
@ -1227,7 +1228,7 @@ abstract class File implements IDBAccessObject {
// this object exists
$tmpFile->bind( $this );
RequestContext::getMain()->getStats()->timing(
MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
'media.thumbnail.generate.bucket', 1000 * $buckettime );
return true;

View file

@ -21,6 +21,7 @@
* @defgroup JobQueue JobQueue
* @author Aaron Schulz
*/
use MediaWiki\MediaWikiServices;
/**
* Class to handle enqueueing and running of background jobs
@ -709,7 +710,7 @@ abstract class JobQueue {
public static function incrStats( $key, $type, $delta = 1 ) {
static $stats;
if ( !$stats ) {
$stats = RequestContext::getMain()->getStats();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
}
$stats->updateCount( "jobqueue.{$key}.all", $delta );
$stats->updateCount( "jobqueue.{$key}.{$type}", $delta );

View file

@ -19,6 +19,7 @@
*
* @file
*/
use MediaWiki\MediaWikiServices;
/**
* Class for viewing MediaWiki article and history.
@ -494,7 +495,7 @@ class Article implements Page {
$useParserCache = $this->mPage->shouldCheckParserCache( $parserOptions, $oldid );
wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
if ( $user->getStubThreshold() ) {
$this->getContext()->getStats()->increment( 'pcache_miss_stub' );
MediaWikiServices::getInstance()->getStatsdDataFactory()->increment( 'pcache_miss_stub' );
}
$this->showRedirectedFromHeader();

View file

@ -21,6 +21,7 @@
* @file
* @ingroup Profiler
*/
use MediaWiki\MediaWikiServices;
/**
* ProfilerOutput class that flushes profiling data to the profiling
@ -38,7 +39,7 @@ class ProfilerOutputStats extends ProfilerOutput {
*/
public function log( array $stats ) {
$prefix = isset( $this->params['prefix'] ) ? $this->params['prefix'] : '';
$contextStats = $this->collector->getContext()->getStats();
$contextStats = MediaWikiServices::getInstance()->getStatsdDataFactory();
foreach ( $stats as $stat ) {
$key = "{$prefix}.{$stat['name']}";

View file

@ -185,7 +185,7 @@ class ResourceLoader implements LoggerAwareInterface {
return self::applyFilter( $filter, $data );
}
$stats = RequestContext::getMain()->getStats();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
$cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
$key = $cache->makeGlobalKey(

View file

@ -624,7 +624,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
*/
final protected function buildContent( ResourceLoaderContext $context ) {
$rl = $context->getResourceLoader();
$stats = RequestContext::getMain()->getStats();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
$statStart = microtime( true );
// Only include properties that are relevant to this context (e.g. only=scripts)

View file

@ -22,6 +22,7 @@
*/
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
require __DIR__ . '/includes/WebStart.php';
@ -317,7 +318,9 @@ function wfStreamThumb( array $params ) {
$streamtime = microtime( true ) - $starttime;
if ( $status->isOK() ) {
RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime );
MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
'media.thumbnail.stream', $streamtime
);
} else {
wfThumbError( 500, 'Could not stream the file', null, [ 'file' => $thumbName,
'path' => $thumbPath, 'error' => $status->getWikiText( false, false, 'en' ) ] );