MediaWiki  1.30.0
SamplingStatsdClientTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Liuggio\StatsdClient\Entity\StatsdData;
4 use Liuggio\StatsdClient\Sender\SenderInterface;
5 
6 class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase {
10  public function testSampling( $data, $sampleRate, $seed, $expectWrite ) {
11  $sender = $this->getMockBuilder( SenderInterface::class )->getMock();
12  $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) );
13  if ( $expectWrite ) {
14  $sender->expects( $this->once() )->method( 'write' )
15  ->with( $this->anything(), $this->equalTo( $data ) );
16  } else {
17  $sender->expects( $this->never() )->method( 'write' );
18  }
19  mt_srand( $seed );
20  $client = new SamplingStatsdClient( $sender );
21  $client->send( $data, $sampleRate );
22  }
23 
24  public function samplingDataProvider() {
25  $unsampled = new StatsdData();
26  $unsampled->setKey( 'foo' );
27  $unsampled->setValue( 1 );
28 
29  $sampled = new StatsdData();
30  $sampled->setKey( 'foo' );
31  $sampled->setValue( 1 );
32  $sampled->setSampleRate( '0.1' );
33 
34  return [
35  // $data, $sampleRate, $seed, $expectWrite
36  [ $unsampled, 1, 0 /*0.44*/, true ],
37  [ $sampled, 1, 0 /*0.44*/, false ],
38  [ $sampled, 1, 4 /*0.03*/, true ],
39  [ $unsampled, 0.1, 0 /*0.44*/, false ],
40  [ $sampled, 0.5, 0 /*0.44*/, false ],
41  [ $sampled, 0.5, 4 /*0.03*/, false ],
42  ];
43  }
44 
45  public function testSetSamplingRates() {
46  $matching = new StatsdData();
47  $matching->setKey( 'foo.bar' );
48  $matching->setValue( 1 );
49 
50  $nonMatching = new StatsdData();
51  $nonMatching->setKey( 'oof.bar' );
52  $nonMatching->setValue( 1 );
53 
54  $sender = $this->getMockBuilder( SenderInterface::class )->getMock();
55  $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) );
56  $sender->expects( $this->once() )->method( 'write' )->with( $this->anything(),
57  $this->equalTo( $nonMatching ) );
58 
59  $client = new SamplingStatsdClient( $sender );
60  $client->setSamplingRates( [ 'foo.*' => 0.2 ] );
61 
62  mt_srand( 0 ); // next random is 0.44
63  $client->send( $matching );
64  mt_srand( 0 );
65  $client->send( $nonMatching );
66  }
67 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
SamplingStatsdClientTest\testSetSamplingRates
testSetSamplingRates()
Definition: SamplingStatsdClientTest.php:45
SamplingStatsdClientTest
Definition: SamplingStatsdClientTest.php:6
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
SamplingStatsdClientTest\testSampling
testSampling( $data, $sampleRate, $seed, $expectWrite)
samplingDataProvider
Definition: SamplingStatsdClientTest.php:10
anything
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break anything
Definition: distributors.txt:39
SamplingStatsdClientTest\samplingDataProvider
samplingDataProvider()
Definition: SamplingStatsdClientTest.php:24
php
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:35
SamplingStatsdClient
A statsd client that applies the sampling rate to the data items before sending them.
Definition: SamplingStatsdClient.php:32
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1965
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52