Unverified Commit 3c5ff279 authored by johncming's avatar johncming Committed by GitHub
Browse files

Update http header `User-Agent` in k8s and swarm discovery. (#7614)



* discovery: update k8s and swarm user agent.

Signed-off-by: default avatarjohncming <johncming@yahoo.com>
parent f482c7bd
......@@ -24,6 +24,7 @@ import (
"github.com/go-kit/kit/log"
config_util "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"
......@@ -33,6 +34,8 @@ const (
swarmLabel = model.MetaLabelPrefix + "dockerswarm_"
)
var userAgent = fmt.Sprintf("Prometheus/%s", version.Version)
// DefaultSDConfig is the default Docker Swarm SD configuration.
var DefaultSDConfig = SDConfig{
RefreshInterval: model.Duration(60 * time.Second),
......@@ -116,6 +119,9 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
Timeout: time.Duration(conf.RefreshInterval),
}),
client.WithScheme(hostURL.Scheme),
client.WithHTTPHeaders(map[string]string{
"User-Agent": userAgent,
}),
)
}
......
......@@ -15,6 +15,7 @@ package kubernetes
import (
"context"
"fmt"
"reflect"
"strings"
"sync"
......@@ -36,6 +37,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/discovery/targetgroup"
)
......@@ -49,6 +51,8 @@ const (
)
var (
// Http header
userAgent = fmt.Sprintf("Prometheus/%s", version.Version)
// Custom events metric
eventCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
......@@ -262,7 +266,7 @@ func New(l log.Logger, conf *SDConfig) (*Discovery, error) {
}
}
kcfg.UserAgent = "Prometheus/discovery"
kcfg.UserAgent = userAgent
c, err := kubernetes.NewForConfig(kcfg)
if err != nil {
......
Supports Markdown
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