diff --git a/retrieval/target.go b/retrieval/target.go index 772e8761a..0365d5311 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -156,6 +156,8 @@ type Target struct { sync.RWMutex // url is the URL to be scraped. Its host is immutable. url *url.URL + // Labels before any processing. + metaLabels clientmodel.LabelSet // Any base labels that are added to this target and its metrics. baseLabels clientmodel.LabelSet // What is the deadline for the HTTP or HTTPS against this endpoint. @@ -165,7 +167,7 @@ type Target struct { } // NewTarget creates a reasonably configured target for querying. -func NewTarget(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSet) *Target { +func NewTarget(cfg *config.ScrapeConfig, baseLabels, metaLabels clientmodel.LabelSet) *Target { t := &Target{ url: &url.URL{ Host: string(baseLabels[clientmodel.AddressLabel]), @@ -174,7 +176,7 @@ func NewTarget(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSet) *Targe scraperStopping: make(chan struct{}), scraperStopped: make(chan struct{}), } - t.Update(cfg, baseLabels) + t.Update(cfg, baseLabels, metaLabels) return t } @@ -185,7 +187,7 @@ func (t *Target) Status() *TargetStatus { // Update overwrites settings in the target that are derived from the job config // it belongs to. -func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSet) { +func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels, metaLabels clientmodel.LabelSet) { t.Lock() defer t.Unlock() @@ -199,6 +201,7 @@ func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSe t.deadline = time.Duration(cfg.ScrapeTimeout) t.httpClient = httputil.NewDeadlineClient(time.Duration(cfg.ScrapeTimeout)) + t.metaLabels = metaLabels t.baseLabels = clientmodel.LabelSet{} // All remaining internal labels will not be part of the label set. for name, val := range baseLabels { @@ -400,6 +403,17 @@ func (t *Target) BaseLabels() clientmodel.LabelSet { return lset } +// MetaLabels returns a copy of the target's labels before any processing. +func (t *Target) MetaLabels() clientmodel.LabelSet { + t.RLock() + defer t.RUnlock() + lset := make(clientmodel.LabelSet, len(t.metaLabels)) + for ln, lv := range t.metaLabels { + lset[ln] = lv + } + return lset +} + func recordScrapeHealth( sampleAppender storage.SampleAppender, timestamp clientmodel.Timestamp, diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index 76e1ba33c..78a8ef8cb 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -225,14 +225,14 @@ func (tm *TargetManager) updateTargetGroup(tgroup *config.TargetGroup, cfg *conf break } } - // Update the exisiting target and discard the new equivalent. + // Update the existing target and discard the new equivalent. // Otherwise start scraping the new target. if match != nil { // Updating is blocked during a scrape. We don't want those wait times // to build up. wg.Add(1) go func(t *Target) { - match.Update(cfg, t.fullLabels()) + match.Update(cfg, t.fullLabels(), t.metaLabels) wg.Done() }(tnew) newTargets[i] = match @@ -351,6 +351,8 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc return nil, fmt.Errorf("instance %d in target group %s has no address", i, tg) } + preRelabelLabels := labels + labels, err := Relabel(labels, cfg.RelabelConfigs...) if err != nil { return nil, fmt.Errorf("error while relabeling instance %d in target group %s: %s", i, tg, err) @@ -367,7 +369,7 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc delete(labels, ln) } } - tr := NewTarget(cfg, labels) + tr := NewTarget(cfg, labels, preRelabelLabels) targets = append(targets, tr) } diff --git a/web/templates/_base.html b/web/templates/_base.html index baaa8df93..dfad25342 100644 --- a/web/templates/_base.html +++ b/web/templates/_base.html @@ -4,11 +4,17 @@