From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- vendor/liuggio/statsd-php-client/LICENSE | 19 ++ vendor/liuggio/statsd-php-client/Readme.md | 149 ++++++++++++++ vendor/liuggio/statsd-php-client/composer.json | 26 +++ vendor/liuggio/statsd-php-client/phpunit.xml.dist | 15 ++ .../src/Liuggio/StatsdClient/Entity/StatsdData.php | 78 +++++++ .../StatsdClient/Entity/StatsdDataInterface.php | 41 ++++ .../Exception/InvalidArgumentException.php | 7 + .../StatsdClient/Factory/StatsdDataFactory.php | 130 ++++++++++++ .../Factory/StatsdDataFactoryInterface.php | 99 +++++++++ .../Monolog/Formatter/StatsDFormatter.php | 101 +++++++++ .../StatsdClient/Monolog/Handler/StatsDHandler.php | 120 +++++++++++ .../src/Liuggio/StatsdClient/Sender/EchoSender.php | 35 ++++ .../StatsdClient/Sender/SenderInterface.php | 32 +++ .../Liuggio/StatsdClient/Sender/SocketSender.php | 88 ++++++++ .../Liuggio/StatsdClient/Sender/SysLogSender.php | 42 ++++ .../src/Liuggio/StatsdClient/StatsdClient.php | 211 +++++++++++++++++++ .../Liuggio/StatsdClient/StatsdClientInterface.php | 23 +++ .../Liuggio/StatsdClient/Entity/StatsdDataTest.php | 27 +++ .../Monolog/Formatter/StatsDFormatterTest.php | 169 +++++++++++++++ .../Monolog/Handler/StatsDHandlerTest.php | 89 ++++++++ .../tests/Liuggio/StatsdClient/ReadmeTest.php | 72 +++++++ .../Liuggio/StatsdClient/StatsdClientTest.php | 228 +++++++++++++++++++++ .../Liuggio/StatsdClient/StatsdDataFactoryTest.php | 97 +++++++++ .../liuggio/statsd-php-client/tests/bootstrap.php | 5 + 24 files changed, 1903 insertions(+) create mode 100644 vendor/liuggio/statsd-php-client/LICENSE create mode 100644 vendor/liuggio/statsd-php-client/Readme.md create mode 100644 vendor/liuggio/statsd-php-client/composer.json create mode 100644 vendor/liuggio/statsd-php-client/phpunit.xml.dist create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Exception/InvalidArgumentException.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactory.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactoryInterface.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatter.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SenderInterface.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SocketSender.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php create mode 100644 vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClientInterface.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Entity/StatsdDataTest.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Handler/StatsDHandlerTest.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdClientTest.php create mode 100644 vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php create mode 100644 vendor/liuggio/statsd-php-client/tests/bootstrap.php (limited to 'vendor/liuggio') diff --git a/vendor/liuggio/statsd-php-client/LICENSE b/vendor/liuggio/statsd-php-client/LICENSE new file mode 100644 index 00000000..3af47475 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) Giulio De Donato + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/liuggio/statsd-php-client/Readme.md b/vendor/liuggio/statsd-php-client/Readme.md new file mode 100644 index 00000000..81083e05 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/Readme.md @@ -0,0 +1,149 @@ +## 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 new file mode 100644 index 00000000..705dbdf8 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/composer.json @@ -0,0 +1,26 @@ +{ + "name": "liuggio/statsd-php-client", + "description": "Statsd (Object Oriented) client library for PHP", + "keywords": ["statsd", "monitoring", "etsy", "php"], + "homepage": "https://github.com/liuggio/statsd-php-client/", + "type": "library", + "license": "MIT", + "require": { + "php": ">=5.2" + }, + "authors": [ + { + "name": "Giulio De Donato", + "email": "liuggio@gmail.com" + } + ], + "autoload": { + "psr-0": {"Liuggio": "src/"} + }, + "require-dev": { + "monolog/monolog": ">=1.2.0" + }, + "suggest": { + "monolog/monolog": "Monolog, in order to do generate statistic from log >=1.2.0)" + } +} diff --git a/vendor/liuggio/statsd-php-client/phpunit.xml.dist b/vendor/liuggio/statsd-php-client/phpunit.xml.dist new file mode 100644 index 00000000..621efd75 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/phpunit.xml.dist @@ -0,0 +1,15 @@ + + + + + + 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 new file mode 100644 index 00000000..9c6203db --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdData.php @@ -0,0 +1,78 @@ +key = $key; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param int $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * @return int + */ + public function getValue() + { + return $this->value; + } + + + public function setMetric($metric) + { + $this->metric = $metric; + } + + public function getMetric() + { + return $this->metric; + } + + /** + * @param bool $withMetric + * + * @return string + */ + public function getMessage($withMetric = true) + { + if (!$withMetric) { + return sprintf('%s:%s', $this->getKey(), $this->getValue()); + } else { + return sprintf('%s:%s|%s', $this->getKey(), $this->getValue(), $this->getMetric()); + } + } + + /** + * @return string + */ + public function __toString() + { + return $this->getMessage(); + } +} 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 new file mode 100644 index 00000000..846bc7cc --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Entity/StatsdDataInterface.php @@ -0,0 +1,41 @@ +setEntityClass($entity_class); + } + + /** + * {@inheritDoc} + **/ + public function timing($key, $time) + { + return $this->produceStatsdData($key, $time, StatsdDataInterface::STATSD_METRIC_TIMING); + } + + /** + * {@inheritDoc} + **/ + public function gauge($key, $value) + { + return $this->produceStatsdData($key, $value, StatsdDataInterface::STATSD_METRIC_GAUGE); + } + + /** + * {@inheritDoc} + **/ + public function set($key, $value) + { + return $this->produceStatsdData($key, $value, StatsdDataInterface::STATSD_METRIC_SET); + } + + /** + * {@inheritDoc} + **/ + public function increment($key) + { + return $this->produceStatsdData($key, 1, StatsdDataInterface::STATSD_METRIC_COUNT); + } + + /** + * {@inheritDoc} + **/ + public function decrement($key) + { + return $this->produceStatsdData($key, -1, StatsdDataInterface::STATSD_METRIC_COUNT); + } + + /** + * {@inheritDoc} + **/ + public function updateCount($key, $delta) + { + return $this->produceStatsdData($key, $delta, StatsdDataInterface::STATSD_METRIC_COUNT); + } + + /** + * {@inheritDoc} + **/ + public function produceStatsdData($key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT) + { + $statsdData = $this->produceStatsdDataEntity(); + + if (null !== $key) { + $statsdData->setKey($key); + } + + if (null !== $value) { + $statsdData->setValue($value); + } + + if (null !== $metric) { + $statsdData->setMetric($metric); + } + + return $statsdData; + } + + /** + * {@inheritDoc} + **/ + public function produceStatsdDataEntity() + { + $statsdData = $this->getEntityClass(); + + return new $statsdData(); + } + + /** + * {@inheritDoc} + **/ + public function setFailSilently($failSilently) + { + $this->failSilently = $failSilently; + } + + /** + * {@inheritDoc} + **/ + public function getFailSilently() + { + return $this->failSilently; + } + + /** + * {@inheritDoc} + **/ + public function setEntityClass($entityClass) + { + $this->entityClass = $entityClass; + } + + /** + * {@inheritDoc} + **/ + public function getEntityClass() + { + return $this->entityClass; + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactoryInterface.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactoryInterface.php new file mode 100644 index 00000000..4d58833b --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Factory/StatsdDataFactoryInterface.php @@ -0,0 +1,99 @@ + + * @author Christophe Coevoet + * @author Giulio De Donato + */ +class StatsDFormatter extends LineFormatter +{ + const SIMPLE_FORMAT = "%channel%.%level_name%.%short_message%"; + + protected $numberOfWords; + protected $logContext; + protected $logExtra; + + /** + * @param string $format The format of the message + * @param Boolean $logContext If true add multiple rows containing Context information + * @param Boolean $logExtra If true add multiple rows containing Extra information + * @param integer $numberOfWords The number of words to show. + */ + public function __construct($format = null, $logContext = true, $logExtra = true, $numberOfWords = 2) + { + $this->format = $format ? : static::SIMPLE_FORMAT; + $this->numberOfWords = $numberOfWords; + $this->logContext = $logContext; + $this->logExtra = $logExtra; + parent::__construct(); + } + + /** + * This function converts a long message into a string with the first N-words. + * eg. from: "Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener" + * to: "Notified event" + * + * @param string $message The message to shortify. + * + * @return string + */ + public function getFirstWords($message) + { + $glue = '-'; + $pieces = explode(' ', $message); + array_splice($pieces, $this->numberOfWords); + $shortMessage = preg_replace("/[^A-Za-z0-9?![:space:]]/", "-", implode($glue, $pieces)); + + return $shortMessage; + } + + /** + * {@inheritdoc} + */ + public function format(array $record) + { + $vars = $this->normalize($record); + + $firstRow = $this->format; + $output = array(); + + $vars['short_message'] = $this->getFirstWords($vars['message']); + foreach ($vars as $var => $val) { + $firstRow = str_replace('%' . $var . '%', $this->convertToString($val), $firstRow); + } + $output[] = $firstRow; + // creating more rows for context content + if ($this->logContext && isset($vars['context'])) { + foreach ($vars['context'] as $key => $parameter) { + $output[] = sprintf("%s.context.%s.%s", $firstRow, $key, $parameter); + } + } + // creating more rows for extra content + if ($this->logExtra && isset($vars['extra'])) { + foreach ($vars['extra'] as $key => $parameter) { + $output[] = sprintf("%s.extra.%s.%s", $firstRow, $key, $parameter); + } + } + + return $output; + } + + /** + * {@inheritdoc} + */ + public function formatBatch(array $records) + { + $output = array(); + foreach ($records as $record) { + $output = array_merge($output, $this->format($record)); + } + + return $output; + } +} \ No newline at end of file diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php new file mode 100644 index 00000000..86c6d399 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Monolog/Handler/StatsDHandler.php @@ -0,0 +1,120 @@ + + */ +class StatsDHandler extends AbstractProcessingHandler +{ + /** + * @var array + */ + protected $buffer = array(); + + /** + * @var string + */ + protected $prefix; + + /** + * @var statsDService + */ + protected $statsDService; + + /** + * @var statsDFactory + */ + protected $statsDFactory; + + /** + * @param StatsdClientInterface $statsDService The Service sends the packet + * @param StatsdDataFactoryInterface $statsDFactory The Factory creates the StatsDPacket + * @param string $prefix Statsd key prefix + * @param integer $level The minimum logging level at which this handler will be triggered + * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not + */ + public function __construct(StatsdClientInterface $statsDService, StatsdDataFactoryInterface $statsDFactory = null, $prefix, $level = Logger::DEBUG, $bubble = true) + { + parent::__construct($level, $bubble); + + $this->statsDService = $statsDService; + $this->statsDFactory = $statsDFactory ? $statsDFactory : new StatsdDataFactory(); + $this->prefix = $prefix; + } + + /** + * {@inheritdoc} + */ + public function close() + { + $this->statsDService->send($this->buffer); + } + + /** + * {@inheritdoc} + */ + protected function write(array $record) + { + $records = is_array($record['formatted']) ? $record['formatted'] : array($record['formatted']); + + foreach ($records as $record) { + if (!empty($record)) { + $this->buffer[] = $this->statsDFactory->increment(sprintf('%s.%s', $this->getPrefix(), $record)); + } + } + } + + /** + * Gets the default formatter. + * + * @return FormatterInterface + */ + protected function getDefaultFormatter() + { + return new StatsDFormatter(); + } + + /** + * @param string $prefix + */ + public function setPrefix($prefix) + { + $this->prefix = $prefix; + } + + /** + * @return string + */ + public function getPrefix() + { + return $this->prefix; + } + + /** + * @param StatsdClientInterface $statsDService + */ + public function setStatsDService(StatsdClientInterface $statsDService) + { + $this->statsDService = $statsDService; + } + + /** + * @param StatsdDataFactoryInterface $statsDFactory + */ + public function setStatsDFactory(StatsdDataFactoryInterface $statsDFactory) + { + $this->statsDFactory = $statsDFactory; + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php new file mode 100644 index 00000000..1015ca94 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/EchoSender.php @@ -0,0 +1,35 @@ +host = $hostname; + $this->port = $port; + + switch ($protocol) { + case 'udp': + $this->protocol = SOL_UDP; + break; + case 'tcp': + $this->protocol = SOL_TCP; + break; + default: + throw new InvalidArgumentException(sprintf('Use udp or tcp as protocol given %s', $protocol)); + break; + } + + } + + /** + * {@inheritDoc} + */ + public function open() + { + $fp = socket_create(AF_INET, SOCK_DGRAM, $this->getProtocol()); + + return $fp; + } + + /** + * {@inheritDoc} + */ + public function write($handle, $message, $length = null) + { + return socket_sendto($handle, $message, strlen($message), 0, $this->getHost(), $this->getPort()); + } + + /** + * {@inheritDoc} + */ + public function close($handle) + { + socket_close($handle); + } + + + protected function setHost($host) + { + $this->host = $host; + } + + protected function getHost() + { + return $this->host; + } + + protected function setPort($port) + { + $this->port = $port; + } + + protected function getPort() + { + return $this->port; + } + + protected function setProtocol($protocol) + { + $this->protocol = $protocol; + } + + protected function getProtocol() + { + return $this->protocol; + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php new file mode 100644 index 00000000..537ead39 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/Sender/SysLogSender.php @@ -0,0 +1,42 @@ +priority = $priority; + } + + /** + * {@inheritDoc} + */ + public function open() + { + syslog($this->priority, "statsd-client-open"); + + return true; + } + + /** + * {@inheritDoc} + */ + function write($handle, $message, $length = null) + { + syslog($this->priority, sprintf("statsd-client-write \"%s\" %d Bytes", $message, strlen($message))); + + return strlen($message); + } + + /** + * {@inheritDoc} + */ + function close($handle) + { + syslog($this->priority, "statsd-client-close"); + } +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php new file mode 100644 index 00000000..a1d232a5 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClient.php @@ -0,0 +1,211 @@ +sender = $sender; + $this->reducePacket = $reducePacket; + $this->failSilently = $fail_silently; + } + + /** + * Throws an exc only if failSilently if getFailSilently is false. + * + * @param \Exception $exception + * + * @throws \Exception + */ + private function throwException(\Exception $exception) + { + if (!$this->getFailSilently()) { + throw $exception; + } + } + + /** + * This function reduces the number of packets,the reduced has the maximum dimension of self::MAX_UDP_SIZE_STR + * Reference: + * https://github.com/etsy/statsd/blob/master/README.md + * All metrics can also be batch send in a single UDP packet, separated by a newline character. + * + * @param array $reducedMetrics + * @param array $metric + * + * @return array + */ + private static function doReduce($reducedMetrics, $metric) + { + $metricLength = strlen($metric); + $lastReducedMetric = count($reducedMetrics) > 0 ? end($reducedMetrics) : null; + + if ($metricLength >= self::MAX_UDP_SIZE_STR + || null === $lastReducedMetric + || strlen($newMetric = $lastReducedMetric . "\n" . $metric) > self::MAX_UDP_SIZE_STR + ) { + $reducedMetrics[] = $metric; + } else { + array_pop($reducedMetrics); + $reducedMetrics[] = $newMetric; + } + + return $reducedMetrics; + } + + + /** + * this function reduce the amount of data that should be send + * + * @param mixed $arrayData + * + * @return mixed $arrayData + */ + public function reduceCount($arrayData) + { + if (is_array($arrayData)) { + $arrayData = array_reduce($arrayData, "self::doReduce", array()); + } + + return $arrayData; + } + + /** + * Reference: https://github.com/etsy/statsd/blob/master/README.md + * Sampling 0.1 + * Tells StatsD that this counter is being sent sampled every 1/10th of the time. + * + * @param mixed $data + * @param int $sampleRate + * + * @return mixed $data + */ + 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; + } + + return $data; + } + + /* + * Send the metrics over UDP + * + * {@inheritDoc} + */ + public function send($data, $sampleRate = 1) + { + // check format + if ($data instanceof StatsdDataInterface || is_string($data)) { + $data = array($data); + } + if (!is_array($data) || empty($data)) { + return; + } + // add sampling + if ($sampleRate < 1) { + $data = $this->appendSampleRate($data, $sampleRate); + } + // reduce number of packets + if ($this->getReducePacket()) { + $data = $this->reduceCount($data); + } + //failures in any of this should be silently ignored if .. + try { + $fp = $this->getSender()->open(); + if (!$fp) { + return; + } + $written = 0; + foreach ($data as $key => $message) { + $written += $this->getSender()->write($fp, $message); + } + $this->getSender()->close($fp); + } catch (\Exception $e) { + $this->throwException($e); + } + + return $written; + } + + /** + * @param boolean $failSilently + */ + public function setFailSilently($failSilently) + { + $this->failSilently = $failSilently; + } + + /** + * @return boolean + */ + public function getFailSilently() + { + return $this->failSilently; + } + + /** + * @param \Liuggio\StatsdClient\Sender\SenderInterface $sender + */ + public function setSender(SenderInterface $sender) + { + $this->sender = $sender; + } + + /** + * @return \Liuggio\StatsdClient\Sender\SenderInterface + */ + public function getSender() + { + return $this->sender; + } + + /** + * @param boolean $reducePacket + */ + public function setReducePacket($reducePacket) + { + $this->reducePacket = $reducePacket; + } + + /** + * @return boolean + */ + public function getReducePacket() + { + return $this->reducePacket; + } + +} diff --git a/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClientInterface.php b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClientInterface.php new file mode 100644 index 00000000..e2c75cda --- /dev/null +++ b/vendor/liuggio/statsd-php-client/src/Liuggio/StatsdClient/StatsdClientInterface.php @@ -0,0 +1,23 @@ +setKey('key'); + $statsdData->setValue('value'); + $statsdData->setMetric('c'); + + $this->assertEquals($statsdData->getMessage(), 'key:value|c'); + + $statsdData = new StatsdData(); + $statsdData->setKey('key'); + $statsdData->setValue(-1); + $statsdData->setMetric('c'); + + $this->assertEquals($statsdData->getMessage(), 'key:-1|c'); + + } +} diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.php new file mode 100644 index 00000000..daf899aa --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Formatter/StatsDFormatterTest.php @@ -0,0 +1,169 @@ +formatBatch(array( + array( + 'level_name' => 'CRITICAL', + 'channel' => 'test', + 'message' => 'bar', + 'context' => array(), + 'datetime' => new \DateTime, + 'extra' => array(), + ), + array( + 'level_name' => 'WARNING', + 'channel' => 'log', + 'message' => 'foo', + 'context' => array(), + 'datetime' => new \DateTime, + 'extra' => array(), + ), + )); + + $this->assertEquals(array('test.CRITICAL.bar', 'log.WARNING.foo'), $message); + } + + public function testDefFormatWithString() + { + $formatter = new StatsDFormatter(StatsDFormatter::SIMPLE_FORMAT); + $message = $formatter->format(array( + 'level_name' => 'WARNING', + 'channel' => 'log', + 'context' => array(), + 'message' => 'foo', + 'datetime' => new \DateTime, + 'extra' => array(), + )); + $this->assertEquals(array('log.WARNING.foo'), $message); + } + + public function testDefFormatWithArrayContext() + { + $formatter = new StatsDFormatter(); + $message = $formatter->format(array( + 'level_name' => 'ERROR', + 'channel' => 'meh', + 'message' => 'foo', + 'datetime' => new \DateTime, + 'extra' => array(), + 'context' => array( + 'foo' => 'bar', + 'baz' => 'qux', + ) + )); + + $assert = array('meh.ERROR.foo', + 'meh.ERROR.foo.context.foo.bar', + 'meh.ERROR.foo.context.baz.qux'); + + $this->assertEquals($assert, $message); + } + + public function testDefFormatWithArrayContextAndExtra() + { + $formatter = new StatsDFormatter(); + $message = $formatter->format(array( + 'level_name' => 'ERROR', + 'channel' => 'meh', + 'message' => 'foo', + 'datetime' => new \DateTime, + 'extra' => array('extra'=>'woow'), + 'context' => array( + 'foo' => 'bar', + 'baz' => 'qux', + ) + )); + + $assert = array('meh.ERROR.foo', + 'meh.ERROR.foo.context.foo.bar', + 'meh.ERROR.foo.context.baz.qux', + 'meh.ERROR.foo.extra.extra.woow'); + + $this->assertEquals($assert, $message); + + } + + public function testDefLongFormat() + { + $formatter = new StatsDFormatter(); + $message = $formatter->format(array( + 'level_name' => 'DEBUG', + 'channel' => 'doctrine', + 'message' => 'INSERT INTO viaggio_calendar (enable, viaggio_id, calendar_id) VALUES (?, ?, ?)', + 'datetime' => new \DateTime, + 'extra' => array(), + 'context' => array( + 'foo' => 'bar', + 'baz' => 'qux', + ) + )); + $this->assertEquals(array("doctrine.DEBUG.INSERT-INTO", + "doctrine.DEBUG.INSERT-INTO.context.foo.bar", + "doctrine.DEBUG.INSERT-INTO.context.baz.qux"), $message); + } + + public function testDefLongFormatWith3WordsNoContextAndNoExtra() + { + $formatter = new StatsDFormatter(null, false, false, 3); + $message = $formatter->format(array( + 'level_name' => 'DEBUG', + 'channel' => 'doctrine', + 'message' => 'INSERT INTO viaggio_calendar (enable, viaggio_id, calendar_id) VALUES (?, ?, ?)', + 'datetime' => new \DateTime, + 'extra' => array(), + 'context' => array( + 'foo' => 'bar', + 'baz' => 'qux', + ) + )); + $this->assertEquals(array("doctrine.DEBUG.INSERT-INTO-viaggio-calendar"), $message); + } + public function testDefRouteException() + { + $formatter = new StatsDFormatter(); + $message = $formatter->format(array( + 'level_name' => 'DEBUG', + 'channel' => 'doctrine', + 'message' => 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /ddd" (uncaught exception) at /xxxx/classes.php line 5062', + 'datetime' => new \DateTime, + 'extra' => array(), + )); + $this->assertEquals(array('doctrine.DEBUG.Symfony-Component-HttpKernel-Exception-NotFoundHttpException--No'), $message); + } + + public function testDefKernelException() + { + $formatter = new StatsDFormatter(); + $message = $formatter->format(array( + 'level_name' => 'DEBUG', + 'channel' => 'doctrine', + 'message' => 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException"', + 'datetime' => new \DateTime, + 'extra' => array(), + 'context' => array( + 'foo' => 'bar', + 'baz' => 'qux', + ) + )); + + $assert = array('doctrine.DEBUG.Notified-event', + 'doctrine.DEBUG.Notified-event.context.foo.bar', + 'doctrine.DEBUG.Notified-event.context.baz.qux'); + + $this->assertEquals($assert, $message); + + + } +} diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Handler/StatsDHandlerTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Handler/StatsDHandlerTest.php new file mode 100644 index 00000000..c1b8eb4b --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/Monolog/Handler/StatsDHandlerTest.php @@ -0,0 +1,89 @@ + $message, + 'context' => $context, + 'level' => $level, + 'level_name' => Logger::getLevelName($level), + 'channel' => 'test', + 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))), + 'extra' => array(), + ); + } + + /** + * @return array + */ + protected function getMultipleRecords() + { + return array( + $this->getRecord(Logger::DEBUG, 'debug message 1'), + $this->getRecord(Logger::DEBUG, 'debug message 2'), + $this->getRecord(Logger::INFO, 'information'), + $this->getRecord(Logger::WARNING, 'warning'), + $this->getRecord(Logger::ERROR, 'error') + ); + } + + /** + * @return Monolog\Formatter\FormatterInterface + */ + protected function getIdentityFormatter() + { + $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); + $formatter->expects($this->any()) + ->method('format') + ->will($this->returnCallback(function($record) { return $record['message']; })); + + return $formatter; + } + + + protected function setup() + { + if (!interface_exists('Liuggio\StatsdClient\StatsdClientInterface')) { + $this->markTestSkipped('The "liuggio/statsd-php-client" package is not installed'); + } + } + + public function testHandle() + { + $client = $this->getMock('Liuggio\StatsdClient\StatsdClientInterface'); + $factory = $this->getMock('Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface'); + + $factory->expects($this->any()) + ->method('increment') + ->will($this->returnCallback(function ($input){ + return sprintf('%s|c|1', $input); + })); + + $prefixToAssert = 'prefix'; + $messageToAssert = 'test-msg'; + + $record = $this->getRecord(Logger::WARNING, $messageToAssert, array('data' => new \stdClass, 'foo' => 34)); + + $assert = array(sprintf('%s.test.WARNING.%s|c|1',$prefixToAssert, $messageToAssert), + sprintf('%s.test.WARNING.%s.context.data.[object] (stdClass: {})|c|1',$prefixToAssert, $messageToAssert), + sprintf('%s.test.WARNING.%s.context.foo.34|c|1',$prefixToAssert, $messageToAssert)); + + $client->expects($this->once()) + ->method('send') + ->with($assert); + + $handler = new StatsDHandler($client, $factory, $prefixToAssert); + $handler->handle($record); + } +} \ No newline at end of file diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php new file mode 100644 index 00000000..4608a601 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/ReadmeTest.php @@ -0,0 +1,72 @@ +mockSender(); + // $sender = new Sender(); + + // StatsdClient(SenderInterface $sender, $host = 'udp://localhost', $port = 8126, $reducePacket = true, $fail_silently = true) + $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); + } + + + + public function testFullUsageArray() { + + $sender = $this->mockSender(); + // $sender = new Sender(); + + // StatsdClient(SenderInterface $sender, $host = 'localhost', $port = 8126, $protocol='udp', $reducePacket = true, $fail_silently = true) + $client = new StatsdClient($sender, $host = 'localhost', $port = 8126, 'udp', $reducePacket = true, $fail_silently = true); + + $data[] ="increment:1|c"; + $data[] ="set:value|s"; + $data[] ="gauge:value|g"; + $data[] = "timing:10|ms"; + $data[] = "decrement:-1|c"; + $data[] ="key:1|c"; + + // send the data as array or directly as object + $client->send($data); + } + + + private function mockSender() { + $sender = $this->getMock('\Liuggio\StatsdClient\Sender\SenderInterface', array('open', 'write', 'close')); + $sender->expects($this->once()) + ->method('open') + ->will($this->returnValue(true)); + + $sender->expects($this->any()) //If you set the reduce = true into the StatsdClient the write will be called once + ->method('write') + ->will($this->returnCallBack(function($fp, $message) { + // echo PHP_EOL . "- " . $message; + })); + + $sender->expects($this->once()) + ->method('close') + ->will($this->returnValue(true)); + + return $sender; + } +} \ No newline at end of file diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdClientTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdClientTest.php new file mode 100644 index 00000000..865f1b2d --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdClientTest.php @@ -0,0 +1,228 @@ +getMockBuilder('\Liuggio\StatsdClient\Sender\SocketSender') ->disableOriginalConstructor() ->getMock(); + + $phpUnit = $this; + $mock->expects($this->any()) + ->method('open') + ->will($this->returnValue(true)); + // if the input is an array expects a call foreach item + if (is_array($messageToAssert)) { + $index = 0; + foreach ($messageToAssert as $oneMessage) { + $index++; + $mock->expects($this->at($index)) + ->method('write') + ->will($this->returnCallBack(function($fp, $message) use ($phpUnit, $oneMessage) { + $phpUnit->assertEquals($message, $oneMessage); + })); + } + } else if (null !== $messageToAssert){ + // if the input is a string expects only once + $mock->expects($this->once()) + ->method('write') + ->will($this->returnCallBack(function($fp, $message) use ($phpUnit, $messageToAssert) { + $phpUnit->assertEquals($message, $messageToAssert); + })); + } + return $mock; + } + + public function mockStatsdClientWithAssertionOnWrite($messageToAssert) { + + $mockSender = $this->mockSenderWithAssertionOnWrite($messageToAssert); + + return new StatsdClient($mockSender, false, false); + } + + public function mockFactory() { + + $mock = $this->getMock('\Liuggio\StatsdClient\Factory\StatsdDataFactory', array('timing')); + + $statsData = new StatsdData(); + $statsData->setKey('key'); + $statsData->setValue('1'); + $statsData->setMetric('ms'); + + $phpUnit = $this; + $mock->expects($this->any()) + ->method('timing') + ->will($this->returnValue($statsData)); + + return $mock; + } + + public static function provider() + { + /** + * First + */ + $statsData0 = new StatsdData(); + $statsData0->setKey('keyTiming'); + $statsData0->setValue('1'); + $statsData0->setMetric('ms'); + /** + * Second + */ + $stats1 = array(); + $statsData1 = new StatsdData(); + $statsData1->setKey('keyTiming'); + $statsData1->setValue('1'); + $statsData1->setMetric('ms'); + $stats1[] = $statsData1; + + $statsData1 = new StatsdData(); + $statsData1->setKey('keyIncrement'); + $statsData1->setValue('1'); + $statsData1->setMetric('c'); + $stats1[] = $statsData1; + + return array( + array($statsData0, "keyTiming:1|ms"), + array($stats1, array("keyTiming:1|ms", "keyIncrement:1|c")), + ); + } + public static function providerSend() + { + return array( + array(array('gauge:value|g'), 'gauge:value|g'), + array(array("keyTiming:1|ms", "keyIncrement:1|c"), array("keyTiming:1|ms", "keyIncrement:1|c")), + ); + } + + /** + * @dataProvider provider + */ + public function testPrepareAndSend($statsdInput, $assertion) { + + $statsdMock = $this->mockStatsdClientWithAssertionOnWrite($assertion); + $statsdMock->send($statsdInput); + } + + /** + * @dataProvider providerSend + */ + public function testSend($array, $assertion) { + + $statsdMock = $this->mockStatsdClientWithAssertionOnWrite($assertion); + $statsdMock->send($array); + } + + public function testReduceCount() + { + $statsd = $this->mockStatsdClientWithAssertionOnWrite(null); + + $entity0 = new StatsdData(); + $entity0->setKey('key1'); + $entity0->setValue('1'); + $entity0->setMetric('c'); + $array0[] = $entity0; + + $entity0 = new StatsdData(); + $entity0->setKey('key2'); + $entity0->setValue('2'); + $entity0->setMetric('ms'); + $array0[] = $entity0; + + $reducedMessage = array('key1:1|c' . PHP_EOL . 'key2:2|ms'); + + $this->assertEquals($statsd->reduceCount($array0), $reducedMessage); + + } + + public function testReduceWithString() + { + $statsd = $this->mockStatsdClientWithAssertionOnWrite(null); + + $msg = 'A3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789:'; + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; + $array0[] = $msg; + + $msg = 'B3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789:'; + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; + $array0[] = $msg; + $reduced = $statsd->reduceCount($array0); + $combined = $array0[0] . PHP_EOL . $array0[1]; + $this->assertEquals($combined, $reduced[0]); + } + + + public function testReduceWithMaxUdpPacketSplitInTwoPacket() + { + $statsd = $this->mockStatsdClientWithAssertionOnWrite(null); + + $msg = 'A3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789'; //1 + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '; //2 + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '; //3 + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '; //4 + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; //500 + $array0[] = $msg; + + $msg = 'Bkey:'; + $msg .= '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789|c'; + $array0[] = $msg; + + $reduced = $statsd->reduceCount($array0); + + $this->assertEquals($array0[0], $reduced[0]); + $this->assertEquals($array0[1], $reduced[1]); + } + + + + public function testMultiplePacketsWithReducing() + { + + $msg = 'A23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789'; + $array0[] = $msg; + $array0[] = $msg; + $array0[] = $msg; + $array0[] = $msg; + $array0[] = $msg; + $array0[] = $msg; + $array0[] = $msg; + $array0[] = $msg; + + $total = count($array0) * strlen($msg); + + $reducedPacketsAssertion = (int) ceil($total / StatsdClientInterface::MAX_UDP_SIZE_STR); + + + $mockSender = $this->mockSenderWithAssertionOnWrite(); + $statsd = new StatsdClient($mockSender, true, false); + $reduced = $statsd->reduceCount($array0); + + $this->assertEquals($reducedPacketsAssertion, count($reduced)); + } + + public function testSampleRate() + { + $senderMock = $this->getMock('Liuggio\StatsdClient\Sender\SenderInterface'); + $senderMock + ->expects($this->once()) + ->method('open') + ->will($this->returnValue(true)) + ; + $senderMock + ->expects($this->once()) + ->method('write') + ->with($this->anything(), 'foo|@0.2') + ; + $client = new StatsdClient($senderMock, false, false); + + $client->send( + 'foo', + 0.2 + ); + } +} diff --git a/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php new file mode 100644 index 00000000..144f629c --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/Liuggio/StatsdClient/StatsdDataFactoryTest.php @@ -0,0 +1,97 @@ +statsDataFactory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); + } + + public function testProduceStatsdData() + { + $key = 'key'; + $value='val'; + + $obj = $this->statsDataFactory->produceStatsdData($key, $value); + $this->assertEquals($key, $obj->getKey()); + $this->assertEquals($value, $obj->getValue()); + } + + public function testTiming() + { + $key = 'key'; + $value = microtime(); + $valueFloat = (string) floatval($value); + + $obj = $this->statsDataFactory->timing($key, $value); + $this->assertEquals($key, $obj->getKey()); + $this->assertContains($valueFloat, $obj->getValue()); + $this->assertContains('ms', $obj->getMetric()); + } + + public function testProduceStatsdDataDecrement() + { + $key = 'key'; + $value = -1; + $stringValue = intval($value); + + $obj = $this->statsDataFactory->produceStatsdData($key, $value); + $this->assertEquals($key, $obj->getKey()); + $this->assertEquals($stringValue, $obj->getValue()); + $this->assertEquals('c', $obj->getMetric()); + } + + public function testGauge() + { + $key = 'key'; + $value = 1000; + $stringValue = (string) intval($value); + + $obj = $this->statsDataFactory->gauge($key, $value); + $this->assertEquals($key, $obj->getKey()); + $this->assertEquals($stringValue, $obj->getValue()); + $this->assertEquals('g', $obj->getMetric()); + } + + public function testDecrement() + { + $key = 'key'; + $value = -1; + $stringValue = intval($value); + + $obj = $this->statsDataFactory->decrement($key); + $this->assertEquals($key, $obj->getKey()); + $this->assertEquals($stringValue, $obj->getValue()); + $this->assertEquals('c', $obj->getMetric()); + } + + public function testcreateStatsdDataIncrement() + { + $key = 'key'; + $value = 1; + $stringValue = intval($value); + + $obj = $this->statsDataFactory->increment($key); + $this->assertEquals($key, $obj->getKey()); + $this->assertEquals($stringValue, $obj->getValue()); + $this->assertEquals('c', $obj->getMetric()); + } + + public function testCreateStatsdDataUpdateCount() + { + $key = 'key'; + $value = 10; + $stringValue = intval($value); + + $obj = $this->statsDataFactory->updateCount($key, 10); + $this->assertEquals($key, $obj->getKey()); + $this->assertEquals($stringValue, $obj->getValue()); + $this->assertEquals('c', $obj->getMetric()); + } +} diff --git a/vendor/liuggio/statsd-php-client/tests/bootstrap.php b/vendor/liuggio/statsd-php-client/tests/bootstrap.php new file mode 100644 index 00000000..0594a467 --- /dev/null +++ b/vendor/liuggio/statsd-php-client/tests/bootstrap.php @@ -0,0 +1,5 @@ +add('Liuggio\\', __DIR__); \ No newline at end of file -- cgit v1.2.3-54-g00ecf