Skip to content

Commit

Permalink
Allow gauge() to accept floats too (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Jan 15, 2022
1 parent 979c028 commit a454a2d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
### Changed
- Supported PHP versions are now 7.4, 8.0, and 8.1
- All properties and methods now have type hints where applicable
- `gauge()` now accepts both `int` and `float` values (#56)
- `ConnectionException` message is now also propagated via `trigger_error()` (#57)
- The following methods return the `StatsDClient` interface instead of `Client`:
- `ConfigurationException::getInstance()`
Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ public function time(string $metric, $func, array $tags = []): void
* Gauges
*
* @param string $metric Metric to gauge
* @param int $value Set the value of the gauge
* @param int|float $value Set the value of the gauge
* @param array $tags A list of metric tags values
*
* @throws ConnectionException
*/
public function gauge(string $metric, int $value, array $tags = []): void
public function gauge(string $metric, $value, array $tags = []): void
{
$this->send([$metric => $value . '|g'], $tags);
}
Expand Down
4 changes: 2 additions & 2 deletions src/StatsDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public function time(string $metric, $func, array $tags = []): void;
* Gauges
*
* @param string $metric Metric to gauge
* @param int $value Set the value of the gauge
* @param int|float $value Set the value of the gauge
* @param array $tags A list of metric tags values
*
* @throws ConnectionException
*/
public function gauge(string $metric, int $value, array $tags = []): void;
public function gauge(string $metric, $value, array $tags = []): void;

/**
* Sets - count the number of unique values passed to a key
Expand Down
6 changes: 6 additions & 0 deletions tests/GaugeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ public function testGauge()
$this->client->gauge('test_metric', 456);
$this->assertEquals('test_metric:456|g', $this->client->getLastMessage());
}

public function testGaugeWithFloat()
{
$this->client->gauge('test_metric', 3.14);
$this->assertEquals('test_metric:3.14|g', $this->client->getLastMessage());
}
}

0 comments on commit a454a2d

Please sign in to comment.