influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.59k stars 5.56k forks source link

http access paths are not respected #2568

Closed ghost closed 7 years ago

ghost commented 7 years ago

Bug report

Relevant telegraf.conf:

[[outputs.influxdb]]
  urls = ["https://monitor.example.com/i"]

(Note the "/i".)

System info:

[T] jeff@loire1:~ $ dpkg -l | grep telegraf
ii  telegraf                        1.2.1-1                             amd64        Plugin-driven server agent for reporting metrics into InfluxDB.
[T] jeff@loire1:~ $ cat /etc/issue
Ubuntu 16.04.2 LTS \n \l

[T] jeff@loire1:~ $ 

Steps to reproduce:

Our influxdb is accessed via an nginx reverse proxy. Rather than serve on many ports, we proxy different paths. But telegraf isn't doing what we expect.

The nginx config looks like this:

server {
  listen              443 ssl;
  server_name         monitor.example.com loire1.example.com;
  ssl_certificate     /etc/ssl/localcerts/example.com.bundled.crt;
  ssl_certificate_key /etc/ssl/localcerts/example.com.key;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;

  ssl_session_timeout 10m;

  error_log /tmp/nginx.log debug;
  rewrite_log on;

  # Grafana serves internally on 3000.
  location /m/ {
    # Passing on localhost, so no need to encrypt.
    proxy_pass    http://localhost:3000/;
  }
  # Influxdb serves internally on 8086.
  location /i/ {
    # Passing on localhost, so no need to encrypt.
    proxy_pass    http://localhost:8086/;
  }
  # Anything that isn't specified above should 301 to grafana.
  location / {
    # Passing on localhost, so no need to encrypt.
    return 301 https://$host/m/$request_uri/;
  }
}

Expected behavior:

I expect telegraf to emit queries like "i/query...".

Actual behavior:

1.2.3.4 - telegraf [24/Mar/2017:14:19:50 +0000] "POST /query?db=&q=CREATE+DATABASE+%22telegraf%22 HTTP/1.1" 301 194 "-" "telegraf"
2017-03-24T14:19:50Z E! Database creation failed: unable to decode json: received status code 301 err: invalid character '<' looking for beginning of value
2017-03-24T14:19:50Z E! Error writing to output [influxdb]: Could not write to any InfluxDB server in cluster

(Note the "/query..." rather than "i/query...".)

danielnelson commented 7 years ago

We aren't going to want to attempt path merging, the url in the config is really a list of "origins" (scheme + authority).

You should still be able to get this working by listening on multiple ports, or using virtualhosts.

ghost commented 7 years ago

Fair enough, though then I'd be inclined to call it a documentation bug, since it's not clear from reading the docs that such a thing shouldn't work.

danielnelson commented 7 years ago

@JeffJellybooks You are right. I updated the docs, do they seem better now?

ghost commented 7 years ago

@danielnelson Thanks, that does indeed add clarity.