X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flibs%2FSamplingStatsdClient.php;h=2e780c97287343e95fa35cd929ad08d9fe1528c7;hb=3bb9384aeefa055a6ef1a6446ad49ee1017389f1;hp=f7afdb5e1330b402c3d028828531b44f3150d771;hpb=f1a890c34cebd8744bf3a6277734275fb975575a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/SamplingStatsdClient.php b/includes/libs/SamplingStatsdClient.php index f7afdb5e13..2e780c9728 100644 --- a/includes/libs/SamplingStatsdClient.php +++ b/includes/libs/SamplingStatsdClient.php @@ -49,14 +49,19 @@ class SamplingStatsdClient extends StatsdClient { return $data; } - /** + /* + * Send the metrics over UDP * 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 ) ) { - $data = array( $data ); + $data = [ $data ]; } if ( !$data ) { return; @@ -74,20 +79,21 @@ class SamplingStatsdClient extends StatsdClient { } $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 ); } - //failures in any of this should be silently ignored if .. + + // failures in any of this should be silently ignored if .. $written = 0; try { $fp = $this->getSender()->open(); if ( !$fp ) { return; } - foreach ( $messages as $message ) { + foreach ( $data as $message ) { $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 - * @return array + * @return StatsdDataInterface[] * @throws LogicException */ protected function sampleData( $data ) { - $newData = array(); + $newData = []; $mt_rand_max = mt_getrandmax(); foreach ( $data as $item ) { $samplingRate = $item->getSampleRate();