Skip to content

Commit

Permalink
Setting User-Agent header (prometheus#2447)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaoglu authored and grobie committed Feb 28, 2017
1 parent 07491c9 commit 8809735
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions retrieval/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"golang.org/x/net/context"
"golang.org/x/net/context/ctxhttp"

Expand Down Expand Up @@ -286,12 +287,15 @@ type targetScraper struct {

const acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3,*/*;q=0.1`

var userAgentHeader = fmt.Sprintf("Prometheus/%s", version.Version)

func (s *targetScraper) scrape(ctx context.Context, ts time.Time) (model.Samples, error) {
req, err := http.NewRequest("GET", s.URL().String(), nil)
if err != nil {
return nil, err
}
req.Header.Add("Accept", acceptHeader)
req.Header.Set("User-Agent", userAgentHeader)

resp, err := ctxhttp.Do(ctx, s.client, req)
if err != nil {
Expand Down

0 comments on commit 8809735

Please sign in to comment.