mirror of https://github.com/prometheus/prometheus
Get OpenStack variables from env as fallback (#3293)
This change enables the OpenStack service discovery to read the authentication parameters from the OS_* environment variables when the identity endpoint URL is not defined in the Prometheus configuration file.pull/3211/merge
parent
e948721a0b
commit
88e4815bb7
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
|
@ -52,7 +53,15 @@ type Discovery interface {
|
|||
|
||||
// NewDiscovery returns a new OpenStackDiscovery which periodically refreshes its targets.
|
||||
func NewDiscovery(conf *config.OpenstackSDConfig, l log.Logger) (Discovery, error) {
|
||||
opts := gophercloud.AuthOptions{
|
||||
var opts gophercloud.AuthOptions
|
||||
if conf.IdentityEndpoint == "" {
|
||||
var err error
|
||||
opts, err = openstack.AuthOptionsFromEnv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
opts = gophercloud.AuthOptions{
|
||||
IdentityEndpoint: conf.IdentityEndpoint,
|
||||
Username: conf.Username,
|
||||
UserID: conf.UserID,
|
||||
|
@ -62,6 +71,7 @@ func NewDiscovery(conf *config.OpenstackSDConfig, l log.Logger) (Discovery, erro
|
|||
DomainName: conf.DomainName,
|
||||
DomainID: conf.DomainID,
|
||||
}
|
||||
}
|
||||
switch conf.Role {
|
||||
case config.OpenStackRoleHypervisor:
|
||||
hypervisor := NewHypervisorDiscovery(&opts,
|
||||
|
|
Loading…
Reference in New Issue