From: Brian Brazil Date: Fri, 14 Jul 2017 10:44:58 +0000 (+0100) Subject: Handle timeout header being missing (#193) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e1857cc80793ae65e8570172cddb9d9de710ba5f;p=blackbox_exporter.git Handle timeout header being missing (#193) --- 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) {