Skip to content

Commit

Permalink
Change default user agent
Browse files Browse the repository at this point in the history
According to prometheus scrape behavior. Change default go http client user-agent
from "Go-http-client/1.1" to "{{ project_name }}/{{ version }}"
  • Loading branch information
nikosmonaut committed Dec 12, 2019
1 parent 3a08e67 commit ff2a54a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ff2a54a

Please sign in to comment.