Merge pull request #776 from prometheus/relabel-debug

Web: Add pre-relabel labels to status page.
This commit is contained in:
Brian Brazil 2015-06-08 12:24:16 +01:00
commit 1047fcfc6e
4 changed files with 32 additions and 8 deletions

View file

@ -156,6 +156,8 @@ type Target struct {
sync.RWMutex sync.RWMutex
// url is the URL to be scraped. Its host is immutable. // url is the URL to be scraped. Its host is immutable.
url *url.URL url *url.URL
// Labels before any processing.
metaLabels clientmodel.LabelSet
// Any base labels that are added to this target and its metrics. // Any base labels that are added to this target and its metrics.
baseLabels clientmodel.LabelSet baseLabels clientmodel.LabelSet
// What is the deadline for the HTTP or HTTPS against this endpoint. // 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. // 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{ t := &Target{
url: &url.URL{ url: &url.URL{
Host: string(baseLabels[clientmodel.AddressLabel]), Host: string(baseLabels[clientmodel.AddressLabel]),
@ -174,7 +176,7 @@ func NewTarget(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSet) *Targe
scraperStopping: make(chan struct{}), scraperStopping: make(chan struct{}),
scraperStopped: make(chan struct{}), scraperStopped: make(chan struct{}),
} }
t.Update(cfg, baseLabels) t.Update(cfg, baseLabels, metaLabels)
return t return t
} }
@ -185,7 +187,7 @@ func (t *Target) Status() *TargetStatus {
// Update overwrites settings in the target that are derived from the job config // Update overwrites settings in the target that are derived from the job config
// it belongs to. // 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() t.Lock()
defer t.Unlock() defer t.Unlock()
@ -199,6 +201,7 @@ func (t *Target) Update(cfg *config.ScrapeConfig, baseLabels clientmodel.LabelSe
t.deadline = time.Duration(cfg.ScrapeTimeout) t.deadline = time.Duration(cfg.ScrapeTimeout)
t.httpClient = httputil.NewDeadlineClient(time.Duration(cfg.ScrapeTimeout)) t.httpClient = httputil.NewDeadlineClient(time.Duration(cfg.ScrapeTimeout))
t.metaLabels = metaLabels
t.baseLabels = clientmodel.LabelSet{} t.baseLabels = clientmodel.LabelSet{}
// All remaining internal labels will not be part of the label set. // All remaining internal labels will not be part of the label set.
for name, val := range baseLabels { for name, val := range baseLabels {
@ -400,6 +403,17 @@ func (t *Target) BaseLabels() clientmodel.LabelSet {
return lset 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( func recordScrapeHealth(
sampleAppender storage.SampleAppender, sampleAppender storage.SampleAppender,
timestamp clientmodel.Timestamp, timestamp clientmodel.Timestamp,

View file

@ -225,14 +225,14 @@ func (tm *TargetManager) updateTargetGroup(tgroup *config.TargetGroup, cfg *conf
break 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. // Otherwise start scraping the new target.
if match != nil { if match != nil {
// Updating is blocked during a scrape. We don't want those wait times // Updating is blocked during a scrape. We don't want those wait times
// to build up. // to build up.
wg.Add(1) wg.Add(1)
go func(t *Target) { go func(t *Target) {
match.Update(cfg, t.fullLabels()) match.Update(cfg, t.fullLabels(), t.metaLabels)
wg.Done() wg.Done()
}(tnew) }(tnew)
newTargets[i] = match 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) return nil, fmt.Errorf("instance %d in target group %s has no address", i, tg)
} }
preRelabelLabels := labels
labels, err := Relabel(labels, cfg.RelabelConfigs...) labels, err := Relabel(labels, cfg.RelabelConfigs...)
if err != nil { if err != nil {
return nil, fmt.Errorf("error while relabeling instance %d in target group %s: %s", i, tg, err) 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) delete(labels, ln)
} }
} }
tr := NewTarget(cfg, labels) tr := NewTarget(cfg, labels, preRelabelLabels)
targets = append(targets, tr) targets = append(targets, tr)
} }

View file

@ -4,11 +4,17 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Prometheus Time Series Collection and Processing Server</title> <title>Prometheus Time Series Collection and Processing Server</title>
<script src="{{ pathPrefix }}/static/vendor/js/jquery.min.js"></script> <script src="{{ pathPrefix }}/static/vendor/js/jquery.min.js"></script>
<script src="{{ pathPrefix }}/static/vendor/bootstrap-3.3.1/js/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/static/vendor/bootstrap-3.3.1/css/bootstrap.min.css"> <link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/static/vendor/bootstrap-3.3.1/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/static/css/prometheus.css"> <link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/static/css/prometheus.css">
<script>var PATH_PREFIX = "{{ pathPrefix }}";</script> <script>
var PATH_PREFIX = "{{ pathPrefix }}";
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
{{template "head" .}} {{template "head" .}}
</head> </head>

View file

@ -56,7 +56,9 @@
</span> </span>
</td> </td>
<td> <td>
{{stripLabels .BaseLabels "job" "instance"}} <a href="#" data-toggle="tooltip" title="" data-original-title="Before Relabel: {{.MetaLabels}}">
{{or (stripLabels .BaseLabels "job" "instance") "{}"}}
</a>
</td> </td>
<td> <td>
{{if .Status.LastScrape.IsZero}}Never{{else}}{{since .Status.LastScrape}} ago{{end}} {{if .Status.LastScrape.IsZero}}Never{{else}}{{since .Status.LastScrape}} ago{{end}}