Merge pull request #21 from corley/feature/remove-filters

Remove filters
This commit is contained in:
Gianluca Arbezzano
2015-05-19 11:01:46 +02:00
10 changed files with 1 additions and 248 deletions
+1 -50
View File
@@ -114,12 +114,7 @@ $options = [
],
"options" => [
"host" => "my.influx.domain.tld",
],
"filters" => [
"query" => [
"name" => "InfluxDB\\Filter\\ColumnsPointsFilter"
],
],
]
];
$client = \InfluxDB\ClientFactory::create($options);
@@ -187,30 +182,6 @@ array(1) {
}
```
By default data is returned as is. You can add filters in order to change a
response as you prefer, by default this library carries a common filter that
simplifies the response.
```
$client->setFilter(new ColumnsPointsFilter());
$data = $client->query("select * from hd_used");
```
With the "ColumnsPointsFilter" you get a list of dictionaries, something like:
```
[
"serie_name" => [
[
"time" => 410545635590,
"sequence_number" => 390001,
"mark" => "element",
],
]
]
```
## Database operations
You can create, list or destroy databases using dedicated methods
@@ -237,23 +208,3 @@ Corley\Benchmarks\InfluxDB\AdapterEvent
sendDataUsingHttpAdapter: [1,000 ] [0.0026700308323] [374.52751]
sendDataUsingUdpAdapter : [1,000 ] [0.0000436344147] [22,917.69026]
```
### Filters
Just what append when you apply the `ColumnsPointsFilter`
```
Corley\Benchmarks\InfluxDB\FilterEvent
Method Name Iterations Average Time Ops/second
------------------------ ------------ -------------- -------------
get10PointDirectData : [10,000 ] [0.0001383633137] [7,227.34931]
get10PointFilteredData : [10,000 ] [0.0001662570953] [6,014.78089]
get100PointDirectData : [1,000 ] [0.0002406690121] [4,155.08416]
get100PointFilteredData : [1,000 ] [0.0008374640942] [1,194.08104]
get1000PointDirectData : [100 ] [0.0011058974266] [904.24299]
get1000PointFilteredData: [100 ] [0.0074790692329] [133.70648]
```
in order to eliminate the http handshake and bandwidth overhead network
operations are completely skipped
-12
View File
@@ -6,7 +6,6 @@ use Prophecy\Argument;
use InfluxDB\Adapter\GuzzleAdapter;
use InfluxDB\Adapter\UdpAdapter;
use InfluxDB\Adapter\AdapterInterface;
use InfluxDB\Filter\FilterInterface;
use InfluxDb\Adapter\QueryableInterface;
class ClientSpec extends ObjectBehavior
@@ -84,15 +83,4 @@ class ClientSpec extends ObjectBehavior
$this->shouldThrow("\\BadMethodCallException")->duringQuery("select * from tcp.test");
}
function it_should_filter_returned_data(FilterInterface $filter, QueryableInterface $adapter)
{
$adapter->query(Argument::Any(), Argument::Any())->willReturn(null);
$filter->filter(Argument::Any())->shouldBeCalledTimes(1)->willReturn([]);
$this->setFilter($filter);
$this->setAdapter($adapter);
$this->query("select * from tcp.test")->shouldReturn([]);
}
}
@@ -1,58 +0,0 @@
<?php
namespace spec\InfluxDB\Filter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ColumnsPointsFilterSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('InfluxDB\Filter\ColumnsPointsFilter');
}
function it_is_a_valid_filter()
{
$this->shouldImplement("InfluxDb\\Filter\\FilterInterface");
}
function it_should_map_columns_with_points()
{
$response = json_decode('[{"name":"hd_used","columns":["time","sequence_number","value","host","mount","time_precision"],"points":[[1410591684,11820001,23.2,"serverA","/mnt","s"]]}]', true);
$this->filter($response)->shouldBeEqualTo([
"hd_used" => [
[
"time" => 1410591684,
"sequence_number" => 11820001,
"value" => 23.2,
"host" => "serverA",
"mount" => "/mnt",
"time_precision" => "s",
],
],
]);
}
function it_should_map_also_a_series_list()
{
$response = json_decode('[{"name":"list_series_result","columns":["time","name"],"points":[[0,"hd_used"]]}]', true);
$this->filter($response)->shouldBeEqualTo([
"list_series_result" => [
[
"time" => 0,
"name" => "hd_used",
],
],
]);
}
function it_should_reply_to_an_empty_set()
{
$response = json_decode('[]', true);
$this->filter($response)->shouldBeEqualTo([]);
}
}
-29
View File
@@ -15,31 +15,6 @@ class Client
*/
private $adapter;
/**
* @var \InfluxDB\Filter\FilterInterface
*/
private $filter;
/**
* Set filter
* @param Filter\FilterInterface $filter
* @return Client
*/
public function setFilter(Filter\FilterInterface $filter)
{
$this->filter = $filter;
return $this;
}
/**
* Get filter
* @return Filter\FilterInterface
*/
public function getFilter()
{
return $this->filter;
}
/**
* Set InfluxDB adapter
* @param Adapter\AdapterInterface
@@ -96,10 +71,6 @@ class Client
$return = $this->getAdapter()->query($query, $timePrecision);
if ($this->getFilter() instanceOf FilterInterface) {
$return = $this->getFilter()->filter($return);
}
return $return;
}
-8
View File
@@ -14,7 +14,6 @@ abstract class ClientFactory
* @param array $options
* @return Client
* @throws InvalidArgumentException If not exist adapter name
* or not find adapter
*/
public static function create(array $options)
{
@@ -24,9 +23,6 @@ abstract class ClientFactory
"options" => [],
],
"options" => [],
"filters" => [
"query" => false
],
];
$options = array_replace_recursive($defaultOptions, $options);
@@ -58,10 +54,6 @@ abstract class ClientFactory
$client = new Client();
$client->setAdapter($adapter);
if ($options["filters"]["query"]) {
$client->setFilter(new $options["filters"]["query"]["name"]);
}
return $client;
}
}
@@ -1,28 +0,0 @@
<?php
namespace InfluxDB\Filter;
/**
* This filter manipulates response
*/
class ColumnsPointsFilter implements FilterInterface
{
/**
* {@inheritDoc}
*/
public function filter($metrics)
{
$response = [];
foreach ($metrics as $metric) {
$columns = $metric["columns"];
$response[$metric["name"]] = [];
foreach ($metric["points"] as $point) {
$response[$metric["name"]][] = array_combine($columns, $point);
}
}
return $response;
}
}
-14
View File
@@ -1,14 +0,0 @@
<?php
namespace InfluxDB\Filter;
/**
* Every filter implement this interface
*/
interface FilterInterface
{
/**
* Filter metrics
* @param mixed $anything
*/
public function filter($anything);
}
-18
View File
@@ -13,16 +13,6 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase
$client = ClientFactory::create([]);
}
/**
* @group factory
*/
public function testDefaultParams()
{
$client = ClientFactory::create(["adapter" => ["name" => "InfluxDB\\Adapter\\GuzzleAdapter"]]);
$this->assertNull($client->getFilter());
}
/**
* @group factory
* @expectedException InvalidArgumentException
@@ -95,7 +85,6 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase
/**
* @group factory
* @group filters
* @dataProvider getTcpAdapters
*/
public function testCreateTcpClientWithFilter($adapter)
@@ -109,11 +98,6 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase
"username" => "user",
"password" => "pass",
],
"filters" => [
"query" => [
"name" => "InfluxDB\\Filter\\ColumnsPointsFilter",
],
],
];
$client = ClientFactory::create($options);
@@ -123,7 +107,5 @@ class ClientFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("127.0.0.1", $client->getAdapter()->getOptions()->getHost());
$this->assertEquals("user", $client->getAdapter()->getOptions()->getUsername());
$this->assertEquals("pass", $client->getAdapter()->getOptions()->getPassword());
$this->assertInstanceOf("InfluxDB\\Filter\\ColumnsPointsFilter", $client->getFilter());
}
}
-16
View File
@@ -5,7 +5,6 @@ use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter;
use InfluxDB\Options;
use InfluxDB\Adapter\UdpAdapter;
use GuzzleHttp\Client as GuzzleHttpClient;
use InfluxDB\Filter\ColumnsPointsFilter;
class ClientTest extends \PHPUnit_Framework_TestCase
{
@@ -147,21 +146,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("udp.test", $body[0]["name"]);
}
/**
* @group filter
*/
public function testColumnsPointsFilterWorksCorrectly()
{
$this->object->setFilter(new ColumnsPointsFilter());
$this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s");
$body = $this->object->query("select mark from tcp.test", "ms");
$this->assertCount(1, $body);
$this->assertEquals("element", $body["tcp.test"][0]["mark"]);
$this->assertSame(1410591552000, $body["tcp.test"][0]["time"]);
}
public function testListActiveDatabses()
{
$databases = $this->object->getDatabases();
-15
View File
@@ -110,21 +110,6 @@ class HttpAdapterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("1410591552000", $body[0]["points"][0][0]);
}
/**
* @group filter
*/
public function testColumnsPointsFilterWorksCorrectly()
{
$this->object->setFilter(new ColumnsPointsFilter());
$this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s");
$body = $this->object->query("select mark from tcp.test", "ms");
$this->assertCount(1, $body);
$this->assertEquals("element", $body["tcp.test"][0]["mark"]);
$this->assertSame(1410591552000, $body["tcp.test"][0]["time"]);
}
public function testListActiveDatabses()
{
$databases = $this->object->getDatabases();