Merge pull request #35 from corley/feature/url-prefix

Allow URL prefixes
This commit is contained in:
Walter Dal Mut
2015-06-21 17:41:38 +02:00
5 changed files with 68 additions and 4 deletions
+4
View File
@@ -13,6 +13,10 @@ before_install:
- sudo cp ./scripts/influxdb_conf.toml /etc/opt/influxdb/influxdb.conf
- travis_retry sudo service influxdb restart
- sudo service influxdb status
- sudo apt-get update
- sudo apt-get install -y nginx
- sudo cp scripts/nginx_proxy.conf /etc/nginx/conf.d/proxy.conf
- travis_retry sudo service nginx restart
before_script:
- composer selfupdate
+25
View File
@@ -0,0 +1,25 @@
server {
listen 9000 default_server;
listen [::]:9000 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /influxdb {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
rewrite ^/influxdb/?(.*) /$1 break;
proxy_pass http://localhost:8086;
proxy_redirect off;
}
}
+6 -4
View File
@@ -54,20 +54,22 @@ class GuzzleAdapter extends AdapterAbstract implements QueryableInterface
protected function getHttpSeriesEndpoint()
{
return sprintf(
"%s://%s:%d/write",
"%s://%s:%d%s/write",
$this->getOptions()->getProtocol(),
$this->getOptions()->getHost(),
$this->getOptions()->getPort()
$this->getOptions()->getPort(),
$this->getOptions()->getPrefix()
);
}
protected function getHttpQueryEndpoint($name = false)
{
$url = sprintf(
"%s://%s:%d/query",
"%s://%s:%d%s/query",
$this->getOptions()->getProtocol(),
$this->getOptions()->getHost(),
$this->getOptions()->getPort()
$this->getOptions()->getPort(),
$this->getOptions()->getPrefix()
);
return $url;
+14
View File
@@ -23,6 +23,8 @@ class Options
private $tags;
private $prefix;
public function __construct()
{
$this->setHost("localhost");
@@ -30,11 +32,23 @@ class Options
$this->setUsername("root");
$this->setPassword("root");
$this->setProtocol("http");
$this->setPrefix("");
$this->setRetentionPolicy("default");
$this->setTags([]);
}
public function getPrefix()
{
return $this->prefix;
}
public function setPrefix($prefix)
{
$this->prefix = $prefix;
return $this;
}
public function getTags()
{
return $this->tags;
+19
View File
@@ -64,6 +64,25 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]);
}
/**
* @group tcp
* @group proxy
*/
public function testGuzzleHttpApiWorksCorrectlyWithProxies()
{
$this->options->setHost("localhost");
$this->options->setPort(9000);
$this->options->setPrefix("/influxdb");
$this->object->mark("tcp.test", ["mark" => "element"]);
sleep(2);
$body = $this->object->query("select * from \"tcp.test\"");
$this->assertCount(1, $body["results"][0]["series"][0]["values"]);
$this->assertEquals("mark", $body["results"][0]["series"][0]["columns"][1]);
$this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]);
}
/**
* @group tcp
*/