mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Update http header User-Agent
in k8s and swarm discovery. (#7614)
* discovery: update k8s and swarm user agent. Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
parent
f482c7bdd7
commit
3c5ff27959
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue