From: nikosmonaut Date: Thu, 12 Dec 2019 12:01:15 +0000 (+0100) Subject: Change default user agent X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=305e88c8d6fcd6d78853a5d5c68ef8f7398a389b;p=blackbox_exporter.git Change default user agent According to prometheus scrape behavior. Change default go http client user-agent from "Go-http-client/1.1" to "{{ project_name }}/{{ version }}" Signed-off-by: nikosmonaut --- diff --git a/prober/http.go b/prober/http.go index f4abdbe..8df0d22 100644 --- a/prober/http.go +++ b/prober/http.go @@ -35,6 +35,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" pconfig "github.com/prometheus/common/config" + "github.com/prometheus/common/version" "golang.org/x/net/publicsuffix" "github.com/prometheus/blackbox_exporter/config" @@ -226,6 +227,8 @@ func (t *transport) GotFirstResponseByte() { t.current.responseStart = time.Now() } +var userAgentDefaultHeader = fmt.Sprintf("BlackBox Exporter/%s", version.Version) + func ProbeHTTP(ctx context.Context, target string, module config.Module, registry *prometheus.Registry, logger log.Logger) (success bool) { var redirects int var ( @@ -403,6 +406,10 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr request.Header.Set(key, value) } + if request.Header.Get("User-Agent") == "" { + request.Header.Set("User-Agent", userAgentDefaultHeader) + } + trace := &httptrace.ClientTrace{ DNSStart: tt.DNSStart, DNSDone: tt.DNSDone,