Add UserAgent to Hetzner Robot SD (#8008)

Fix #8003

Signed-off-by: Viren Negi <meetme2meat@gmail.com>
This commit is contained in:
Viren Negi 2020-10-05 17:04:41 +05:30 committed by GitHub
parent 073e93c768
commit 8dbfa14607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/common/config" "github.com/prometheus/common/config"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/discovery/refresh" "github.com/prometheus/prometheus/discovery/refresh"
"github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/discovery/targetgroup"
) )
@ -39,6 +40,8 @@ const (
hetznerLabelRobotCancelled = hetznerRobotLabelPrefix + "cancelled" hetznerLabelRobotCancelled = hetznerRobotLabelPrefix + "cancelled"
) )
var userAgent = fmt.Sprintf("Prometheus/%s", version.Version)
// Discovery periodically performs Hetzner Robot requests. It implements // Discovery periodically performs Hetzner Robot requests. It implements
// the Discoverer interface. // the Discoverer interface.
type robotDiscovery struct { type robotDiscovery struct {
@ -67,7 +70,14 @@ func newRobotDiscovery(conf *SDConfig, logger log.Logger) (*robotDiscovery, erro
return d, nil return d, nil
} }
func (d *robotDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { 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 { if err != nil {
return nil, err return nil, err
} }