Merge pull request #557 from nikonhub/feature-change_default_http_user_agent
authorBen Kochie <superq@gmail.com>
Sat, 22 Jan 2022 19:03:14 +0000 (20:03 +0100)
committerGitHub <noreply@github.com>
Sat, 22 Jan 2022 19:03:14 +0000 (20:03 +0100)
Change default user agent

1  2 
prober/http.go

diff --cc prober/http.go
index 156feca76150548377270b3d0ca31418e46f7f13,555a10a0636fbade4682f9deedfcf82b52e7bed1..7d5adc368e1510fc058cc685b5001845e310a2a3
@@@ -33,11 -31,11 +33,12 @@@ import 
        "sync"
        "time"
  
 -      "github.com/go-kit/kit/log"
 -      "github.com/go-kit/kit/log/level"
 +      "github.com/andybalholm/brotli"
 +      "github.com/go-kit/log"
 +      "github.com/go-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"
@@@ -208,30 -226,9 +209,32 @@@ func (t *transport) GotFirstResponseByt
        defer t.mu.Unlock()
        t.current.responseStart = time.Now()
  }
 +func (t *transport) TLSHandshakeStart() {
 +      t.mu.Lock()
 +      defer t.mu.Unlock()
 +      t.current.tlsStart = time.Now()
 +}
 +func (t *transport) TLSHandshakeDone(_ tls.ConnectionState, _ error) {
 +      t.mu.Lock()
 +      defer t.mu.Unlock()
 +      t.current.tlsDone = time.Now()
 +}
 +
 +// byteCounter implements an io.ReadCloser that keeps track of the total
 +// number of bytes it has read.
 +type byteCounter struct {
 +      io.ReadCloser
 +      n int64
 +}
 +
 +func (bc *byteCounter) Read(p []byte) (int, error) {
 +      n, err := bc.ReadCloser.Read(p)
 +      bc.n += int64(n)
 +      return n, err
 +}
  
+ 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 (