Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.33% |
14 / 15 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
| PrefixingStatsdDataFactoryProxy | |
100.00% |
14 / 14 |
|
100.00% |
9 / 9 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addPrefixToKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| timing | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| gauge | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| set | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| increment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| decrement | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| updateCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| produceStatsdData | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace Wikimedia\Stats; |
| 8 | |
| 9 | use Liuggio\StatsdClient\Entity\StatsdDataInterface; |
| 10 | use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; |
| 11 | |
| 12 | /** |
| 13 | * Proxy to prefix metric keys sent to a StatsdDataFactoryInterface |
| 14 | * |
| 15 | * @deprecated since 1.44 Use StatsFactory with `setLabel()` instead |
| 16 | * |
| 17 | * For example: |
| 18 | * |
| 19 | * ``` |
| 20 | * $statsFactory |
| 21 | * ->getCounter( 'example_total' ) |
| 22 | * ->setLabel( 'wiki', WikiMap::getCurrentWikiId() ) |
| 23 | * ``` |
| 24 | * |
| 25 | * @since 1.32 |
| 26 | */ |
| 27 | class PrefixingStatsdDataFactoryProxy implements StatsdDataFactoryInterface { |
| 28 | |
| 29 | /** |
| 30 | * @var string |
| 31 | */ |
| 32 | private $prefix; |
| 33 | |
| 34 | /** |
| 35 | * @var StatsdDataFactoryInterface |
| 36 | */ |
| 37 | private $factory; |
| 38 | |
| 39 | /** |
| 40 | * @param StatsdDataFactoryInterface $factory |
| 41 | * @param string $prefix |
| 42 | */ |
| 43 | public function __construct( |
| 44 | StatsdDataFactoryInterface $factory, |
| 45 | $prefix |
| 46 | ) { |
| 47 | $this->factory = $factory; |
| 48 | $this->prefix = rtrim( $prefix, '.' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param string $key |
| 53 | * @return string |
| 54 | */ |
| 55 | private function addPrefixToKey( $key ) { |
| 56 | return $this->prefix . '.' . $key; |
| 57 | } |
| 58 | |
| 59 | /** @inheritDoc */ |
| 60 | public function timing( $key, $time ) { |
| 61 | return $this->factory->timing( $this->addPrefixToKey( $key ), $time ); |
| 62 | } |
| 63 | |
| 64 | /** @inheritDoc */ |
| 65 | public function gauge( $key, $value ) { |
| 66 | return $this->factory->gauge( $this->addPrefixToKey( $key ), $value ); |
| 67 | } |
| 68 | |
| 69 | /** @inheritDoc */ |
| 70 | public function set( $key, $value ) { |
| 71 | return $this->factory->set( $this->addPrefixToKey( $key ), $value ); |
| 72 | } |
| 73 | |
| 74 | /** @inheritDoc */ |
| 75 | public function increment( $key ) { |
| 76 | return $this->factory->increment( $this->addPrefixToKey( $key ) ); |
| 77 | } |
| 78 | |
| 79 | /** @inheritDoc */ |
| 80 | public function decrement( $key ) { |
| 81 | return $this->factory->decrement( $this->addPrefixToKey( $key ) ); |
| 82 | } |
| 83 | |
| 84 | /** @inheritDoc */ |
| 85 | public function updateCount( $key, $delta ) { |
| 86 | return $this->factory->updateCount( $this->addPrefixToKey( $key ), $delta ); |
| 87 | } |
| 88 | |
| 89 | /** @inheritDoc */ |
| 90 | public function produceStatsdData( |
| 91 | $key, |
| 92 | $value = 1, |
| 93 | $metric = StatsdDataInterface::STATSD_METRIC_COUNT |
| 94 | ) { |
| 95 | return $this->factory->produceStatsdData( |
| 96 | $this->addPrefixToKey( $key ), |
| 97 | $value, |
| 98 | $metric |
| 99 | ); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** @deprecated class alias since 1.43 */ |
| 104 | class_alias( PrefixingStatsdDataFactoryProxy::class, 'PrefixingStatsdDataFactoryProxy' ); |