Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| MetricsClientFactory | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| newMetricsClient | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\EventLogging\MetricsPlatform; |
| 4 | |
| 5 | use MediaWiki\Context\IContextSource; |
| 6 | use MediaWiki\Extension\EventLogging\EventSubmitter\EventSubmitter; |
| 7 | use MediaWiki\Extension\EventLogging\MetricsPlatform\EventSubmitter as MetricsPlatformEventSubmitter; |
| 8 | use Psr\Log\LoggerInterface; |
| 9 | use Wikimedia\MetricsPlatform\MetricsClient; |
| 10 | use Wikimedia\MetricsPlatform\StreamConfig\StreamConfigFactory; |
| 11 | |
| 12 | /** |
| 13 | * Factory for legacy Metrics Platform clients. |
| 14 | * |
| 15 | * @deprecated since 1.48 Use the Test Kitchen PHP SDK instead, via the |
| 16 | * TestKitchen.InstrumentManager service. |
| 17 | * @see https://wikitech.wikimedia.org/wiki/Test_Kitchen/SDK/PHP_SDK |
| 18 | */ |
| 19 | class MetricsClientFactory { |
| 20 | |
| 21 | /** @var ContextAttributesFactory */ |
| 22 | private $contextAttributesFactory; |
| 23 | |
| 24 | /** @var EventSubmitter */ |
| 25 | private $eventSubmitter; |
| 26 | |
| 27 | /** @var array|false */ |
| 28 | private $streamConfigs; |
| 29 | |
| 30 | /** @var LoggerInterface */ |
| 31 | private $logger; |
| 32 | |
| 33 | /** |
| 34 | * @param ContextAttributesFactory $contextAttributesFactory |
| 35 | * @param EventSubmitter $eventSubmitter |
| 36 | * @param array|false $streamConfigs |
| 37 | * @param LoggerInterface $logger |
| 38 | */ |
| 39 | public function __construct( |
| 40 | ContextAttributesFactory $contextAttributesFactory, |
| 41 | EventSubmitter $eventSubmitter, |
| 42 | $streamConfigs, |
| 43 | LoggerInterface $logger |
| 44 | ) { |
| 45 | $this->contextAttributesFactory = $contextAttributesFactory; |
| 46 | $this->eventSubmitter = $eventSubmitter; |
| 47 | $this->streamConfigs = $streamConfigs; |
| 48 | $this->logger = $logger; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Create a legacy Metrics Platform client. |
| 53 | * |
| 54 | * @param IContextSource $requestContext |
| 55 | * @return MetricsClient |
| 56 | * @deprecated since 1.48 Use the Test Kitchen PHP SDK instead, via the |
| 57 | * TestKitchen.InstrumentManager service and Instrument::send(). |
| 58 | * @see https://wikitech.wikimedia.org/wiki/Test_Kitchen/SDK/PHP_SDK |
| 59 | */ |
| 60 | public function newMetricsClient( IContextSource $requestContext ): MetricsClient { |
| 61 | $eventSubmitter = new MetricsPlatformEventSubmitter( $this->eventSubmitter ); |
| 62 | $integration = new Integration( $this->contextAttributesFactory, $requestContext ); |
| 63 | |
| 64 | // TODO: EventStreamConfig (and EventLogging to some extent) and the PHP Metrics Platform |
| 65 | // Client have representations of stream configs. Extract a single representation into a |
| 66 | // library. |
| 67 | $streamConfigs = new StreamConfigFactory( $this->streamConfigs ); |
| 68 | |
| 69 | return new MetricsClient( $eventSubmitter, $integration, $streamConfigs, $this->logger ); |
| 70 | } |
| 71 | } |