diff --git a/retrieval/target.go b/retrieval/target.go index 8d4e063b1d..68e783e97e 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -164,6 +164,8 @@ type Target struct { metaLabels model.LabelSet // Any base labels that are added to this target and its metrics. baseLabels model.LabelSet + // Internal labels, such as scheme. + internalLabels model.LabelSet // What is the deadline for the HTTP or HTTPS against this endpoint. deadline time.Duration // The time between two scrapes. @@ -211,6 +213,11 @@ func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels, metaLabels model.L t.url.Scheme = string(baseLabels[model.SchemeLabel]) t.url.Path = string(baseLabels[model.MetricsPathLabel]) + t.internalLabels = model.LabelSet{} + t.internalLabels[model.SchemeLabel] = baseLabels[model.SchemeLabel] + t.internalLabels[model.MetricsPathLabel] = baseLabels[model.MetricsPathLabel] + t.internalLabels[model.AddressLabel] = model.LabelValue(t.url.Host) + params := url.Values{} for k, v := range cfg.Params { @@ -224,6 +231,7 @@ func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels, metaLabels model.L } else { params[string(k[len(model.ParamLabelPrefix):])] = []string{string(v)} } + t.internalLabels[model.ParamLabelPrefix+k[len(model.ParamLabelPrefix):]] = v } } t.url.RawQuery = params.Encode() @@ -561,13 +569,13 @@ func (t *Target) InstanceIdentifier() string { func (t *Target) fullLabels() model.LabelSet { t.RLock() defer t.RUnlock() - lset := make(model.LabelSet, len(t.baseLabels)+2) + lset := make(model.LabelSet, len(t.baseLabels)+len(t.internalLabels)) for ln, lv := range t.baseLabels { lset[ln] = lv } - lset[model.MetricsPathLabel] = model.LabelValue(t.url.Path) - lset[model.AddressLabel] = model.LabelValue(t.url.Host) - lset[model.SchemeLabel] = model.LabelValue(t.url.Scheme) + for k, v := range t.internalLabels { + lset[k] = v + } return lset } diff --git a/retrieval/targetmanager_test.go b/retrieval/targetmanager_test.go index f098fafd44..aa0cb188a9 100644 --- a/retrieval/targetmanager_test.go +++ b/retrieval/targetmanager_test.go @@ -287,34 +287,44 @@ func TestTargetManagerConfigUpdate(t *testing.T) { scrapeConfigs: []*config.ScrapeConfig{testJob1}, expected: map[string][]model.LabelSet{ "test_job1:static:0:0": { - {model.JobLabel: "test_job1", model.InstanceLabel: "example.org:80", "testParam": "paramValue"}, - {model.JobLabel: "test_job1", model.InstanceLabel: "example.com:80", "testParam": "paramValue"}, + {model.JobLabel: "test_job1", model.InstanceLabel: "example.org:80", "testParam": "paramValue", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.org:80", model.ParamLabelPrefix + "testParam": "paramValue"}, + {model.JobLabel: "test_job1", model.InstanceLabel: "example.com:80", "testParam": "paramValue", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.com:80", model.ParamLabelPrefix + "testParam": "paramValue"}, }, }, }, { scrapeConfigs: []*config.ScrapeConfig{testJob1}, expected: map[string][]model.LabelSet{ "test_job1:static:0:0": { - {model.JobLabel: "test_job1", model.InstanceLabel: "example.org:80", "testParam": "paramValue"}, - {model.JobLabel: "test_job1", model.InstanceLabel: "example.com:80", "testParam": "paramValue"}, + {model.JobLabel: "test_job1", model.InstanceLabel: "example.org:80", "testParam": "paramValue", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.org:80", model.ParamLabelPrefix + "testParam": "paramValue"}, + {model.JobLabel: "test_job1", model.InstanceLabel: "example.com:80", "testParam": "paramValue", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.com:80", model.ParamLabelPrefix + "testParam": "paramValue"}, }, }, }, { scrapeConfigs: []*config.ScrapeConfig{testJob1, testJob2}, expected: map[string][]model.LabelSet{ "test_job1:static:0:0": { - {model.JobLabel: "test_job1", model.InstanceLabel: "example.org:80", "testParam": "paramValue"}, - {model.JobLabel: "test_job1", model.InstanceLabel: "example.com:80", "testParam": "paramValue"}, + {model.JobLabel: "test_job1", model.InstanceLabel: "example.org:80", "testParam": "paramValue", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.org:80", model.ParamLabelPrefix + "testParam": "paramValue"}, + {model.JobLabel: "test_job1", model.InstanceLabel: "example.com:80", "testParam": "paramValue", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.com:80", model.ParamLabelPrefix + "testParam": "paramValue"}, }, "test_job2:static:0:0": { - {model.JobLabel: "test_job2", model.InstanceLabel: "example.org:8080", "foo": "bar", "new": "ox-ba"}, - {model.JobLabel: "test_job2", model.InstanceLabel: "example.com:8081", "foo": "bar", "new": "ox-ba"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "example.org:8080", "foo": "bar", "new": "ox-ba", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.org:8080"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "example.com:8081", "foo": "bar", "new": "ox-ba", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.com:8081"}, }, "test_job2:static:0:1": { - {model.JobLabel: "test_job2", model.InstanceLabel: "foo.com:1234"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "foo.com:1234", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "foo.com:1234"}, }, "test_job2:static:0:2": { - {model.JobLabel: "test_job2", model.InstanceLabel: "fixed"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "fixed", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "foo.com:1235"}, }, }, }, { @@ -324,14 +334,18 @@ func TestTargetManagerConfigUpdate(t *testing.T) { scrapeConfigs: []*config.ScrapeConfig{testJob2}, expected: map[string][]model.LabelSet{ "test_job2:static:0:0": { - {model.JobLabel: "test_job2", model.InstanceLabel: "example.org:8080", "foo": "bar", "new": "ox-ba"}, - {model.JobLabel: "test_job2", model.InstanceLabel: "example.com:8081", "foo": "bar", "new": "ox-ba"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "example.org:8080", "foo": "bar", "new": "ox-ba", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.org:8080"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "example.com:8081", "foo": "bar", "new": "ox-ba", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "example.com:8081"}, }, "test_job2:static:0:1": { - {model.JobLabel: "test_job2", model.InstanceLabel: "foo.com:1234"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "foo.com:1234", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "foo.com:1234"}, }, "test_job2:static:0:2": { - {model.JobLabel: "test_job2", model.InstanceLabel: "fixed"}, + {model.JobLabel: "test_job2", model.InstanceLabel: "fixed", + model.SchemeLabel: "", model.MetricsPathLabel: "", model.AddressLabel: "foo.com:1235"}, }, }, }, @@ -363,7 +377,7 @@ func TestTargetManagerConfigUpdate(t *testing.T) { for _, expt := range expTargets { found := false for _, actt := range actTargets { - if reflect.DeepEqual(expt, actt.BaseLabels()) { + if reflect.DeepEqual(expt, actt.fullLabels()) { found = true break }