Merge pull request #967 from fabric8io/relabelable-scheme

Make scheme relabelable via discovery
This commit is contained in:
Fabian Reinartz 2015-08-06 14:15:01 +02:00
commit a2d382627a
4 changed files with 10 additions and 2 deletions

View File

@ -29,6 +29,10 @@ const (
// timeseries.
MetricNameLabel LabelName = "__name__"
// SchemeLabel is the name of the label that holds the scheme on which to
// scrape a target.
SchemeLabel LabelName = "__scheme__"
// AddressLabel is the name of the label that holds the address of
// a scrape target.
AddressLabel LabelName = "__address__"

View File

@ -177,7 +177,8 @@ type Target struct {
func NewTarget(cfg *config.ScrapeConfig, baseLabels, metaLabels clientmodel.LabelSet) *Target {
t := &Target{
url: &url.URL{
Host: string(baseLabels[clientmodel.AddressLabel]),
Scheme: string(baseLabels[clientmodel.SchemeLabel]),
Host: string(baseLabels[clientmodel.AddressLabel]),
},
status: &TargetStatus{},
scraperStopping: make(chan struct{}),
@ -205,7 +206,7 @@ func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels, metaLabels clientm
}
t.httpClient = httpClient
t.url.Scheme = cfg.Scheme
t.url.Scheme = string(baseLabels[clientmodel.SchemeLabel])
t.url.Path = string(baseLabels[clientmodel.MetricsPathLabel])
params := url.Values{}
for k, v := range cfg.Params {
@ -510,6 +511,7 @@ func (t *Target) fullLabels() clientmodel.LabelSet {
}
lset[clientmodel.MetricsPathLabel] = clientmodel.LabelValue(t.url.Path)
lset[clientmodel.AddressLabel] = clientmodel.LabelValue(t.url.Host)
lset[clientmodel.SchemeLabel] = clientmodel.LabelValue(t.url.Scheme)
return lset
}

View File

@ -426,6 +426,7 @@ func TestURLParams(t *testing.T) {
},
},
clientmodel.LabelSet{
clientmodel.SchemeLabel: clientmodel.LabelValue(serverURL.Scheme),
clientmodel.AddressLabel: clientmodel.LabelValue(serverURL.Host),
"__param_foo": "bar",
},

View File

@ -339,6 +339,7 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc
labelsets := []clientmodel.LabelSet{
tg.Labels,
{
clientmodel.SchemeLabel: clientmodel.LabelValue(cfg.Scheme),
clientmodel.MetricsPathLabel: clientmodel.LabelValue(cfg.MetricsPath),
clientmodel.JobLabel: clientmodel.LabelValue(cfg.JobName),
},