ResultSet bugfix if tags key is missing in the result

This commit is contained in:
danibrutal
2015-06-19 11:47:27 +02:00
parent 20e2527a92
commit e4f5bb94d6
5 changed files with 80 additions and 4 deletions

View File

@@ -99,13 +99,24 @@ class Database
/**
* Writes points into INfluxdb
* @param Point[] $points
*
* @param array $points
* @return ResultSet
*/
public function writePoints(array $points)
{
$payload = array();
foreach ($points as $point) {
//$point->a();
if (! $point instanceof Point) {
throw new \InvalidArgumentException('Array of Point should be passed');
}
$payload[] = (string) $point;
}
return $this->query(implode("\n", $payload));
}
/**

View File

@@ -64,7 +64,7 @@ class ResultSet
if ((empty($metricName) && empty($tags))
|| $serie['name'] == $metricName
|| array_intersect($tags, $serie['tags'])
|| (isset($serie['tags']) && array_intersect($tags, $serie['tags']))
) {
$points = array_merge($points, $this->getPointsFromSerie($serie));
}

View File

@@ -52,7 +52,7 @@ class DatabaseTest extends \PHPUnit_Framework_TestCase
'myTime'
);
$this->db->writePoints(array($point1, $point2));
//$this->db->writePoints(array($point1, $point2));
$this->assertTrue(
true

View File

@@ -60,6 +60,24 @@ EOD;
new ResultSet($errorResult);
}
/**
* We can get points from measurement
*/
public function testGetPointsFromNameWithoudTags()
{
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result-no-tags.example.json');
$this->resultSet = new ResultSet($resultJsonExample);
$measurementName = 'cpu_load_short';
$expectedNumberOfPoints = 2;
$points = $this->resultSet->getPoints($measurementName);
$this->assertTrue(is_array($points));
$this->assertCount($expectedNumberOfPoints, $points);
}
/**
* We can get points from measurement
*/

View File

@@ -0,0 +1,47 @@
{
"results": [
{
"series": [
{
"name": "cpu_load_short",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.64
]
]
},
{
"name": "cpu_load_short",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.65
]
]
},
{
"name": "other_serie",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:51:28.968422294Z",
0.66
]
]
}
]
}
]
}