Make HTTP basic auth configurable for scrape targets.

This commit is contained in:
Fabian Reinartz 2015-05-15 12:47:50 +02:00
parent 92493603c4
commit d5aa012fd0
4 changed files with 22 additions and 3 deletions

View file

@ -182,6 +182,8 @@ type DefaultedScrapeConfig struct {
MetricsPath string `yaml:"metrics_path,omitempty"`
// The URL scheme with which to fetch metrics from targets.
Scheme string `yaml:"scheme,omitempty"`
// The HTTP basic authentication credentials for the targets.
BasicAuth *BasicAuth `yaml:"basic_auth"`
// List of labeled target groups for this job.
TargetGroups []*TargetGroup `yaml:"target_groups,omitempty"`
@ -191,7 +193,13 @@ type DefaultedScrapeConfig struct {
RelabelConfigs []*RelabelConfig `yaml:"relabel_configs,omitempty"`
}
// A labeled group of targets to scrape for a job.
// BasicAuth contains basic HTTP authentication credentials.
type BasicAuth struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}
// TargetGroup is a set of targets with a common label set.
type TargetGroup struct {
// Targets is a list of targets identified by a label set. Each target is
// uniquely identifiable in the group by its address label.

View file

@ -69,8 +69,12 @@ var expectedConf = &Config{DefaultedConfig{
ScrapeInterval: Duration(50 * time.Second),
ScrapeTimeout: Duration(5 * time.Second),
BasicAuth: &BasicAuth{
Username: "admin",
Password: "password",
},
MetricsPath: "/my_path",
Scheme: "http",
Scheme: "https",
DNSSDConfigs: []*DNSSDConfig{
{DefaultedDNSSDConfig{

View file

@ -40,11 +40,15 @@ scrape_configs:
- job_name: service-x
basic_auth:
username: admin
password: password
scrape_interval: 50s
scrape_timeout: 5s
metrics_path: /my_path
# scheme defaults to 'http'.
scheme: https
dns_sd_configs:
- refresh_interval: 15s

View file

@ -192,6 +192,9 @@ func (t *target) Update(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSe
t.url.Scheme = cfg.Scheme
t.url.Path = string(baseLabels[clientmodel.MetricsPathLabel])
if cfg.BasicAuth != nil {
t.url.User = url.UserPassword(cfg.BasicAuth.Username, cfg.BasicAuth.Password)
}
t.scrapeInterval = time.Duration(cfg.ScrapeInterval)
t.deadline = time.Duration(cfg.ScrapeTimeout)