Handle timeout header being missing (#193)
authorBrian Brazil <brian.brazil@robustperception.io>
Fri, 14 Jul 2017 10:44:58 +0000 (11:44 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Jul 2017 10:44:58 +0000 (11:44 +0100)
blackbox.yml
circle.yml
main.go

index 54831c455c0062a0bf9ac9515e61eb77b2a2b520..6691f2255c6e5ef181877b3d5633d1170326154b 100644 (file)
@@ -1,16 +1,13 @@
 modules:
   http_2xx:
     prober: http
-    timeout: 5s
     http:
   http_post_2xx:
     prober: http
-    timeout: 5s
     http:
       method: POST
   tcp_connect:
     prober: tcp
-    timeout: 5s
   pop3s_banner:
     prober: tcp
     tcp:
@@ -21,13 +18,11 @@ modules:
         insecure_skip_verify: false
   ssh_banner:
     prober: tcp
-    timeout: 5s
     tcp:
       query_response:
       - expect: "^SSH-2.0-"
   irc_banner:
     prober: tcp
-    timeout: 5s
     tcp:
       query_response:
       - send: "NICK prober"
@@ -37,4 +32,3 @@ modules:
       - expect: "^:[^ ]+ 001"
   icmp:
     prober: icmp
-    timeout: 5s
index a212a3f0db4b75de7adf28340ac3f4924baf97e7..9c20ab86ee6a7a5c7cf5931d8534409d25b5ec52 100644 (file)
@@ -2,7 +2,7 @@ machine:
   environment:
     DOCKER_IMAGE_NAME: prom/blackbox-exporter
     QUAY_IMAGE_NAME: quay.io/prometheus/blackbox-exporter
-    DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.6-base
+    DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.8-base
     REPO_PATH: github.com/prometheus/blackbox_exporter
   pre:
     - sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci'
diff --git a/main.go b/main.go
index 6a9bfe944819b17f63b934f6dbb7d591d07a7369..58d72bc4456f9bd895b75d8cf228061d7d02bc95 100644 (file)
--- a/main.go
+++ b/main.go
@@ -73,7 +73,6 @@ func (sc *SafeConfig) reloadConfig(confFile string) (err error) {
 }
 
 func probeHandler(w http.ResponseWriter, r *http.Request, c *Config) {
-
        moduleName := r.URL.Query().Get("module")
        if moduleName == "" {
                moduleName = "http_2xx"
@@ -85,15 +84,14 @@ func probeHandler(w http.ResponseWriter, r *http.Request, c *Config) {
        }
 
        // If a timeout is configured via the Prometheus header, add it to the request.
-       var prometheusTimeout string
-       if r.Header["X-Prometheus-Scrape-Timeout-Seconds"] != nil {
-               prometheusTimeout = r.Header["X-Prometheus-Scrape-Timeout-Seconds"][0]
-       }
-
-       timeoutSeconds, err := strconv.ParseFloat(prometheusTimeout, 64)
-       if err != nil {
-               http.Error(w, fmt.Sprintf("Failed to parse timeout from Prometheus header: %s", err), http.StatusInternalServerError)
-               return
+       var timeoutSeconds float64
+       if v := r.Header.Get("X-Prometheus-Scrape-Timeout-Seconds"); v != "" {
+               var err error
+               timeoutSeconds, err = strconv.ParseFloat(v, 64)
+               if err != nil {
+                       http.Error(w, fmt.Sprintf("Failed to parse timeout from Prometheus header: %s", err), http.StatusInternalServerError)
+                       return
+               }
        }
        if timeoutSeconds == 0 {
                timeoutSeconds = 10
@@ -203,14 +201,14 @@ func main() {
        })
        http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                w.Write([]byte(`<html>
-                       <head><title>Blackbox Exporter</title></head>
-                       <body>
-                       <h1>Blackbox Exporter</h1>
-                       <p><a href="/probe?target=prometheus.io&module=http_2xx">Probe prometheus.io for http_2xx</a></p>
-                       <p><a href="/metrics">Metrics</a></p>
-                       <p><a href="/config">Configuration</a></p>
-                       </body>
-                       </html>`))
+    <head><title>Blackbox Exporter</title></head>
+    <body>
+    <h1>Blackbox Exporter</h1>
+    <p><a href="/probe?target=prometheus.io&module=http_2xx">Probe prometheus.io for http_2xx</a></p>
+    <p><a href="/metrics">Metrics</a></p>
+    <p><a href="/config">Configuration</a></p>
+    </body>
+    </html>`))
        })
 
        http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {