From 8dbfa14607a5cb138df43638f06c1a938c73df84 Mon Sep 17 00:00:00 2001 From: Viren Negi Date: Mon, 5 Oct 2020 17:04:41 +0530 Subject: [PATCH] Add UserAgent to Hetzner Robot SD (#8008) Fix #8003 Signed-off-by: Viren Negi --- discovery/hetzner/robot.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/discovery/hetzner/robot.go b/discovery/hetzner/robot.go index 24ca5678e..4035d5fcf 100644 --- a/discovery/hetzner/robot.go +++ b/discovery/hetzner/robot.go @@ -29,6 +29,7 @@ import ( "github.com/pkg/errors" "github.com/prometheus/common/config" "github.com/prometheus/common/model" + "github.com/prometheus/common/version" "github.com/prometheus/prometheus/discovery/refresh" "github.com/prometheus/prometheus/discovery/targetgroup" ) @@ -39,6 +40,8 @@ const ( hetznerLabelRobotCancelled = hetznerRobotLabelPrefix + "cancelled" ) +var userAgent = fmt.Sprintf("Prometheus/%s", version.Version) + // Discovery periodically performs Hetzner Robot requests. It implements // the Discoverer interface. type robotDiscovery struct { @@ -67,7 +70,14 @@ func newRobotDiscovery(conf *SDConfig, logger log.Logger) (*robotDiscovery, erro return d, nil } func (d *robotDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { - resp, err := d.client.Get(d.endpoint + "/server") + req, err := http.NewRequest("GET", d.endpoint+"/server", nil) + if err != nil { + return nil, err + } + + req.Header.Add("User-Agent", userAgent) + + resp, err := d.client.Do(req) if err != nil { return nil, err }