mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Merge pull request #3544 from Conorbro/relabel
Added service discovery view showing labels before and after relabelling
This commit is contained in:
commit
b5c30090b9
|
@ -124,8 +124,9 @@ type scrapePool struct {
|
|||
client *http.Client
|
||||
// Targets and loops must always be synchronized to have the same
|
||||
// set of hashes.
|
||||
targets map[uint64]*Target
|
||||
loops map[uint64]loop
|
||||
targets map[uint64]*Target
|
||||
droppedTargets []*Target
|
||||
loops map[uint64]loop
|
||||
|
||||
// Constructor for new scrape loops. This is settable for testing convenience.
|
||||
newLoop func(*Target, scraper) loop
|
||||
|
@ -251,7 +252,13 @@ func (sp *scrapePool) Sync(tgs []*config.TargetGroup) {
|
|||
level.Error(sp.logger).Log("msg", "creating targets failed", "err", err)
|
||||
continue
|
||||
}
|
||||
all = append(all, targets...)
|
||||
for _, t := range targets {
|
||||
if t.Labels().Len() > 0 {
|
||||
all = append(all, t)
|
||||
} else if t.DiscoveredLabels().Len() > 0 {
|
||||
sp.droppedTargets = append(sp.droppedTargets, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
sp.sync(all)
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ func (app *timeLimitAppender) AddFast(lset labels.Labels, ref uint64, t int64, v
|
|||
|
||||
// populateLabels builds a label set from the given label set and scrape configuration.
|
||||
// It returns a label set before relabeling was applied as the second return value.
|
||||
// Returns a nil label set if the target is dropped during relabeling.
|
||||
// Returns the original discovered label set found before relabelling was applied if the target is dropped during relabeling.
|
||||
func populateLabels(lset labels.Labels, cfg *config.ScrapeConfig) (res, orig labels.Labels, err error) {
|
||||
// Copy labels into the labelset for the target if they are not set already.
|
||||
scrapeLabels := []labels.Label{
|
||||
|
@ -278,7 +278,7 @@ func populateLabels(lset labels.Labels, cfg *config.ScrapeConfig) (res, orig lab
|
|||
|
||||
// Check if the target was dropped.
|
||||
if lset == nil {
|
||||
return nil, nil, nil
|
||||
return nil, preRelabelLabels, nil
|
||||
}
|
||||
if v := lset.Get(model.AddressLabel); v == "" {
|
||||
return nil, nil, fmt.Errorf("no address")
|
||||
|
@ -362,7 +362,7 @@ func targetsFromGroup(tg *config.TargetGroup, cfg *config.ScrapeConfig) ([]*Targ
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("instance %d in group %s: %s", i, tg, err)
|
||||
}
|
||||
if lbls != nil {
|
||||
if lbls != nil || origLabels != nil {
|
||||
targets = append(targets, NewTarget(lbls, origLabels, cfg.Params))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,6 +143,23 @@ func (tm *TargetManager) reload() {
|
|||
}
|
||||
}
|
||||
|
||||
// TargetMap returns map of active and dropped targets and their corresponding scrape config job name.
|
||||
func (tm *TargetManager) TargetMap() map[string][]*Target {
|
||||
tm.mtx.RLock()
|
||||
defer tm.mtx.RUnlock()
|
||||
|
||||
targetsMap := make(map[string][]*Target)
|
||||
for jobName, ps := range tm.targetSets {
|
||||
ps.sp.mtx.RLock()
|
||||
for _, t := range ps.sp.targets {
|
||||
targetsMap[jobName] = append(targetsMap[jobName], t)
|
||||
}
|
||||
targetsMap[jobName] = append(targetsMap[jobName], ps.sp.droppedTargets...)
|
||||
ps.sp.mtx.RUnlock()
|
||||
}
|
||||
return targetsMap
|
||||
}
|
||||
|
||||
// Targets returns the targets currently being scraped.
|
||||
func (tm *TargetManager) Targets() []*Target {
|
||||
tm.mtx.RLock()
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -49,6 +49,7 @@
|
|||
<li><a href="{{ pathPrefix }}/config">Configuration</a></li>
|
||||
<li><a href="{{ pathPrefix }}/rules">Rules</a></li>
|
||||
<li><a href="{{ pathPrefix }}/targets">Targets</a></li>
|
||||
<li><a href="{{ pathPrefix }}/service-discovery">Service Discovery</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
|
|
86
web/ui/templates/service-discovery.html
Normal file
86
web/ui/templates/service-discovery.html
Normal file
|
@ -0,0 +1,86 @@
|
|||
{{define "head"}}
|
||||
<link type="text/css" rel="stylesheet" href="{{ pathPrefix }}/static/css/targets.css?v={{ buildVersion }}">
|
||||
<script src="{{ pathPrefix }}/static/js/targets.js?v={{ buildVersion }}"></script>
|
||||
{{end}}
|
||||
|
||||
<style>
|
||||
*[id]:before {
|
||||
display: block;
|
||||
content: " ";
|
||||
margin-top: -65px;
|
||||
height: 65px;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
{{define "content"}}
|
||||
<div class="container-fluid">
|
||||
|
||||
<h1>Service Discovery</h1>
|
||||
<div class="table-container">
|
||||
<table class="table table-condensed table-bordered table-striped table-hover">
|
||||
<ul>
|
||||
{{range $i, $job := .Index}}
|
||||
<li>
|
||||
<a href="#job-{{$job}}">{{$job}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{{$targets := .Targets}}
|
||||
{{range $job := .Index}}
|
||||
|
||||
<div class="table-container">
|
||||
<h2 id="job-{{$job}}">
|
||||
{{$job}}
|
||||
<button type="button" class="targets collapsed-table btn btn-primary">show more</button>
|
||||
</h2>
|
||||
<table class="table table-condensed table-bordered table-striped table-hover" style="display:none">
|
||||
<thead class="job_details">
|
||||
<tr>
|
||||
<th>Discovered Labels</th>
|
||||
<th>Target Labels</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{{range index $targets $job}}
|
||||
<tr>
|
||||
<td class="labels">
|
||||
{{$labels := .DiscoveredLabels.Map }}
|
||||
<ul style="list-style-type:none">
|
||||
{{range $label, $value := $labels}}
|
||||
<li>
|
||||
<span class="label label-primary">{{$label}}="{{$value}}"</span>
|
||||
</li>
|
||||
{{else}}
|
||||
<li>
|
||||
<span class="label label-default">none</span>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</td>
|
||||
<td class="labels">
|
||||
{{$labels := .Labels.Map }}
|
||||
<ul style="list-style-type:none">
|
||||
{{range $label, $value := $labels}}
|
||||
<li>
|
||||
<span class="label label-primary">{{$label}}="{{$value}}"</span>
|
||||
</li>
|
||||
{{else}}
|
||||
<li>
|
||||
<span class="label label-default">Dropped</span>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
{{end}}
|
|
@ -13,7 +13,7 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
{{range $job, $pool := .TargetPools }}
|
||||
{{range $job, $pool := .TargetPools}}
|
||||
{{$healthy := numHealthy $pool}}
|
||||
{{$total := len $pool}}
|
||||
|
||||
|
|
18
web/web.go
18
web/web.go
|
@ -216,6 +216,7 @@ func New(logger log.Logger, o *Options) *Handler {
|
|||
router.Get("/rules", readyf(instrf("rules", h.rules)))
|
||||
router.Get("/targets", readyf(instrf("targets", h.targets)))
|
||||
router.Get("/version", readyf(instrf("version", h.version)))
|
||||
router.Get("/service-discovery", readyf(instrf("servicediscovery", h.serviceDiscovery)))
|
||||
|
||||
router.Get("/heap", instrf("heap", h.dumpHeap))
|
||||
|
||||
|
@ -584,6 +585,23 @@ func (h *Handler) rules(w http.ResponseWriter, r *http.Request) {
|
|||
h.executeTemplate(w, "rules.html", h.ruleManager)
|
||||
}
|
||||
|
||||
func (h *Handler) serviceDiscovery(w http.ResponseWriter, r *http.Request) {
|
||||
var index []string
|
||||
targets := h.targetManager.TargetMap()
|
||||
for job := range targets {
|
||||
index = append(index, job)
|
||||
}
|
||||
sort.Strings(index)
|
||||
scrapeConfigData := struct {
|
||||
Index []string
|
||||
Targets map[string][]*retrieval.Target
|
||||
}{
|
||||
Index: index,
|
||||
Targets: targets,
|
||||
}
|
||||
h.executeTemplate(w, "service-discovery.html", scrapeConfigData)
|
||||
}
|
||||
|
||||
func (h *Handler) targets(w http.ResponseWriter, r *http.Request) {
|
||||
// Bucket targets by job label
|
||||
tps := map[string][]*retrieval.Target{}
|
||||
|
|
Loading…
Reference in a new issue