dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Convert Special:NewFiles to use OOUI."
[lhc/web/wiklou.git]
/
includes
/
libs
/
SamplingStatsdClient.php
diff --git
a/includes/libs/SamplingStatsdClient.php
b/includes/libs/SamplingStatsdClient.php
index
a8477c9
..
2e780c9
100644
(file)
--- a/
includes/libs/SamplingStatsdClient.php
+++ b/
includes/libs/SamplingStatsdClient.php
@@
-49,14
+49,19
@@
class SamplingStatsdClient extends StatsdClient {
return $data;
}
return $data;
}
- /**
+ /*
+ * Send the metrics over UDP
* Sample the metrics according to their sample rate and send the remaining ones.
*
* Sample the metrics according to their sample rate and send the remaining ones.
*
- * {@inheritDoc}
+ * @param StatsdDataInterface|StatsdDataInterface[] $data message(s) to sent
+ * strings are not allowed here as sampleData requires a StatsdDataInterface
+ * @param int $sampleRate
+ *
+ * @return integer the data sent in bytes
*/
public function send( $data, $sampleRate = 1 ) {
if ( !is_array( $data ) ) {
*/
public function send( $data, $sampleRate = 1 ) {
if ( !is_array( $data ) ) {
- $data =
array( $data )
;
+ $data =
[ $data ]
;
}
if ( !$data ) {
return;
}
if ( !$data ) {
return;
@@
-74,12
+79,13
@@
class SamplingStatsdClient extends StatsdClient {
}
$data = $this->sampleData( $data );
}
$data = $this->sampleData( $data );
- $
messages
= array_map( 'strval', $data );
+ $
data
= array_map( 'strval', $data );
// reduce number of packets
if ( $this->getReducePacket() ) {
$data = $this->reduceCount( $data );
}
// reduce number of packets
if ( $this->getReducePacket() ) {
$data = $this->reduceCount( $data );
}
+
// failures in any of this should be silently ignored if ..
$written = 0;
try {
// failures in any of this should be silently ignored if ..
$written = 0;
try {
@@
-87,7
+93,7
@@
class SamplingStatsdClient extends StatsdClient {
if ( !$fp ) {
return;
}
if ( !$fp ) {
return;
}
- foreach ( $
messages
as $message ) {
+ foreach ( $
data
as $message ) {
$written += $this->getSender()->write( $fp, $message );
}
$this->getSender()->close( $fp );
$written += $this->getSender()->write( $fp, $message );
}
$this->getSender()->close( $fp );
@@
-101,11
+107,11
@@
class SamplingStatsdClient extends StatsdClient {
/**
* Throw away some of the data according to the sample rate.
* @param StatsdDataInterface[] $data
/**
* Throw away some of the data according to the sample rate.
* @param StatsdDataInterface[] $data
- * @return
array
+ * @return
StatsdDataInterface[]
* @throws LogicException
*/
protected function sampleData( $data ) {
* @throws LogicException
*/
protected function sampleData( $data ) {
- $newData =
array()
;
+ $newData =
[]
;
$mt_rand_max = mt_getrandmax();
foreach ( $data as $item ) {
$samplingRate = $item->getSampleRate();
$mt_rand_max = mt_getrandmax();
foreach ( $data as $item ) {
$samplingRate = $item->getSampleRate();