From: addshore Date: Sat, 2 Apr 2016 09:22:00 +0000 (+0300) Subject: Move statsd files in libs to own directory X-Git-Tag: 1.31.0-rc.0~7418 X-Git-Url: http://git.cyclocoop.org//%22javascript:ModifierStyle%28%27%22.%24id.%22%27%29/%22?a=commitdiff_plain;h=737e83edf59bdd9cb909cdc65c34c64f7ac07b85;p=lhc%2Fweb%2Fwiklou.git Move statsd files in libs to own directory Change-Id: Ia3ac9441d7548fedb672e3f2567be7c4eafae208 --- diff --git a/autoload.php b/autoload.php index c62e99d3ee..df38b3a2a2 100644 --- a/autoload.php +++ b/autoload.php @@ -185,7 +185,7 @@ $wgAutoloadLocalClasses = [ 'BmpHandler' => __DIR__ . '/includes/media/BMP.php', 'BotPassword' => __DIR__ . '/includes/user/BotPassword.php', 'BrokenRedirectsPage' => __DIR__ . '/includes/specials/SpecialBrokenRedirects.php', - 'BufferingStatsdDataFactory' => __DIR__ . '/includes/libs/BufferingStatsdDataFactory.php', + 'BufferingStatsdDataFactory' => __DIR__ . '/includes/libs/stats/BufferingStatsdDataFactory.php', 'CLIParser' => __DIR__ . '/maintenance/parse.php', 'CSSMin' => __DIR__ . '/includes/libs/CSSMin.php', 'CacheDependency' => __DIR__ . '/includes/cache/CacheDependency.php', @@ -893,7 +893,7 @@ $wgAutoloadLocalClasses = [ 'NullJob' => __DIR__ . '/includes/jobqueue/jobs/NullJob.php', 'NullLockManager' => __DIR__ . '/includes/filebackend/lockmanager/LockManager.php', 'NullRepo' => __DIR__ . '/includes/filerepo/NullRepo.php', - 'NullStatsdDataFactory' => __DIR__ . '/includes/libs/NullStatsdDataFactory.php', + 'NullStatsdDataFactory' => __DIR__ . '/includes/libs/stats/NullStatsdDataFactory.php', 'OOUIHTMLForm' => __DIR__ . '/includes/htmlform/OOUIHTMLForm.php', 'ORAField' => __DIR__ . '/includes/db/DatabaseOracle.php', 'ORAResult' => __DIR__ . '/includes/db/DatabaseOracle.php', diff --git a/includes/libs/BufferingStatsdDataFactory.php b/includes/libs/BufferingStatsdDataFactory.php deleted file mode 100644 index 9c18b10f10..0000000000 --- a/includes/libs/BufferingStatsdDataFactory.php +++ /dev/null @@ -1,87 +0,0 @@ -prefix = $prefix; - } - - /** - * Normalize a metric key for StatsD - * - * Replace occurences of '::' with dots and any other non-alphanumeric - * characters with underscores. Combine runs of dots or underscores. - * Then trim leading or trailing dots or underscores. - * - * @param string $key - * @since 1.26 - */ - private static function normalizeMetricKey( $key ) { - $key = preg_replace( '/[:.]+/', '.', $key ); - $key = preg_replace( '/[^a-z0-9.]+/i', '_', $key ); - $key = trim( $key, '_.' ); - return str_replace( [ '._', '_.' ], '.', $key ); - } - - public function produceStatsdData( - $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT - ) { - $entity = $this->produceStatsdDataEntity(); - if ( $key !== null ) { - $key = self::normalizeMetricKey( "{$this->prefix}.{$key}" ); - $entity->setKey( $key ); - } - if ( $value !== null ) { - $entity->setValue( $value ); - } - if ( $metric !== null ) { - $entity->setMetric( $metric ); - } - // Don't bother buffering a counter update with a delta of zero. - if ( !( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$value ) ) { - $this->buffer[] = $entity; - } - return $entity; - } - - /** - * @return StatsdData[] - */ - public function getBuffer() { - return $this->buffer; - } -} diff --git a/includes/libs/NullStatsdDataFactory.php b/includes/libs/NullStatsdDataFactory.php deleted file mode 100644 index 3b272e216e..0000000000 --- a/includes/libs/NullStatsdDataFactory.php +++ /dev/null @@ -1,111 +0,0 @@ -setKey( $key ); - $data->setValue( $value ); - $data->setMetric( $metric ); - return $data; - } - -} diff --git a/includes/libs/stats/BufferingStatsdDataFactory.php b/includes/libs/stats/BufferingStatsdDataFactory.php new file mode 100644 index 0000000000..9c18b10f10 --- /dev/null +++ b/includes/libs/stats/BufferingStatsdDataFactory.php @@ -0,0 +1,87 @@ +prefix = $prefix; + } + + /** + * Normalize a metric key for StatsD + * + * Replace occurences of '::' with dots and any other non-alphanumeric + * characters with underscores. Combine runs of dots or underscores. + * Then trim leading or trailing dots or underscores. + * + * @param string $key + * @since 1.26 + */ + private static function normalizeMetricKey( $key ) { + $key = preg_replace( '/[:.]+/', '.', $key ); + $key = preg_replace( '/[^a-z0-9.]+/i', '_', $key ); + $key = trim( $key, '_.' ); + return str_replace( [ '._', '_.' ], '.', $key ); + } + + public function produceStatsdData( + $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT + ) { + $entity = $this->produceStatsdDataEntity(); + if ( $key !== null ) { + $key = self::normalizeMetricKey( "{$this->prefix}.{$key}" ); + $entity->setKey( $key ); + } + if ( $value !== null ) { + $entity->setValue( $value ); + } + if ( $metric !== null ) { + $entity->setMetric( $metric ); + } + // Don't bother buffering a counter update with a delta of zero. + if ( !( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$value ) ) { + $this->buffer[] = $entity; + } + return $entity; + } + + /** + * @return StatsdData[] + */ + public function getBuffer() { + return $this->buffer; + } +} diff --git a/includes/libs/stats/NullStatsdDataFactory.php b/includes/libs/stats/NullStatsdDataFactory.php new file mode 100644 index 0000000000..3b272e216e --- /dev/null +++ b/includes/libs/stats/NullStatsdDataFactory.php @@ -0,0 +1,111 @@ +setKey( $key ); + $data->setValue( $value ); + $data->setMetric( $metric ); + return $data; + } + +}