mirror of https://github.com/prometheus/prometheus
ec2_sd_configs: Support profiles for configuring the ec2 service
parent
ba3fcceaa5
commit
bec6870ed4
|
@ -29,6 +29,7 @@ The following individuals have contributed code to this repository
|
||||||
* Joonas Bergius <joonas@digitalocean.com>
|
* Joonas Bergius <joonas@digitalocean.com>
|
||||||
* Joseph Wilk <joe@josephwilk.net>
|
* Joseph Wilk <joe@josephwilk.net>
|
||||||
* Julius Volz <julius.volz@gmail.com>
|
* Julius Volz <julius.volz@gmail.com>
|
||||||
|
* Kraig Amador <kraig@bigkraig.com>
|
||||||
* Laurie Malau <laurie.malau@gmail.com>
|
* Laurie Malau <laurie.malau@gmail.com>
|
||||||
* Marko Mikulicic <mkm@cesanta.com>
|
* Marko Mikulicic <mkm@cesanta.com>
|
||||||
* Matt T. Proud <matt.proud@gmail.com>
|
* Matt T. Proud <matt.proud@gmail.com>
|
||||||
|
|
|
@ -907,6 +907,7 @@ type EC2SDConfig struct {
|
||||||
Region string `yaml:"region"`
|
Region string `yaml:"region"`
|
||||||
AccessKey string `yaml:"access_key,omitempty"`
|
AccessKey string `yaml:"access_key,omitempty"`
|
||||||
SecretKey string `yaml:"secret_key,omitempty"`
|
SecretKey string `yaml:"secret_key,omitempty"`
|
||||||
|
Profile string `yaml:"profile,omitempty"`
|
||||||
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
|
RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,7 @@ var expectedConf = &Config{
|
||||||
Region: "us-east-1",
|
Region: "us-east-1",
|
||||||
AccessKey: "access",
|
AccessKey: "access",
|
||||||
SecretKey: "secret",
|
SecretKey: "secret",
|
||||||
|
Profile: "profile",
|
||||||
RefreshInterval: model.Duration(60 * time.Second),
|
RefreshInterval: model.Duration(60 * time.Second),
|
||||||
Port: 80,
|
Port: 80,
|
||||||
},
|
},
|
||||||
|
|
|
@ -143,6 +143,7 @@ scrape_configs:
|
||||||
- region: us-east-1
|
- region: us-east-1
|
||||||
access_key: access
|
access_key: access
|
||||||
secret_key: secret
|
secret_key: secret
|
||||||
|
profile: profile
|
||||||
|
|
||||||
- job_name: service-azure
|
- job_name: service-azure
|
||||||
azure_sd_configs:
|
azure_sd_configs:
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
"github.com/aws/aws-sdk-go/aws/defaults"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
@ -72,6 +72,7 @@ func init() {
|
||||||
type EC2Discovery struct {
|
type EC2Discovery struct {
|
||||||
aws *aws.Config
|
aws *aws.Config
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
|
profile string
|
||||||
port int
|
port int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,13 +80,14 @@ type EC2Discovery struct {
|
||||||
func NewEC2Discovery(conf *config.EC2SDConfig) *EC2Discovery {
|
func NewEC2Discovery(conf *config.EC2SDConfig) *EC2Discovery {
|
||||||
creds := credentials.NewStaticCredentials(conf.AccessKey, conf.SecretKey, "")
|
creds := credentials.NewStaticCredentials(conf.AccessKey, conf.SecretKey, "")
|
||||||
if conf.AccessKey == "" && conf.SecretKey == "" {
|
if conf.AccessKey == "" && conf.SecretKey == "" {
|
||||||
creds = defaults.DefaultChainCredentials
|
creds = nil
|
||||||
}
|
}
|
||||||
return &EC2Discovery{
|
return &EC2Discovery{
|
||||||
aws: &aws.Config{
|
aws: &aws.Config{
|
||||||
Region: &conf.Region,
|
Region: &conf.Region,
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
},
|
},
|
||||||
|
profile: conf.Profile,
|
||||||
interval: time.Duration(conf.RefreshInterval),
|
interval: time.Duration(conf.RefreshInterval),
|
||||||
port: conf.Port,
|
port: conf.Port,
|
||||||
}
|
}
|
||||||
|
@ -130,7 +132,15 @@ func (ed *EC2Discovery) refresh() (tg *config.TargetGroup, err error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ec2s := ec2.New(ed.aws)
|
sess, err := session.NewSessionWithOptions(session.Options{
|
||||||
|
Config: *ed.aws,
|
||||||
|
Profile: ed.profile,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not create aws session: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ec2s := ec2.New(sess)
|
||||||
tg = &config.TargetGroup{
|
tg = &config.TargetGroup{
|
||||||
Source: *ed.aws.Region,
|
Source: *ed.aws.Region,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue