From 40c8a710be93e4ac1901b43c5cfb084efb5595b9 Mon Sep 17 00:00:00 2001 From: addshore Date: Fri, 27 Nov 2015 20:17:03 +0100 Subject: [PATCH] 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 --- includes/libs/SamplingStatsdClient.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 ); -- 2.20.1