From e1857cc80793ae65e8570172cddb9d9de710ba5f Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Fri, 14 Jul 2017 11:44:58 +0100 Subject: [PATCH] Handle timeout header being missing (#193) --- blackbox.yml | 6 ------ circle.yml | 2 +- main.go | 34 ++++++++++++++++------------------ 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/blackbox.yml b/blackbox.yml index 54831c4..6691f22 100644 --- a/blackbox.yml +++ b/blackbox.yml @@ -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 diff --git a/circle.yml b/circle.yml index a212a3f..9c20ab8 100644 --- a/circle.yml +++ b/circle.yml @@ -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 6a9bfe9..58d72bc 100644 --- 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(` - Blackbox Exporter - -

Blackbox Exporter

-

Probe prometheus.io for http_2xx

-

Metrics

-

Configuration

- - `)) + Blackbox Exporter + +

Blackbox Exporter

+

Probe prometheus.io for http_2xx

+

Metrics

+

Configuration

+ + `)) }) http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) { -- 2.25.1