Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit 09131d7

Browse files
authored
Fix regression preventing string values in set() (DataDog#122)
1 parent a5c4ab1 commit 09131d7

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/DogStatsd.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,17 @@ public function distribution($stat, $value, $sampleRate = 1.0, $tags = null)
238238
* Set
239239
*
240240
* @param string $stat The metric
241-
* @param float $value The value
241+
* @param string|float $value The value
242242
* @param float $sampleRate the rate (0-1) for sampling.
243243
* @param array|string $tags Key Value array of Tag => Value, or single tag as string
244244
* @return void
245245
**/
246246
public function set($stat, $value, $sampleRate = 1.0, $tags = null)
247247
{
248-
$value = $this->normalizeStat($value);
248+
if (!is_string($value)) {
249+
$value = $this->normalizeStat($value);
250+
}
251+
249252
$this->send(array($stat => "$value|s"), $sampleRate, $tags);
250253
}
251254

tests/UnitTests/DogStatsd/SocketsTest.php

+36-7
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,16 @@ public function testDistribution()
318318
);
319319
}
320320

321-
public function testSet()
321+
/**
322+
* @dataProvider setProvider
323+
* @param $stat
324+
* @param $value
325+
* @param $sampleRate
326+
* @param $tags
327+
* @param $expectedUdpMessage
328+
*/
329+
public function testSet($stat, $value, $sampleRate, $tags, $expectedUdpMessage)
322330
{
323-
$stat = 'some.set_metric';
324-
$value = 22239;
325-
$sampleRate = 1.0;
326-
$tags = array('little' => 'bit');
327-
$expectedUdpMessage = 'some.set_metric:22239|s|#little:bit';
328-
329331
$dog = new DogStatsd(array("disable_telemetry" => false));
330332

331333
$dog->set(
@@ -351,6 +353,33 @@ public function testSet()
351353
);
352354
}
353355

356+
public function setProvider()
357+
{
358+
return array(
359+
'integer' => array(
360+
'some.int_metric',
361+
1,
362+
1.0,
363+
array('little' => 'bit'),
364+
'some.int_metric:1|s|#little:bit'
365+
),
366+
'float' => array(
367+
'some.float_metric',
368+
3.1415926535898,
369+
1.0,
370+
array('little' => 'bit'),
371+
'some.float_metric:3.14|s|#little:bit'
372+
),
373+
'string' => array(
374+
'some.string_metric',
375+
'uniqueval',
376+
1.0,
377+
array('little' => 'bit'),
378+
'some.string_metric:uniqueval|s|#little:bit'
379+
),
380+
);
381+
}
382+
354383
/**
355384
* @dataProvider serviceCheckProvider
356385
* @param $name

0 commit comments

Comments
 (0)