mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -08:00
Merge pull request #7604 from roidelapluie/swarmsocket
Docker swarm: enable unix socket
This commit is contained in:
commit
79620c78db
|
@ -88,16 +88,12 @@ type Discovery struct {
|
|||
|
||||
// NewDiscovery returns a new Discovery which periodically refreshes its targets.
|
||||
func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
||||
var err error
|
||||
d := &Discovery{
|
||||
port: conf.Port,
|
||||
role: conf.Role,
|
||||
}
|
||||
|
||||
rt, err := config_util.NewRoundTripperFromConfig(conf.HTTPClientConfig, "dockerswarm_sd", false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// This is used in tests. In normal situations, it is set when Unmarshaling.
|
||||
if conf.url == nil {
|
||||
conf.url, err = url.Parse(conf.Host)
|
||||
|
@ -106,15 +102,29 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
|||
}
|
||||
}
|
||||
|
||||
d.client, err = client.NewClientWithOpts(
|
||||
opts := []client.Opt{
|
||||
client.WithHost(conf.Host),
|
||||
client.WithHTTPClient(&http.Client{
|
||||
Transport: rt,
|
||||
Timeout: time.Duration(conf.RefreshInterval),
|
||||
}),
|
||||
client.WithScheme(conf.url.Scheme),
|
||||
client.WithAPIVersionNegotiation(),
|
||||
)
|
||||
}
|
||||
|
||||
// There are other protocols than HTTP supported by the Docker daemon, like
|
||||
// unix, which are not supported by the HTTP client. Passing HTTP client
|
||||
// options to the Docker client makes those non-HTTP requests fail.
|
||||
if conf.url.Scheme == "http" || conf.url.Scheme == "https" {
|
||||
rt, err := config_util.NewRoundTripperFromConfig(conf.HTTPClientConfig, "dockerswarm_sd", false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts = append(opts,
|
||||
client.WithHTTPClient(&http.Client{
|
||||
Transport: rt,
|
||||
Timeout: time.Duration(conf.RefreshInterval),
|
||||
}),
|
||||
client.WithScheme(conf.url.Scheme),
|
||||
)
|
||||
}
|
||||
|
||||
d.client, err = client.NewClientWithOpts(opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error setting up docker swarm client: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue