Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telegraf does not respect http(s)_proxy env variables #1588

Closed
rhruiz opened this issue Aug 5, 2016 · 14 comments · Fixed by #3212
Closed

telegraf does not respect http(s)_proxy env variables #1588

rhruiz opened this issue Aug 5, 2016 · 14 comments · Fixed by #3212
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Milestone

Comments

@rhruiz
Copy link

rhruiz commented Aug 5, 2016

Bug report

The influx http client (v2) that telegraf uses does not uses the defined http_proxy, https_proxy, no_proxy environment variables and always tries to connect directly to the endpoint configured in telegraf.conf

Relevant telegraf.conf:

None

System info:

Telegraf - Version 0.10.4.1
Linux valar0003 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u4 (2016-02-29) x86_64 GNU/Linux
Debian 8.3

Steps to reproduce:

  1. configure your influxdb http endpoint in telegraf.conf that is directly accessible by the telegraf machine
  2. set the appropriate proxy environment variable (http_proxy or https_proxy)
  3. check that metrics are not pushed to influxdb

Expected behavior:

Connections to influxdb are proxyed

Actual behavior:

Connections are either refused or blocked pending on your firewall configuration and the following is logged:

016/08/05 14:55:54 Database creation failed: Get http://influxdb.****************/query?db=&q=CREATE+DATABASE+IF+NOT+EXISTS+%22*********%22: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
2016/08/05 14:55:54 Starting Telegraf (version 1.0.0-beta1)

@sparrc
Copy link
Contributor

sparrc commented Aug 6, 2016

can you provide a link to documentation of the environment variable? is it an issue that should be opened on the influxdb repo?

@rhruiz
Copy link
Author

rhruiz commented Aug 6, 2016

The golang http itself provides some helper functions to use those variables: https://golang.org/pkg/net/http/#ProxyFromEnvironment

And I open this in the influxdb if it makes more sense

Thanks

@rhruiz
Copy link
Author

rhruiz commented Aug 15, 2016

I have created a related issue on the influx repo.

Closing this one. Thanks.

@rhruiz rhruiz closed this as completed Aug 15, 2016
@rhruiz
Copy link
Author

rhruiz commented Aug 16, 2016

Reopening as the comment on influxdata/influxdb#7157 says:

"Telegraf issues should be created in influxdata/telegraf rather than here."

@rhruiz rhruiz reopened this Aug 16, 2016
@jwilder jwilder added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Sep 1, 2016
@arcidodo
Copy link

i need this to! is there a workaround?

@dougtweedy
Copy link

Any update/workaround on this?

@csaurav
Copy link

csaurav commented Mar 6, 2017

Anywork around for this ? I am stuck here too

@loque1
Copy link

loque1 commented Mar 7, 2017

I am facing the same issue. Most corporate environments do not allow unfettered access to the internet from any server. They are tightly controlled so egress out is through a single source i.e. a web proxy. From the doc's

DefaultTransport is the default implementation of Transport and is used by DefaultClient. It establishes network connections as needed and caches them for reuse by subsequent calls. It uses HTTP proxies as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy) environment variables.

https://golang.org/pkg/net/http/#ProxyFromEnvironment

The datadog output uses the following from your code

   func (d *Datadog) Connect() error {
	if d.Apikey == "" {
		return fmt.Errorf("apikey is a required field for datadog output")
	}
	d.client = &http.Client{
		Timeout: d.Timeout.Duration,
	}
	return nil
   }

I think should be something similar to the below.

   func (d *Datadog) Connect() error {
	if d.Apikey == "" {
		return fmt.Errorf("apikey is a required field for datadog output")
	}
       if *proxy != "" {
                proxyURL, err := url.Parse(*proxy)
                if err != nil {
                        panic("Error parsing proxy URL")
                }
                transport := http.Transport{
                        Proxy:           http.ProxyURL(proxyURL)
                }
                client = http.Client{
                        Transport: &transport,
                        Timeout:  d.Timeout.Duration ,
                }

        } else {
                client = http.Client{
                    Timeout: d.Timeout.Duration,
               }
        }
	return nil
}

I think at this point as you overide the default client you need to set the transport to be proxy and provide the proxy url which should be picked up from the environment variables one of HTTP_PROXY, HTTPS_PROXY,http_proxy or https_proxy.

Does this make sense ? I am not a coder so I suggest somone look over what I am saying

@loque1
Copy link

loque1 commented Mar 8, 2017

Ok My mistake I think it is using the proxy. setting the following
HTTPS_PROXY=http://<host>:<port>
HTTP_PROXY=http://<host>:<port>
https_proxy=http://<host>:<port>
http_proxy=http://<host>:<port>
NO_PROXY=localhost,127.0.0.1,.<domain>
causes the proxy to be used for the datadog plugin at least

@Integrative
Copy link

Doesn't work for me, InfluxDB output does not respect environment proxy settings.

declare -x http_proxy="http://172.21.8.35:3128"
declare -x https_proxy="http://172.21.8.35:3128"

telegraf /etc/telegraf/telegraf.conf --debug

Post http://xxx:8086/query?db=&q=CREATE+DATABASE+%22cem%22: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
(version 1.2.1)

@csaurav
Copy link

csaurav commented Mar 13, 2017 via email

@oliven31
Copy link

Any update/workaround on this?

@jcmcken
Copy link
Contributor

jcmcken commented Oct 2, 2017

Any chance this gets into a 1.4.x release? This bug/missing feature renders the http_response input pretty useless for anything but intranet resources.

@danielnelson
Copy link
Contributor

@jcmcken The fix for this issue only added support to the InfluxDB and other output plugins, I opened a new issue for http_response: #3297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.