Skip to content
Snippets Groups Projects
Commit 8b6f3a1b authored by conorbroderick's avatar conorbroderick
Browse files

Added service discovery view showing labels before and after relabelling

parent 52c01218
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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)
 
Loading
Loading
Loading
Loading
@@ -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{
Loading
Loading
@@ -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")
Loading
Loading
@@ -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))
}
}
Loading
Loading
Loading
Loading
@@ -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()
Loading
Loading
This diff is collapsed.
Loading
Loading
@@ -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>
Loading
Loading
{{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}}
Loading
Loading
@@ -13,7 +13,7 @@
</button>
</div>
 
{{range $job, $pool := .TargetPools }}
{{range $job, $pool := .TargetPools}}
{{$healthy := numHealthy $pool}}
{{$total := len $pool}}
 
Loading
Loading
Loading
Loading
@@ -214,6 +214,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))
 
Loading
Loading
@@ -582,6 +583,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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment