mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 16:43:21 +00:00
Merge pull request #776 from prometheus/relabel-debug
Web: Add pre-relabel labels to status page.
This commit is contained in:
commit
1047fcfc6e
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,17 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Prometheus Time Series Collection and Processing Server</title>
|
||||
<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/css/prometheus.css">
|
||||
|
||||
<script>var PATH_PREFIX = "{{ pathPrefix }}";</script>
|
||||
<script>
|
||||
var PATH_PREFIX = "{{ pathPrefix }}";
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
})
|
||||
</script>
|
||||
|
||||
{{template "head" .}}
|
||||
</head>
|
||||
|
@ -56,7 +56,9 @@
|
||||
</span>
|
||||
</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>
|
||||
{{if .Status.LastScrape.IsZero}}Never{{else}}{{since .Status.LastScrape}} ago{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user