From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- vendor/liuggio/statsd-php-client/CHANGELOG.md | 17 ++ vendor/liuggio/statsd-php-client/README.md | 152 ++++++++++++++++ vendor/liuggio/statsd-php-client/Readme.md | 149 ---------------- vendor/liuggio/statsd-php-client/composer.json | 2 +- vendor/liuggio/statsd-php-client/phpunit.xml | 15 ++ vendor/liuggio/statsd-php-client/phpunit.xml.dist | 15 -- .../src/Liuggio/StatsdClient/Entity/StatsdData.php | 28 ++- .../StatsdClient/Entity/StatsdDataInterface.php | 6 + .../Liuggio/StatsdClient/Service/StatsdService.php | 196 +++++++++++++++++++++ .../src/Liuggio/StatsdClient/StatsdClient.php | 8 +- .../StatsdClient/Service/StatsdServiceTest.php | 86 +++++++++ 11 files changed, 502 insertions(+), 172 deletions(-) create mode 100644 vendor/liuggio/statsd-php-client/CHANGELOG.md create mode 100644 vendor/liuggio/statsd-php-client/README.md delete mode 100644 vendor/liuggio/statsd-php-client/Readme.md create mode 100644 vendor/liuggio/statsd-php-client/phpunit.xml delete mode 100644 vendor/liuggio/statsd-php-client/phpunit.xml.dist create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Service/StatsdService.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php (limited to 'vendor/liuggio/statsd-php-client') diff --git a/vendor/liuggio/statsd-php-client/CHANGELOG.md b/vendor/liuggio/statsd-php-client/CHANGELOG.md new file mode 100644 index 00000000..e7ee9a44 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/CHANGELOG.md @@ -0,0 +1,17 @@ +CHANGELOG for 1.x.x +=================== + +This changelog references the relevant changes (bug and security fixes) done +in 1.x.x minor. + +To get the diff for a specific change, go to https://github.com/liuggio/statsd-php-client/commit/XXX where XXX is the change hash +To get the diff between two versions, go to https://github.com/liuggio/statsd-php-client/compare/v1.0.12...v1.0.13 + +### 1.0.14, 1.0.16 + * fix minor casing issue + * php 5.3.2 instead of php5.2 + +### 1.0.13 + * add changelog + * feature StatsdService abstracting Client/Factory usage + * feature Deal with sampling in StatsdService diff --git a/vendor/liuggio/statsd-php-client/README.md b/vendor/liuggio/statsd-php-client/README.md new file mode 100644 index 00000000..e7c6f67a --- /dev/null +++ b/vendor/liuggio/statsd-php-client/README.md @@ -0,0 +1,152 @@ +## statsd-php-client + +Be careful, see the [Upgrading section](Readme.md#upgrade) for <= v1.0.4, there's a BC. + +[![Build Status](https://secure.travis-ci.org/liuggio/statsd-php-client.png)](http://travis-ci.org/liuggio/statsd-php-client) [![Latest Stable Version](https://poser.pugx.org/liuggio/statsd-php-client/v/stable.png)](https://packagist.org/packages/liuggio/statsd-php-client) [![Total Downloads](https://poser.pugx.org/liuggio/statsd-php-client/downloads.png)](https://packagist.org/packages/liuggio/statsd-php-client) + +`statsd-php-client` is an Open Source, and **Object Oriented** Client for **etsy/statsd** written in php + +- `StatsdDataFactory` creates the `Liuggio\StatsdClient\Entity\StatsdDataInterface` Objects + +- `Sender` just sends data over the network (there are many sender) + +- `StatsdClient` sends the created objects via the `Sender` to the server + +## Why use this library instead the [statsd/php-example](https://github.com/etsy/statsd/blob/master/examples/php-example.php)? + +- You are wise. + +- You could also use monolog to redirect data to statsd + +- This library is tested. + +- This library optimizes the messages to send, compressing multiple messages in individual UDP packets. + +- This library pays attention to the maximum length of the UDP. + +- This library is made by Objects not array, but it also accepts array. + +- You do want to debug the packets, and using `SysLogSender` the packets will be logged in your `syslog` log (on debian-like distro: `tail -f /var/log/syslog`) + + +## Example + +1. create the Sender + +2. create the Client + +3. create the Factory + +4. the Factory will help you to create data + +5. the Client will send the data + +### Standard Usage + +```php +use Liuggio\StatsdClient\StatsdClient, + Liuggio\StatsdClient\Factory\StatsdDataFactory, + Liuggio\StatsdClient\Sender\SocketSender, + Liuggio\StatsdClient\Service\StatsdService; +// use Liuggio\StatsdClient\Sender\SysLogSender; + +$sender = new SocketSender(/*'localhost', 8126, 'udp'*/); +// $sender = new SysLogSender(); // enabling this, the packet will not send over the socket + +$client = new StatsdClient($sender); +$factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); +$service = new StatsdService($client, $factory); + +// create the metrics with the service +$service->timing('usageTime', 100); +$service->increment('visitor'); +$service->decrement('click'); +$service->gauge('gaugor', 333); +$service->set('uniques', 765); + +// send the data to statsd +$service->flush(); + +``` + +### Usage with Monolog + +```php +use Liuggio\StatsdClient\StatsdClient, + Liuggio\StatsdClient\Factory\StatsdDataFactory, + Liuggio\StatsdClient\Sender\SocketSender; +// use Liuggio\StatsdClient\Sender\SysLogSender; + +use Monolog\Logger; +use Liuggio\StatsdClient\Monolog\Handler\StatsDHandler; + +$sender = new SocketSender(/*'localhost', 8126, 'udp'*/); +// $sender = new SysLogSender(); // enabling this, the packet will not send over the socket +$client = new StatsdClient($sender); +$factory = new StatsdDataFactory(); + +$logger = new Logger('my_logger'); +$logger->pushHandler(new StatsDHandler($client, $factory, 'prefix', Logger::DEBUG)); + +$logger->addInfo('My logger is now ready'); +``` + +the output will be: `prefix.my_logger.INFO.My-logger:1|c" 36 Bytes` + + + + +## Short Theory + +### Easily Install StatSD and Graphite + +In order to try this application monitor you have to install etsy/statsd and Graphite + +see this blog post to install it with vagrant [Easy install statsd graphite](http://welcometothebundle.com/easily-install-statsd-and-graphite-with-vagrant/). + +#### [StatsD](https://github.com/etsy/statsd) + +StatsD is a simple daemon for easy stats aggregation + +#### [Graphite](http://graphite.wikidot.com/) + +Graphite is a Scalable Realtime Graphing + +#### The Client sends data with UDP (faster) + +https://www.google.com/search?q=tcp+vs+udp + +## Contribution + +Active contribution and patches are very welcome. +To keep things in shape we have quite a bunch of unit tests. If you're submitting pull requests please +make sure that they are still passing and if you add functionality please +take a look at the coverage as well it should be pretty high :) + +- First fork or clone the repository + +``` +git clone git://github.com/liuggio/statsd-php-client.git +cd statsd-php-client +``` + +- Install vendors: + +``` bash +composer.phar install +``` + +- This will give you proper results: + +``` bash +phpunit --coverage-html reports +``` + +## Upgrade + +BC from the v1.0.4 version, [see Sender and Client differences](https://github.com/liuggio/statsd-php-client/pull/5/files). + + +## TODO + +example with monolog diff --git a/vendor/liuggio/statsd-php-client/Readme.md b/vendor/liuggio/statsd-php-client/Readme.md deleted file mode 100644 index 81083e05..00000000 --- a/vendor/liuggio/statsd-php-client/Readme.md +++ /dev/null @@ -1,149 +0,0 @@ -## statsd-php-client - -Be careful, see the [Upgrading section](Readme.md#upgrade) for <= v1.0.4, there's a BC. - -[![Build Status](https://secure.travis-ci.org/liuggio/statsd-php-client.png)](http://travis-ci.org/liuggio/statsd-php-client) [![Latest Stable Version](https://poser.pugx.org/liuggio/statsd-php-client/v/stable.png)](https://packagist.org/packages/liuggio/statsd-php-client) [![Total Downloads](https://poser.pugx.org/liuggio/statsd-php-client/downloads.png)](https://packagist.org/packages/liuggio/statsd-php-client) - -`statsd-php-client` is an Open Source, and **Object Oriented** Client for **etsy/statsd** written in php - -- `StatsdDataFactory` creates the `Liuggio\StatsdClient\Entity\StatsdDataInterface` Objects - -- `Sender` just sends data over the network (there are many sender) - -- `StatsdClient` sends the created objects via the `Sender` to the server - -## Why use this library instead the [statsd/php-example](https://github.com/etsy/statsd/blob/master/examples/php-example.php)? - -- You are wise. - -- You could also use monolog to redirect data to statsd - -- This library is tested. - -- This library optimizes the messages to send, compressing multiple messages in individual UDP packets. - -- This library pays attention to the maximum length of the UDP. - -- This library is made by Objects not array, but it also accepts array. - -- You do want to debug the packets, and using `SysLogSender` the packets will be logged in your `syslog` log (on debian-like distro: `tail -f /var/log/syslog`) - - -## Example - -1. create the Sender - -2. create the Client - -3. create the Factory - -4. the Factory will help you to create data - -5. the Client will send the data - -### Standard Usage - -```php -use Liuggio\StatsdClient\StatsdClient, - Liuggio\StatsdClient\Factory\StatsdDataFactory, - Liuggio\StatsdClient\Sender\SocketSender; -// use Liuggio\StatsdClient\Sender\SysLogSender; - -$sender = new SocketSender(/*'localhost', 8126, 'udp'*/); -// $sender = new SysLogSender(); // enabling this, the packet will not send over the socket - -$client = new StatsdClient($sender); -$factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); - -// create the data with the factory -$data[] = $factory->timing('usageTime', 100); -$data[] = $factory->increment('visitor'); -$data[] = $factory->decrement('click'); -$data[] = $factory->gauge('gaugor', 333); -$data[] = $factory->set('uniques', 765); - -// send the data as array or directly as object -$client->send($data); -``` - -### Usage with Monolog - -```php -use Liuggio\StatsdClient\StatsdClient, - Liuggio\StatsdClient\Factory\StatsdDataFactory, - Liuggio\StatsdClient\Sender\SocketSender; -// use Liuggio\StatsdClient\Sender\SysLogSender; - -use Monolog\Logger; -use Liuggio\StatsdClient\Monolog\Handler\StatsDHandler; - -$sender = new SocketSender(/*'localhost', 8126, 'udp'*/); -// $sender = new SysLogSender(); // enabling this, the packet will not send over the socket -$client = new StatsdClient($sender); -$factory = new StatsdDataFactory(); - -$logger = new Logger('my_logger'); -$logger->pushHandler(new StatsDHandler($client, $factory, 'prefix', Logger::DEBUG)); - -$logger->addInfo('My logger is now ready'); -``` - -the output will be: `prefix.my_logger.INFO.My-logger:1|c" 36 Bytes` - - - - -## Short Theory - -### Easily Install StatSD and Graphite - -In order to try this application monitor you have to install etsy/statsd and Graphite - -see this blog post to install it with vagrant [Easy install statsd graphite](http://welcometothebundle.com/easily-install-statsd-and-graphite-with-vagrant/). - -#### [StatsD](https://github.com/etsy/statsd) - -StatsD is a simple daemon for easy stats aggregation - -#### [Graphite](http://graphite.wikidot.com/) - -Graphite is a Scalable Realtime Graphing - -#### The Client sends data with UDP (faster) - -https://www.google.com/search?q=tcp+vs+udp - -## Contribution - -Active contribution and patches are very welcome. -To keep things in shape we have quite a bunch of unit tests. If you're submitting pull requests please -make sure that they are still passing and if you add functionality please -take a look at the coverage as well it should be pretty high :) - -- First fork or clone the repository - -``` -git clone git://github.com/liuggio/statsd-php-client.git -cd statsd-php-client -``` - -- Install vendors: - -``` bash -composer.phar install -``` - -- This will give you proper results: - -``` bash -phpunit --coverage-html reports -``` - -## Upgrade - -BC from the v1.0.4 version, [see Sender and Client differences](https://github.com/liuggio/statsd-php-client/pull/5/files). - - -## TODO - -example with monolog diff --git a/vendor/liuggio/statsd-php-client/composer.json b/vendor/liuggio/statsd-php-client/composer.json index 705dbdf8..b47e0fd6 100644 --- a/vendor/liuggio/statsd-php-client/composer.json +++ b/vendor/liuggio/statsd-php-client/composer.json @@ -6,7 +6,7 @@ "type": "library", "license": "MIT", "require": { - "php": ">=5.2" + "php": ">=5.3.2" }, "authors": [ { diff --git a/vendor/liuggio/statsd-php-client/phpunit.xml b/vendor/liuggio/statsd-php-client/phpunit.xml new file mode 100644 index 00000000..621efd75 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/phpunit.xml @@ -0,0 +1,15 @@ + + + + + + tests/Liuggio/StatsdClient + + + + + + src/Liuggio/ + + + \ No newline at end of file diff --git a/vendor/liuggio/statsd-php-client/phpunit.xml.dist b/vendor/liuggio/statsd-php-client/phpunit.xml.dist deleted file mode 100644 index 621efd75..00000000 --- a/vendor/liuggio/statsd-php-client/phpunit.xml.dist +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - tests/Liuggio/StatsdClient - - - - - - src/Liuggio/ - - - \ No newline at end of file diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.php index 9c6203db..2f030859 100644 --- a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.php +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.php @@ -10,6 +10,7 @@ class StatsdData implements StatsdDataInterface private $key; private $value; private $metric; + private $sampleRate = 1; /** * @param string $key @@ -54,6 +55,22 @@ class StatsdData implements StatsdDataInterface return $this->metric; } + /** + * @param float $sampleRate + */ + public function setSampleRate($sampleRate) + { + $this->sampleRate = $sampleRate; + } + + /** + * @return float + */ + public function getSampleRate() + { + return $this->sampleRate; + } + /** * @param bool $withMetric * @@ -62,10 +79,17 @@ class StatsdData implements StatsdDataInterface public function getMessage($withMetric = true) { if (!$withMetric) { - return sprintf('%s:%s', $this->getKey(), $this->getValue()); + $result = sprintf('%s:%s', $this->getKey(), $this->getValue()); } else { - return sprintf('%s:%s|%s', $this->getKey(), $this->getValue(), $this->getMetric()); + $result = sprintf('%s:%s|%s', $this->getKey(), $this->getValue(), $this->getMetric()); } + + $sampleRate = $this->getSampleRate(); + if($sampleRate < 1){ + $result.= "|@$sampleRate"; + } + + return $result; } /** diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.php index 846bc7cc..d7b07a80 100644 --- a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.php +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.php @@ -33,6 +33,12 @@ interface StatsdDataInterface */ function getMessage(); + /** + * @abstract + * @return float + */ + function getSampleRate(); + /** * @abstract * @return string diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Service/StatsdService.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Service/StatsdService.php new file mode 100644 index 00000000..061e3510 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Service/StatsdService.php @@ -0,0 +1,196 @@ +client = $client; + if (is_null($factory)) { + $factory = new StatsdDataFactory(); + } + $this->factory = $factory; + $this->setSamplingRate($samplingRate); + } + + /** + * Actually defines the sampling rate used by the service. + * If set to 0.1, the service will automatically discard 10% + * of the incoming metrics. It will also automatically flag these + * as sampled data to statsd. + * + * @param float $samplingRate + */ + public function setSamplingRate($samplingRate) + { + if ($samplingRate <= 0.0 || 1.0 < $samplingRate) { + throw new \LogicException('Sampling rate shall be within ]0, 1]'); + } + $this->samplingRate = $samplingRate; + $this->samplingFunction = function($min, $max){ + return rand($min, $max); + }; + } + + /** + * @return float + */ + public function getSamplingRate() + { + return $this->samplingRate; + } + + /** + * {@inheritdoc} + */ + public function timing($key, $time) + { + $this->appendToBuffer( + $this->factory->timing($key, $time) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function gauge($key, $value) + { + $this->appendToBuffer( + $this->factory->gauge($key, $value) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function set($key, $value) + { + $this->appendToBuffer( + $this->factory->set($key, $value) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function increment($key) + { + $this->appendToBuffer( + $this->factory->increment($key) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function decrement($key) + { + $this->appendToBuffer( + $this->factory->decrement($key) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function updateCount($key, $delta) + { + $this->appendToBuffer( + $this->factory->updateCount($key, $delta) + ); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function produceStatsdData($key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT) + { + throw new \BadFunctionCallException('produceStatsdData is not implemented'); + } + + /** + * @param callable $samplingFunction rand() function by default. + */ + public function setSamplingFunction(\Closure $samplingFunction) + { + $this->samplingFunction = $samplingFunction; + } + + private function appendToBuffer(StatsdData $data) + { + if($this->samplingRate < 1){ + $data->setSampleRate($this->samplingRate); + $result = call_user_func($this->samplingFunction, 0 , floor(1 / $this->samplingRate)); + if ($result == 0) { + array_push($this->buffer, $data); + }; + } else { + array_push($this->buffer, $data); + } + } + + /** + * Send all buffered data to statsd. + * + * @return $this + */ + public function flush() + { + $this->client->send($this->buffer); + $this->buffer = array(); + + return $this; + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php index a1d232a5..c5c16fed 100644 --- a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php @@ -109,12 +109,10 @@ class StatsdClient implements StatsdClientInterface */ public function appendSampleRate($data, $sampleRate = 1) { - $sampledData = array(); if ($sampleRate < 1) { - foreach ($data as $key => $message) { - $sampledData[$key] = sprintf('%s|@%s', $message, $sampleRate); - } - $data = $sampledData; + array_walk($data, function(&$message, $key) use ($sampleRate) { + $message = sprintf('%s|@%s', $message, $sampleRate); + }); } return $data; diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php new file mode 100644 index 00000000..dcf2710d --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Service/StatsdServiceTest.php @@ -0,0 +1,86 @@ +clientMock = $this->getMockBuilder('Liuggio\StatsdClient\StatsdClient') + ->disableOriginalConstructor() + ->getMock(); + $this->factoryMock = $this->getMockBuilder('Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface') + ->disableOriginalConstructor() + ->getMock(); + } + + public function testConstructorWithoutFactory() + { + $dut = new StatsdService($this->clientMock); + $dut->timing('foo.bar', 123); + } + + public function testFactoryImplementation() + { + $data = new StatsdData(); + + // Configure the client mock. + $this->factoryMock->expects($this->once())->method('timing')->willReturn($data); + $this->factoryMock->expects($this->once())->method('gauge')->willReturn($data); + $this->factoryMock->expects($this->once())->method('set')->willReturn($data); + $this->factoryMock->expects($this->once())->method('increment')->willReturn($data); + $this->factoryMock->expects($this->once())->method('decrement')->willReturn($data); + $this->factoryMock->expects($this->once())->method('updateCount')->willReturn($data); + + // Actual test + $dut = new StatsdService($this->clientMock, $this->factoryMock); + $dut->timing('foo.bar', 123); + $dut->gauge('foo.bar', 123); + $dut->set('foo.bar', 123); + $dut->increment('foo.bar'); + $dut->decrement('foo.bar'); + $dut->updateCount('foo.bar', 123); + } + + public function testFlush() + { + $data = new StatsdData(); + $this->factoryMock->expects($this->once())->method('timing')->willReturn($data); + $this->clientMock->expects($this->once())->method('send') + ->with($this->equalTo(array($data))); + + // Actual test + $dut = new StatsdService($this->clientMock, $this->factoryMock); + $dut->timing('foobar', 123); + $dut->flush(); + } + + public function testSampling() + { + $tries = false; + $closure = function($a, $b) use (&$tries) { + $tries = !$tries; + return $tries ? 1 : 0; + }; + + $data = new StatsdData(); + $this->factoryMock->expects($this->exactly(2))->method('timing')->willReturn($data); + $this->clientMock->expects($this->once())->method('send') + ->with($this->equalTo(array($data))); + + // Actual test + $dut = new StatsdService($this->clientMock, $this->factoryMock); + $dut->setSamplingRate(0.1); + $dut->setSamplingFunction($closure); + $dut->timing('foo', 123); + $dut->timing('bar', 123); + $dut->flush(); + + $this->assertSame(0.1, $data->getSampleRate()); + } +} -- cgit v1.2.3-54-g00ecf