Unverified Commit 8dbfa146 by Viren Negi Committed by GitHub

Add UserAgent to Hetzner Robot SD (#8008)

Fix #8003
Signed-off-by: 's avatarViren Negi <meetme2meat@gmail.com>
parent 073e93c7
Pipeline #68326 failed with stages
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment