From: addshore Date: Fri, 27 Nov 2015 19:17:03 +0000 (+0100) Subject: Fix packet reduction in SamplingStatsdClient X-Git-Tag: 1.31.0-rc.0~8854^2 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=40c8a710be93e4ac1901b43c5cfb084efb5595b9;p=lhc%2Fweb%2Fwiklou.git Fix packet reduction in SamplingStatsdClient Doc block has also been changed to show that this implementation does not follow the defined interface. It also says why... Bug: T116031 Change-Id: If8cca355ae77b751486b40e56a6b3a51b1d7fe0b --- diff --git a/includes/libs/SamplingStatsdClient.php b/includes/libs/SamplingStatsdClient.php index 8abaa68625..f77b211637 100644 --- a/includes/libs/SamplingStatsdClient.php +++ b/includes/libs/SamplingStatsdClient.php @@ -49,10 +49,15 @@ 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 ) ) { @@ -74,12 +79,13 @@ 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 .. $written = 0; try { @@ -87,7 +93,7 @@ class SamplingStatsdClient extends StatsdClient { if ( !$fp ) { return; } - foreach ( $messages as $message ) { + foreach ( $data as $message ) { $written += $this->getSender()->write( $fp, $message ); } $this->getSender()->close( $fp );