| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace Wikimedia\Stats; |
| 22 |
|
| 23 |
use Liuggio\StatsdClient\Entity\StatsdDataInterface; |
| 24 |
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PrefixingStatsdDataFactoryProxy implements StatsdDataFactoryInterface { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
private $prefix; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private $factory; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public function __construct( |
| 48 |
StatsdDataFactoryInterface $factory, |
| 49 |
$prefix |
| 50 |
) { |
| 51 |
$this->factory = $factory; |
| 52 |
$this->prefix = rtrim( $prefix, '.' ); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
private function addPrefixToKey( $key ) { |
| 60 |
return $this->prefix . '.' . $key; |
| 61 |
} |
| 62 |
|
| 63 |
public function timing( $key, $time ) { |
| 64 |
return $this->factory->timing( $this->addPrefixToKey( $key ), $time ); |
| 65 |
} |
| 66 |
|
| 67 |
public function gauge( $key, $value ) { |
| 68 |
return $this->factory->gauge( $this->addPrefixToKey( $key ), $value ); |
| 69 |
} |
| 70 |
|
| 71 |
public function set( $key, $value ) { |
| 72 |
return $this->factory->set( $this->addPrefixToKey( $key ), $value ); |
| 73 |
} |
| 74 |
|
| 75 |
public function increment( $key ) { |
| 76 |
return $this->factory->increment( $this->addPrefixToKey( $key ) ); |
| 77 |
} |
| 78 |
|
| 79 |
public function decrement( $key ) { |
| 80 |
return $this->factory->decrement( $this->addPrefixToKey( $key ) ); |
| 81 |
} |
| 82 |
|
| 83 |
public function updateCount( $key, $delta ) { |
| 84 |
return $this->factory->updateCount( $this->addPrefixToKey( $key ), $delta ); |
| 85 |
} |
| 86 |
|
| 87 |
public function produceStatsdData( |
| 88 |
$key, |
| 89 |
$value = 1, |
| 90 |
$metric = StatsdDataInterface::STATSD_METRIC_COUNT |
| 91 |
) { |
| 92 |
return $this->factory->produceStatsdData( |
| 93 |
$this->addPrefixToKey( $key ), |
| 94 |
$value, |
| 95 |
$metric |
| 96 |
); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
class_alias( PrefixingStatsdDataFactoryProxy::class, 'PrefixingStatsdDataFactoryProxy' ); |