MediaWiki REL1_27
BufferingStatsdDataFactory.php
Go to the documentation of this file.
1<?php
23use Liuggio\StatsdClient\Entity\StatsdData;
24use Liuggio\StatsdClient\Entity\StatsdDataInterface;
25use Liuggio\StatsdClient\Factory\StatsdDataFactory;
26
35class BufferingStatsdDataFactory extends StatsdDataFactory {
36 protected $buffer = [];
37
38 public function __construct( $prefix ) {
39 parent::__construct();
40 $this->prefix = $prefix;
41 }
42
53 private static function normalizeMetricKey( $key ) {
54 $key = preg_replace( '/[:.]+/', '.', $key );
55 $key = preg_replace( '/[^a-z0-9.]+/i', '_', $key );
56 $key = trim( $key, '_.' );
57 return str_replace( [ '._', '_.' ], '.', $key );
58 }
59
60 public function produceStatsdData(
61 $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT
62 ) {
63 $entity = $this->produceStatsdDataEntity();
64 if ( $key !== null ) {
65 $key = self::normalizeMetricKey( "{$this->prefix}.{$key}" );
66 $entity->setKey( $key );
67 }
68 if ( $value !== null ) {
69 $entity->setValue( $value );
70 }
71 if ( $metric !== null ) {
72 $entity->setMetric( $metric );
73 }
74 // Don't bother buffering a counter update with a delta of zero.
75 if ( !( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$value ) ) {
76 $this->buffer[] = $entity;
77 }
78 return $entity;
79 }
80
84 public function getBuffer() {
85 return $this->buffer;
86 }
87}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
A factory for application metric data.
produceStatsdData( $key, $value=1, $metric=StatsdDataInterface::STATSD_METRIC_COUNT)
static normalizeMetricKey( $key)
Normalize a metric key for StatsD.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37