'MediaWiki\\Widget\\TitleInputWidget' => __DIR__ . '/includes/widget/TitleInputWidget.php',
'MediaWiki\\Widget\\UserInputWidget' => __DIR__ . '/includes/widget/UserInputWidget.php',
'MediaWiki\\Widget\\UsersMultiselectWidget' => __DIR__ . '/includes/widget/UsersMultiselectWidget.php',
+ 'MediawikiStatsdDataFactory' => __DIR__ . '/includes/libs/stats/MediawikiStatsdDataFactory.php',
'MemCachedClientforWiki' => __DIR__ . '/includes/compat/MemcachedClientCompat.php',
'MemcLockManager' => __DIR__ . '/includes/libs/lockmanager/MemcLockManager.php',
'MemcachedBagOStuff' => __DIR__ . '/includes/libs/objectcache/MemcachedBagOStuff.php',
$profiler->logData();
$config = $context->getConfig();
- if ( $config->get( 'StatsdServer' ) ) {
+ $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+ if ( $config->get( 'StatsdServer' ) && $stats->hasData() ) {
try {
$statsdServer = explode( ':', $config->get( 'StatsdServer' ) );
$statsdHost = $statsdServer[0];
$statsdSender = new SocketSender( $statsdHost, $statsdPort );
$statsdClient = new SamplingStatsdClient( $statsdSender, true, false );
$statsdClient->setSamplingRates( $config->get( 'StatsdSamplingRates' ) );
- $statsdClient->send(
- MediaWikiServices::getInstance()->getStatsdDataFactory()->getBuffer()
- );
+ $statsdClient->send( $stats->getData() );
} catch ( Exception $ex ) {
MWExceptionHandler::logException( $ex );
}
use GenderCache;
use GlobalVarConfig;
use Hooks;
+use MediawikiStatsdDataFactory;
use Wikimedia\Rdbms\LBFactory;
use LinkCache;
-use Liuggio\StatsdClient\Factory\StatsdDataFactory;
use Wikimedia\Rdbms\LoadBalancer;
use MediaHandlerFactory;
use MediaWiki\Linker\LinkRenderer;
/**
* @since 1.27
- * @return StatsdDataFactory
+ * @return MediawikiStatsdDataFactory
*/
public function getStatsdDataFactory() {
return $this->getService( 'StatsdDataFactory' );
* @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
*
* @since 1.25
- * @return StatsdDataFactory
+ * @return MediawikiStatsdDataFactory
*/
public function getStats() {
return MediaWikiServices::getInstance()->getStatsdDataFactory();
*
* @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
*
- * @return StatsdDataFactory
+ * @return MediawikiStatsdDataFactory
*/
public function getStats() {
return MediaWikiServices::getInstance()->getStatsdDataFactory();
* @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
*
* @since 1.25
- * @return StatsdDataFactory
+ * @return MediawikiStatsdDataFactory
*/
public function getStats();
*
* @deprecated since 1.27 use a StatsdDataFactory from MediaWikiServices (preferably injected)
*
- * @return StatsdDataFactory
+ * @return MediawikiStatsdDataFactory
*/
public function getStats() {
return MediaWikiServices::getInstance()->getStatsdDataFactory();
*
* @since 1.25
*/
-class BufferingStatsdDataFactory extends StatsdDataFactory {
+class BufferingStatsdDataFactory extends StatsdDataFactory implements MediawikiStatsdDataFactory {
protected $buffer = [];
+ /**
+ * Collection enabled?
+ * @var bool
+ */
+ protected $enabled = true;
+ /**
+ * @var string
+ */
+ private $prefix;
public function __construct( $prefix ) {
parent::__construct();
*
* @param string $key
* @since 1.26
+ * @return string
*/
private static function normalizeMetricKey( $key ) {
$key = preg_replace( '/[:.]+/', '.', $key );
$key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT
) {
$entity = $this->produceStatsdDataEntity();
+ if ( !$this->enabled ) {
+ return $entity;
+ }
if ( $key !== null ) {
$key = self::normalizeMetricKey( "{$this->prefix}.{$key}" );
$entity->setKey( $key );
}
/**
+ * @deprecated Use getData()
* @return StatsdData[]
*/
public function getBuffer() {
return $this->buffer;
}
+
+ /**
+ * Check whether this data factory has any data.
+ * @return boolean
+ */
+ public function hasData() {
+ return !empty( $this->buffer );
+ }
+
+ /**
+ * Return data from the factory.
+ * @return StatsdData[]
+ */
+ public function getData() {
+ return $this->buffer;
+ }
+
+ /**
+ * Set collection enable status.
+ * @param bool $enabled Will collection be enabled?
+ * @return void
+ */
+ public function setEnabled( $enabled ) {
+ $this->enabled = $enabled;
+ }
}
--- /dev/null
+<?php
+use Liuggio\StatsdClient\Entity\StatsdData;
+use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
+
+/**
+ * Mediawiki adaptation of Statsd data factory.
+ */
+interface MediawikiStatsdDataFactory extends StatsdDataFactoryInterface {
+ /**
+ * Check whether this data factory has any data.
+ * @return boolean
+ */
+ public function hasData();
+
+ /**
+ * Return data from the factory.
+ * @return StatsdData[]
+ */
+ public function getData();
+
+ /**
+ * Set collection enable status.
+ * @param bool $enabled Will collection be enabled?
+ * @return void
+ */
+ public function setEnabled( $enabled );
+
+}
* @author Addshore
* @since 1.27
*/
-class NullStatsdDataFactory implements StatsdDataFactoryInterface {
+class NullStatsdDataFactory implements MediawikiStatsdDataFactory {
/**
* This function creates a 'timing' StatsdData.
return $data;
}
+ /**
+ * Check whether this data factory has any data.
+ * @return boolean
+ */
+ public function hasData() {
+ return false;
+ }
+
+ /**
+ * Return data from the factory.
+ * @return StatsdData[]
+ */
+ public function getData() {
+ return [];
+ }
+
+ /**
+ * Set collection enable status.
+ * @param bool $enabled Will collection be enabled?
+ * @return void
+ */
+ public function setEnabled( $enabled ) {
+ // Nothing to do, null factory is always disabled.
+ }
}
'MainConfig' => [ 'MainConfig', Config::class ],
'SiteStore' => [ 'SiteStore', SiteStore::class ],
'SiteLookup' => [ 'SiteLookup', SiteLookup::class ],
- 'StatsdDataFactory' => [ 'StatsdDataFactory', StatsdDataFactory::class ],
+ 'StatsdDataFactory' => [ 'StatsdDataFactory', MediawikiStatsdDataFactory::class ],
'InterwikiLookup' => [ 'InterwikiLookup', InterwikiLookup::class ],
'EventRelayerGroup' => [ 'EventRelayerGroup', EventRelayerGroup::class ],
'SearchEngineFactory' => [ 'SearchEngineFactory', SearchEngineFactory::class ],