app/vmselect: remove dependency on lib/promscrape from app/vmselect

This commit is contained in:
Aliaksandr Valialkin 2023-01-03 23:26:27 -08:00
parent fd175ad80b
commit 5bca3a5be2
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
9 changed files with 1341 additions and 1298 deletions

View file

@ -0,0 +1,33 @@
{% stripspace %}
// CommonHeader writes common header for /targets-like pages
{% func CommonHeader() %}
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="static/css/bootstrap.min.css" rel="stylesheet" />
{% endfunc %}
// Navbar writes navigation bar for /targets-like pages
{% func Navbar() %}
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="d-flex justify-content-between">
<a href="/" class="navbar-brand d-flex align-items-center ms-3" title="The High Performance Open Source Time Series Database &amp; Monitoring Solution ">
<svg xmlns="http://www.w3.org/2000/svg" id="VM_logo" viewBox="0 0 464.61 533.89" width="20" height="20" class="me-1"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M459.86,467.77c9,7.67,24.12,13.49,39.3,13.69v0h1.68v0c15.18-.2,30.31-6,39.3-13.69,47.43-40.45,184.65-166.24,184.65-166.24,36.84-34.27-65.64-68.28-223.95-68.47h-1.68c-158.31.19-260.79,34.2-224,68.47C275.21,301.53,412.43,427.32,459.86,467.77Z" transform="translate(-267.7 -233.05)"/><path class="cls-1" d="M540.1,535.88c-9,7.67-24.12,13.5-39.3,13.7h-1.6c-15.18-.2-30.31-6-39.3-13.7-32.81-28-148.56-132.93-192.16-172.7v60.74c0,6.67,2.55,15.52,7.09,19.68,29.64,27.18,143.94,131.8,185.07,166.88,9,7.67,24.12,13.49,39.3,13.69v0h1.6v0c15.18-.2,30.31-6,39.3-13.69,41.13-35.08,155.43-139.7,185.07-166.88,4.54-4.16,7.09-13,7.09-19.68V363.18C688.66,403,572.91,507.9,540.1,535.88Z" transform="translate(-267.7 -233.05)"/><path class="cls-1" d="M540.1,678.64c-9,7.67-24.12,13.49-39.3,13.69v0h-1.6v0c-15.18-.2-30.31-6-39.3-13.69-32.81-28-148.56-132.94-192.16-172.7v60.73c0,6.67,2.55,15.53,7.09,19.69,29.64,27.17,143.94,131.8,185.07,166.87,9,7.67,24.12,13.5,39.3,13.7h1.6c15.18-.2,30.31-6,39.3-13.7,41.13-35.07,155.43-139.7,185.07-166.87,4.54-4.16,7.09-13,7.09-19.69V505.94C688.66,545.7,572.91,650.66,540.1,678.64Z" transform="translate(-267.7 -233.05)"/></svg>
<strong>VictoriaMetrics</strong>
</a>
</div>
</div>
{% endfunc %}
// ErrorNotification writes the given err as error notification
{% func ErrorNotification(err error) %}
<div class="alert alert-danger d-flex align-items-center" role="alert">
<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Danger:">
<use xlink:href="#exclamation-triangle-fill"/></svg>
<div>
{%s err.Error() %}
</div>
</div>
{% endfunc %}
{% endstripspace %}

View file

@ -0,0 +1,127 @@
// Code generated by qtc from "components.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
// CommonHeader writes common header for /targets-like pages
//line lib/htmlcomponents/components.qtpl:4
package htmlcomponents
//line lib/htmlcomponents/components.qtpl:4
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line lib/htmlcomponents/components.qtpl:4
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line lib/htmlcomponents/components.qtpl:4
func StreamCommonHeader(qw422016 *qt422016.Writer) {
//line lib/htmlcomponents/components.qtpl:4
qw422016.N().S(`<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><link href="static/css/bootstrap.min.css" rel="stylesheet" />`)
//line lib/htmlcomponents/components.qtpl:8
}
//line lib/htmlcomponents/components.qtpl:8
func WriteCommonHeader(qq422016 qtio422016.Writer) {
//line lib/htmlcomponents/components.qtpl:8
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/htmlcomponents/components.qtpl:8
StreamCommonHeader(qw422016)
//line lib/htmlcomponents/components.qtpl:8
qt422016.ReleaseWriter(qw422016)
//line lib/htmlcomponents/components.qtpl:8
}
//line lib/htmlcomponents/components.qtpl:8
func CommonHeader() string {
//line lib/htmlcomponents/components.qtpl:8
qb422016 := qt422016.AcquireByteBuffer()
//line lib/htmlcomponents/components.qtpl:8
WriteCommonHeader(qb422016)
//line lib/htmlcomponents/components.qtpl:8
qs422016 := string(qb422016.B)
//line lib/htmlcomponents/components.qtpl:8
qt422016.ReleaseByteBuffer(qb422016)
//line lib/htmlcomponents/components.qtpl:8
return qs422016
//line lib/htmlcomponents/components.qtpl:8
}
// Navbar writes navigation bar for /targets-like pages
//line lib/htmlcomponents/components.qtpl:11
func StreamNavbar(qw422016 *qt422016.Writer) {
//line lib/htmlcomponents/components.qtpl:11
qw422016.N().S(`<div class="navbar navbar-dark bg-dark box-shadow"><div class="d-flex justify-content-between"><a href="/" class="navbar-brand d-flex align-items-center ms-3" title="The High Performance Open Source Time Series Database &amp; Monitoring Solution "><svg xmlns="http://www.w3.org/2000/svg" id="VM_logo" viewBox="0 0 464.61 533.89" width="20" height="20" class="me-1"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M459.86,467.77c9,7.67,24.12,13.49,39.3,13.69v0h1.68v0c15.18-.2,30.31-6,39.3-13.69,47.43-40.45,184.65-166.24,184.65-166.24,36.84-34.27-65.64-68.28-223.95-68.47h-1.68c-158.31.19-260.79,34.2-224,68.47C275.21,301.53,412.43,427.32,459.86,467.77Z" transform="translate(-267.7 -233.05)"/><path class="cls-1" d="M540.1,535.88c-9,7.67-24.12,13.5-39.3,13.7h-1.6c-15.18-.2-30.31-6-39.3-13.7-32.81-28-148.56-132.93-192.16-172.7v60.74c0,6.67,2.55,15.52,7.09,19.68,29.64,27.18,143.94,131.8,185.07,166.88,9,7.67,24.12,13.49,39.3,13.69v0h1.6v0c15.18-.2,30.31-6,39.3-13.69,41.13-35.08,155.43-139.7,185.07-166.88,4.54-4.16,7.09-13,7.09-19.68V363.18C688.66,403,572.91,507.9,540.1,535.88Z" transform="translate(-267.7 -233.05)"/><path class="cls-1" d="M540.1,678.64c-9,7.67-24.12,13.49-39.3,13.69v0h-1.6v0c-15.18-.2-30.31-6-39.3-13.69-32.81-28-148.56-132.94-192.16-172.7v60.73c0,6.67,2.55,15.53,7.09,19.69,29.64,27.17,143.94,131.8,185.07,166.87,9,7.67,24.12,13.5,39.3,13.7h1.6c15.18-.2,30.31-6,39.3-13.7,41.13-35.07,155.43-139.7,185.07-166.87,4.54-4.16,7.09-13,7.09-19.69V505.94C688.66,545.7,572.91,650.66,540.1,678.64Z" transform="translate(-267.7 -233.05)"/></svg><strong>VictoriaMetrics</strong></a></div></div>`)
//line lib/htmlcomponents/components.qtpl:20
}
//line lib/htmlcomponents/components.qtpl:20
func WriteNavbar(qq422016 qtio422016.Writer) {
//line lib/htmlcomponents/components.qtpl:20
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/htmlcomponents/components.qtpl:20
StreamNavbar(qw422016)
//line lib/htmlcomponents/components.qtpl:20
qt422016.ReleaseWriter(qw422016)
//line lib/htmlcomponents/components.qtpl:20
}
//line lib/htmlcomponents/components.qtpl:20
func Navbar() string {
//line lib/htmlcomponents/components.qtpl:20
qb422016 := qt422016.AcquireByteBuffer()
//line lib/htmlcomponents/components.qtpl:20
WriteNavbar(qb422016)
//line lib/htmlcomponents/components.qtpl:20
qs422016 := string(qb422016.B)
//line lib/htmlcomponents/components.qtpl:20
qt422016.ReleaseByteBuffer(qb422016)
//line lib/htmlcomponents/components.qtpl:20
return qs422016
//line lib/htmlcomponents/components.qtpl:20
}
// ErrorNotification writes the given err as error notification
//line lib/htmlcomponents/components.qtpl:23
func StreamErrorNotification(qw422016 *qt422016.Writer, err error) {
//line lib/htmlcomponents/components.qtpl:23
qw422016.N().S(`<div class="alert alert-danger d-flex align-items-center" role="alert"><svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Danger:"><use xlink:href="#exclamation-triangle-fill"/></svg><div>`)
//line lib/htmlcomponents/components.qtpl:28
qw422016.E().S(err.Error())
//line lib/htmlcomponents/components.qtpl:28
qw422016.N().S(`</div></div>`)
//line lib/htmlcomponents/components.qtpl:31
}
//line lib/htmlcomponents/components.qtpl:31
func WriteErrorNotification(qq422016 qtio422016.Writer, err error) {
//line lib/htmlcomponents/components.qtpl:31
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/htmlcomponents/components.qtpl:31
StreamErrorNotification(qw422016, err)
//line lib/htmlcomponents/components.qtpl:31
qt422016.ReleaseWriter(qw422016)
//line lib/htmlcomponents/components.qtpl:31
}
//line lib/htmlcomponents/components.qtpl:31
func ErrorNotification(err error) string {
//line lib/htmlcomponents/components.qtpl:31
qb422016 := qt422016.AcquireByteBuffer()
//line lib/htmlcomponents/components.qtpl:31
WriteErrorNotification(qb422016, err)
//line lib/htmlcomponents/components.qtpl:31
qs422016 := string(qb422016.B)
//line lib/htmlcomponents/components.qtpl:31
qt422016.ReleaseByteBuffer(qb422016)
//line lib/htmlcomponents/components.qtpl:31
return qs422016
//line lib/htmlcomponents/components.qtpl:31
}

131
lib/promrelabel/debug.go Normal file
View file

@ -0,0 +1,131 @@
package promrelabel
import (
"fmt"
"io"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
)
// WriteMetricRelabelDebug writes /metric-relabel-debug page to w with the given metric and relabelConfigs fields.
func WriteMetricRelabelDebug(w io.Writer, metric, relabelConfigs string) {
if metric == "" {
metric = "{}"
}
labels, err := promutils.NewLabelsFromString(metric)
if err != nil {
err = fmt.Errorf("cannot parse metric: %s", err)
WriteMetricRelabelDebugSteps(w, nil, metric, relabelConfigs, err)
return
}
pcs, err := ParseRelabelConfigsData([]byte(relabelConfigs))
if err != nil {
err = fmt.Errorf("cannot parse relabel configs: %s", err)
WriteMetricRelabelDebugSteps(w, nil, metric, relabelConfigs, err)
return
}
dss := newDebugRelabelSteps(pcs, labels, false)
WriteMetricRelabelDebugSteps(w, dss, metric, relabelConfigs, nil)
}
// WriteTargetRelabelDebug writes /target-relabel-debug page to w with the corresponding args.
func WriteTargetRelabelDebug(w io.Writer, targetID, metric, relabelConfigs string, err error) {
if metric == "" {
metric = "{}"
}
if targetID == "" {
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, err)
return
}
labels, err := promutils.NewLabelsFromString(metric)
if err != nil {
err = fmt.Errorf("cannot parse metric: %s", err)
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, err)
return
}
pcs, err := ParseRelabelConfigsData([]byte(relabelConfigs))
if err != nil {
err = fmt.Errorf("cannot parse relabel configs: %s", err)
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, err)
return
}
dss := newDebugRelabelSteps(pcs, labels, true)
WriteTargetRelabelDebugSteps(w, targetID, dss, metric, relabelConfigs, nil)
}
func newDebugRelabelSteps(pcs *ParsedConfigs, labels *promutils.Labels, isTargetRelabel bool) []DebugStep {
// The target relabeling below must be in sync with the code at scrapeWorkConfig.getScrapeWork if isTragetRelabeling=true
// and with the code at scrapeWork.addRowToTimeseries when isTargetRelabeling=false
// Prevent from modifying the original labels
labels = labels.Clone()
// Apply relabeling
labelsResult, dss := pcs.ApplyDebug(labels.GetLabels())
labels.Labels = labelsResult
outStr := LabelsToString(labels.GetLabels())
if isTargetRelabel {
// Add missing instance label
if labels.Get("instance") == "" {
address := labels.Get("__address__")
if address != "" {
inStr := outStr
labels.Add("instance", address)
outStr = LabelsToString(labels.GetLabels())
dss = append(dss, DebugStep{
Rule: "add missing instance label from __address__ label",
In: inStr,
Out: outStr,
})
}
}
// Remove labels with __ prefix
inStr := outStr
labels.RemoveLabelsWithDoubleUnderscorePrefix()
outStr = LabelsToString(labels.GetLabels())
if inStr != outStr {
dss = append(dss, DebugStep{
Rule: "remove labels with __ prefix",
In: inStr,
Out: outStr,
})
}
} else {
// Remove labels with __ prefix except of __name__
inStr := outStr
labels.Labels = FinalizeLabels(labels.Labels[:0], labels.Labels)
outStr = LabelsToString(labels.GetLabels())
if inStr != outStr {
dss = append(dss, DebugStep{
Rule: "remove labels with __ prefix except of __name__",
In: inStr,
Out: outStr,
})
}
}
// There is no need in labels' sorting, since LabelsToString() automatically sorts labels.
return dss
}
func getChangedLabelNames(in, out *promutils.Labels) map[string]struct{} {
inMap := in.ToMap()
outMap := out.ToMap()
changed := make(map[string]struct{})
for k, v := range outMap {
inV, ok := inMap[k]
if !ok || inV != v {
changed[k] = struct{}{}
}
}
for k, v := range inMap {
outV, ok := outMap[k]
if !ok || outV != v {
changed[k] = struct{}{}
}
}
return changed
}

View file

@ -1,25 +1,25 @@
{% import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
) %}
{% stripspace %}
{% func MetricRelabelDebugSteps(dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) %}
{% func MetricRelabelDebugSteps(dss []DebugStep, metric, relabelConfigs string, err error) %}
<!DOCTYPE html>
<html lang="en">
<head>
{%= commonHeader() %}
{%= htmlcomponents.CommonHeader() %}
<title>Metric relabel debug</title>
</head>
<body>
{%= navbar() %}
{%= htmlcomponents.Navbar() %}
<div class="container-fluid">
<a href="https://docs.victoriametrics.com/relabeling.html" target="_blank">Relabeling docs</a>{% space %}
<a href="target-relabel-debug">Target relabel debug</a>
<br>
{% if err != nil %}
{%= errorNotification(err) %}
{%= htmlcomponents.ErrorNotification(err) %}
{% endif %}
<div class="m-3">
@ -40,21 +40,21 @@
</html>
{% endfunc %}
{% func TargetRelabelDebugSteps(targetID string, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) %}
{% func TargetRelabelDebugSteps(targetID string, dss []DebugStep, metric, relabelConfigs string, err error) %}
<!DOCTYPE html>
<html lang="en">
<head>
{%= commonHeader() %}
{%= htmlcomponents.CommonHeader() %}
<title>Target relabel debug</title>
</head>
<body>
{%= navbar() %}
{%= htmlcomponents.Navbar() %}
<div class="container-fluid">
<a href="https://docs.victoriametrics.com/relabeling.html" target="_blank">Relabeling docs</a>{% space %}
<a href="metric-relabel-debug">Metric relabel debug</a>
<br/>
{% if err != nil %}
{%= errorNotification(err) %}
{%= htmlcomponents.ErrorNotification(err) %}
{% endif %}
<div class="m-3">
@ -92,7 +92,7 @@
</div>
{% endfunc %}
{% func relabelDebugSteps(dss []promrelabel.DebugStep) %}
{% func relabelDebugSteps(dss []DebugStep) %}
{% if len(dss) > 0 %}
<div class="m-3">
<b>Original labels:</b> <samp>{%= mustFormatLabels(dss[0].In) %}</samp>
@ -171,7 +171,7 @@
{% endfunc %}
{% func mustFormatLabels(s string) %}
{% code labels := promutils.MustNewLabelsFromString(s) %}
{% code labels := promutils.MustNewLabelsFromString(s) %}
{%= labelsWithHighlight(labels, nil, "") %}
{% endfunc %}

View file

@ -0,0 +1,433 @@
// Code generated by qtc from "debug.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line lib/promrelabel/debug.qtpl:1
package promrelabel
//line lib/promrelabel/debug.qtpl:1
import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
)
//line lib/promrelabel/debug.qtpl:8
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line lib/promrelabel/debug.qtpl:8
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line lib/promrelabel/debug.qtpl:8
func StreamMetricRelabelDebugSteps(qw422016 *qt422016.Writer, dss []DebugStep, metric, relabelConfigs string, err error) {
//line lib/promrelabel/debug.qtpl:8
qw422016.N().S(`<!DOCTYPE html><html lang="en"><head>`)
//line lib/promrelabel/debug.qtpl:12
htmlcomponents.StreamCommonHeader(qw422016)
//line lib/promrelabel/debug.qtpl:12
qw422016.N().S(`<title>Metric relabel debug</title></head><body>`)
//line lib/promrelabel/debug.qtpl:16
htmlcomponents.StreamNavbar(qw422016)
//line lib/promrelabel/debug.qtpl:16
qw422016.N().S(`<div class="container-fluid"><a href="https://docs.victoriametrics.com/relabeling.html" target="_blank">Relabeling docs</a>`)
//line lib/promrelabel/debug.qtpl:18
qw422016.N().S(` `)
//line lib/promrelabel/debug.qtpl:18
qw422016.N().S(`<a href="target-relabel-debug">Target relabel debug</a><br>`)
//line lib/promrelabel/debug.qtpl:21
if err != nil {
//line lib/promrelabel/debug.qtpl:22
htmlcomponents.StreamErrorNotification(qw422016, err)
//line lib/promrelabel/debug.qtpl:23
}
//line lib/promrelabel/debug.qtpl:23
qw422016.N().S(`<div class="m-3"><form method="POST">`)
//line lib/promrelabel/debug.qtpl:27
streamrelabelDebugFormInputs(qw422016, metric, relabelConfigs)
//line lib/promrelabel/debug.qtpl:27
qw422016.N().S(`<input type="submit" value="Submit" class="btn btn-primary m-1" /></form></div><div class="row"><main class="col-12">`)
//line lib/promrelabel/debug.qtpl:35
streamrelabelDebugSteps(qw422016, dss)
//line lib/promrelabel/debug.qtpl:35
qw422016.N().S(`</main></div></div></body></html>`)
//line lib/promrelabel/debug.qtpl:41
}
//line lib/promrelabel/debug.qtpl:41
func WriteMetricRelabelDebugSteps(qq422016 qtio422016.Writer, dss []DebugStep, metric, relabelConfigs string, err error) {
//line lib/promrelabel/debug.qtpl:41
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:41
StreamMetricRelabelDebugSteps(qw422016, dss, metric, relabelConfigs, err)
//line lib/promrelabel/debug.qtpl:41
qt422016.ReleaseWriter(qw422016)
//line lib/promrelabel/debug.qtpl:41
}
//line lib/promrelabel/debug.qtpl:41
func MetricRelabelDebugSteps(dss []DebugStep, metric, relabelConfigs string, err error) string {
//line lib/promrelabel/debug.qtpl:41
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:41
WriteMetricRelabelDebugSteps(qb422016, dss, metric, relabelConfigs, err)
//line lib/promrelabel/debug.qtpl:41
qs422016 := string(qb422016.B)
//line lib/promrelabel/debug.qtpl:41
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promrelabel/debug.qtpl:41
return qs422016
//line lib/promrelabel/debug.qtpl:41
}
//line lib/promrelabel/debug.qtpl:43
func StreamTargetRelabelDebugSteps(qw422016 *qt422016.Writer, targetID string, dss []DebugStep, metric, relabelConfigs string, err error) {
//line lib/promrelabel/debug.qtpl:43
qw422016.N().S(`<!DOCTYPE html><html lang="en"><head>`)
//line lib/promrelabel/debug.qtpl:47
htmlcomponents.StreamCommonHeader(qw422016)
//line lib/promrelabel/debug.qtpl:47
qw422016.N().S(`<title>Target relabel debug</title></head><body>`)
//line lib/promrelabel/debug.qtpl:51
htmlcomponents.StreamNavbar(qw422016)
//line lib/promrelabel/debug.qtpl:51
qw422016.N().S(`<div class="container-fluid"><a href="https://docs.victoriametrics.com/relabeling.html" target="_blank">Relabeling docs</a>`)
//line lib/promrelabel/debug.qtpl:53
qw422016.N().S(` `)
//line lib/promrelabel/debug.qtpl:53
qw422016.N().S(`<a href="metric-relabel-debug">Metric relabel debug</a><br/>`)
//line lib/promrelabel/debug.qtpl:56
if err != nil {
//line lib/promrelabel/debug.qtpl:57
htmlcomponents.StreamErrorNotification(qw422016, err)
//line lib/promrelabel/debug.qtpl:58
}
//line lib/promrelabel/debug.qtpl:58
qw422016.N().S(`<div class="m-3"><form method="POST">`)
//line lib/promrelabel/debug.qtpl:62
streamrelabelDebugFormInputs(qw422016, metric, relabelConfigs)
//line lib/promrelabel/debug.qtpl:62
qw422016.N().S(`<input type="hidden" name="id" value="`)
//line lib/promrelabel/debug.qtpl:64
qw422016.E().S(targetID)
//line lib/promrelabel/debug.qtpl:64
qw422016.N().S(`" /><input type="submit" value="Submit" class="btn btn-primary m-1" />`)
//line lib/promrelabel/debug.qtpl:67
if targetID != "" {
//line lib/promrelabel/debug.qtpl:67
qw422016.N().S(`<button type="button" onclick="location.href='target-relabel-debug?id=`)
//line lib/promrelabel/debug.qtpl:68
qw422016.E().S(targetID)
//line lib/promrelabel/debug.qtpl:68
qw422016.N().S(`'" class="btn btn-secondary m-1">Reset</button>`)
//line lib/promrelabel/debug.qtpl:69
}
//line lib/promrelabel/debug.qtpl:69
qw422016.N().S(`</form></div><div class="row"><main class="col-12">`)
//line lib/promrelabel/debug.qtpl:75
streamrelabelDebugSteps(qw422016, dss)
//line lib/promrelabel/debug.qtpl:75
qw422016.N().S(`</main></div></div></body></html>`)
//line lib/promrelabel/debug.qtpl:81
}
//line lib/promrelabel/debug.qtpl:81
func WriteTargetRelabelDebugSteps(qq422016 qtio422016.Writer, targetID string, dss []DebugStep, metric, relabelConfigs string, err error) {
//line lib/promrelabel/debug.qtpl:81
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:81
StreamTargetRelabelDebugSteps(qw422016, targetID, dss, metric, relabelConfigs, err)
//line lib/promrelabel/debug.qtpl:81
qt422016.ReleaseWriter(qw422016)
//line lib/promrelabel/debug.qtpl:81
}
//line lib/promrelabel/debug.qtpl:81
func TargetRelabelDebugSteps(targetID string, dss []DebugStep, metric, relabelConfigs string, err error) string {
//line lib/promrelabel/debug.qtpl:81
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:81
WriteTargetRelabelDebugSteps(qb422016, targetID, dss, metric, relabelConfigs, err)
//line lib/promrelabel/debug.qtpl:81
qs422016 := string(qb422016.B)
//line lib/promrelabel/debug.qtpl:81
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promrelabel/debug.qtpl:81
return qs422016
//line lib/promrelabel/debug.qtpl:81
}
//line lib/promrelabel/debug.qtpl:83
func streamrelabelDebugFormInputs(qw422016 *qt422016.Writer, metric, relabelConfigs string) {
//line lib/promrelabel/debug.qtpl:83
qw422016.N().S(`<div>Relabel configs:<br/><textarea name="relabel_configs" style="width: 100%; height: 15em" class="m-1">`)
//line lib/promrelabel/debug.qtpl:86
qw422016.E().S(relabelConfigs)
//line lib/promrelabel/debug.qtpl:86
qw422016.N().S(`</textarea></div><div>Labels:<br/><textarea name="metric" style="width: 100%; height: 5em" class="m-1">`)
//line lib/promrelabel/debug.qtpl:91
qw422016.E().S(metric)
//line lib/promrelabel/debug.qtpl:91
qw422016.N().S(`</textarea></div>`)
//line lib/promrelabel/debug.qtpl:93
}
//line lib/promrelabel/debug.qtpl:93
func writerelabelDebugFormInputs(qq422016 qtio422016.Writer, metric, relabelConfigs string) {
//line lib/promrelabel/debug.qtpl:93
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:93
streamrelabelDebugFormInputs(qw422016, metric, relabelConfigs)
//line lib/promrelabel/debug.qtpl:93
qt422016.ReleaseWriter(qw422016)
//line lib/promrelabel/debug.qtpl:93
}
//line lib/promrelabel/debug.qtpl:93
func relabelDebugFormInputs(metric, relabelConfigs string) string {
//line lib/promrelabel/debug.qtpl:93
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:93
writerelabelDebugFormInputs(qb422016, metric, relabelConfigs)
//line lib/promrelabel/debug.qtpl:93
qs422016 := string(qb422016.B)
//line lib/promrelabel/debug.qtpl:93
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promrelabel/debug.qtpl:93
return qs422016
//line lib/promrelabel/debug.qtpl:93
}
//line lib/promrelabel/debug.qtpl:95
func streamrelabelDebugSteps(qw422016 *qt422016.Writer, dss []DebugStep) {
//line lib/promrelabel/debug.qtpl:96
if len(dss) > 0 {
//line lib/promrelabel/debug.qtpl:96
qw422016.N().S(`<div class="m-3"><b>Original labels:</b> <samp>`)
//line lib/promrelabel/debug.qtpl:98
streammustFormatLabels(qw422016, dss[0].In)
//line lib/promrelabel/debug.qtpl:98
qw422016.N().S(`</samp></div>`)
//line lib/promrelabel/debug.qtpl:100
}
//line lib/promrelabel/debug.qtpl:100
qw422016.N().S(`<table class="table table-striped table-hover table-bordered table-sm"><thead><tr><th scope="col" style="width: 5%">Step</th><th scope="col" style="width: 25%">Relabeling Rule</th><th scope="col" style="width: 35%">Input Labels</th><th scope="col" stile="width: 35%">Output labels</a></tr></thead><tbody>`)
//line lib/promrelabel/debug.qtpl:111
for i, ds := range dss {
//line lib/promrelabel/debug.qtpl:113
inLabels := promutils.MustNewLabelsFromString(ds.In)
outLabels := promutils.MustNewLabelsFromString(ds.Out)
changedLabels := getChangedLabelNames(inLabels, outLabels)
//line lib/promrelabel/debug.qtpl:116
qw422016.N().S(`<tr><td>`)
//line lib/promrelabel/debug.qtpl:118
qw422016.N().D(i)
//line lib/promrelabel/debug.qtpl:118
qw422016.N().S(`</td><td><b><pre class="m-2">`)
//line lib/promrelabel/debug.qtpl:119
qw422016.E().S(ds.Rule)
//line lib/promrelabel/debug.qtpl:119
qw422016.N().S(`</pre></b></td><td><div class="m-2" style="font-size: 0.9em" title="deleted and updated labels highlighted in red">`)
//line lib/promrelabel/debug.qtpl:122
streamlabelsWithHighlight(qw422016, inLabels, changedLabels, "red")
//line lib/promrelabel/debug.qtpl:122
qw422016.N().S(`</div></td><td><div class="m-2" style="font-size: 0.9em" title="added and updated labels highlighted in blue">`)
//line lib/promrelabel/debug.qtpl:127
streamlabelsWithHighlight(qw422016, outLabels, changedLabels, "blue")
//line lib/promrelabel/debug.qtpl:127
qw422016.N().S(`</div></td></tr>`)
//line lib/promrelabel/debug.qtpl:131
}
//line lib/promrelabel/debug.qtpl:131
qw422016.N().S(`</tbody></table>`)
//line lib/promrelabel/debug.qtpl:134
if len(dss) > 0 {
//line lib/promrelabel/debug.qtpl:134
qw422016.N().S(`<div class="m-3"><b>Resulting labels:</b> <samp>`)
//line lib/promrelabel/debug.qtpl:136
streammustFormatLabels(qw422016, dss[len(dss)-1].Out)
//line lib/promrelabel/debug.qtpl:136
qw422016.N().S(`</samp></div>`)
//line lib/promrelabel/debug.qtpl:138
}
//line lib/promrelabel/debug.qtpl:139
}
//line lib/promrelabel/debug.qtpl:139
func writerelabelDebugSteps(qq422016 qtio422016.Writer, dss []DebugStep) {
//line lib/promrelabel/debug.qtpl:139
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:139
streamrelabelDebugSteps(qw422016, dss)
//line lib/promrelabel/debug.qtpl:139
qt422016.ReleaseWriter(qw422016)
//line lib/promrelabel/debug.qtpl:139
}
//line lib/promrelabel/debug.qtpl:139
func relabelDebugSteps(dss []DebugStep) string {
//line lib/promrelabel/debug.qtpl:139
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:139
writerelabelDebugSteps(qb422016, dss)
//line lib/promrelabel/debug.qtpl:139
qs422016 := string(qb422016.B)
//line lib/promrelabel/debug.qtpl:139
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promrelabel/debug.qtpl:139
return qs422016
//line lib/promrelabel/debug.qtpl:139
}
//line lib/promrelabel/debug.qtpl:141
func streamlabelsWithHighlight(qw422016 *qt422016.Writer, labels *promutils.Labels, highlight map[string]struct{}, color string) {
//line lib/promrelabel/debug.qtpl:143
labelsList := labels.GetLabels()
metricName := ""
for i, label := range labelsList {
if label.Name == "__name__" {
metricName = label.Value
labelsList = append(labelsList[:i], labelsList[i+1:]...)
break
}
}
//line lib/promrelabel/debug.qtpl:153
if metricName != "" {
//line lib/promrelabel/debug.qtpl:154
if _, ok := highlight["__name__"]; ok {
//line lib/promrelabel/debug.qtpl:154
qw422016.N().S(`<span style="font-weight:bold;color:`)
//line lib/promrelabel/debug.qtpl:155
qw422016.E().S(color)
//line lib/promrelabel/debug.qtpl:155
qw422016.N().S(`">`)
//line lib/promrelabel/debug.qtpl:155
qw422016.E().S(metricName)
//line lib/promrelabel/debug.qtpl:155
qw422016.N().S(`</span>`)
//line lib/promrelabel/debug.qtpl:156
} else {
//line lib/promrelabel/debug.qtpl:157
qw422016.E().S(metricName)
//line lib/promrelabel/debug.qtpl:158
}
//line lib/promrelabel/debug.qtpl:159
if len(labelsList) == 0 {
//line lib/promrelabel/debug.qtpl:159
return
//line lib/promrelabel/debug.qtpl:159
}
//line lib/promrelabel/debug.qtpl:160
}
//line lib/promrelabel/debug.qtpl:160
qw422016.N().S(`{`)
//line lib/promrelabel/debug.qtpl:162
for i, label := range labelsList {
//line lib/promrelabel/debug.qtpl:163
if _, ok := highlight[label.Name]; ok {
//line lib/promrelabel/debug.qtpl:163
qw422016.N().S(`<span style="font-weight:bold;color:`)
//line lib/promrelabel/debug.qtpl:164
qw422016.E().S(color)
//line lib/promrelabel/debug.qtpl:164
qw422016.N().S(`">`)
//line lib/promrelabel/debug.qtpl:164
qw422016.E().S(label.Name)
//line lib/promrelabel/debug.qtpl:164
qw422016.N().S(`=`)
//line lib/promrelabel/debug.qtpl:164
qw422016.E().Q(label.Value)
//line lib/promrelabel/debug.qtpl:164
qw422016.N().S(`</span>`)
//line lib/promrelabel/debug.qtpl:165
} else {
//line lib/promrelabel/debug.qtpl:166
qw422016.E().S(label.Name)
//line lib/promrelabel/debug.qtpl:166
qw422016.N().S(`=`)
//line lib/promrelabel/debug.qtpl:166
qw422016.E().Q(label.Value)
//line lib/promrelabel/debug.qtpl:167
}
//line lib/promrelabel/debug.qtpl:168
if i < len(labelsList)-1 {
//line lib/promrelabel/debug.qtpl:168
qw422016.N().S(`,`)
//line lib/promrelabel/debug.qtpl:168
qw422016.N().S(` `)
//line lib/promrelabel/debug.qtpl:168
}
//line lib/promrelabel/debug.qtpl:169
}
//line lib/promrelabel/debug.qtpl:169
qw422016.N().S(`}`)
//line lib/promrelabel/debug.qtpl:171
}
//line lib/promrelabel/debug.qtpl:171
func writelabelsWithHighlight(qq422016 qtio422016.Writer, labels *promutils.Labels, highlight map[string]struct{}, color string) {
//line lib/promrelabel/debug.qtpl:171
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:171
streamlabelsWithHighlight(qw422016, labels, highlight, color)
//line lib/promrelabel/debug.qtpl:171
qt422016.ReleaseWriter(qw422016)
//line lib/promrelabel/debug.qtpl:171
}
//line lib/promrelabel/debug.qtpl:171
func labelsWithHighlight(labels *promutils.Labels, highlight map[string]struct{}, color string) string {
//line lib/promrelabel/debug.qtpl:171
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:171
writelabelsWithHighlight(qb422016, labels, highlight, color)
//line lib/promrelabel/debug.qtpl:171
qs422016 := string(qb422016.B)
//line lib/promrelabel/debug.qtpl:171
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promrelabel/debug.qtpl:171
return qs422016
//line lib/promrelabel/debug.qtpl:171
}
//line lib/promrelabel/debug.qtpl:173
func streammustFormatLabels(qw422016 *qt422016.Writer, s string) {
//line lib/promrelabel/debug.qtpl:174
labels := promutils.MustNewLabelsFromString(s)
//line lib/promrelabel/debug.qtpl:175
streamlabelsWithHighlight(qw422016, labels, nil, "")
//line lib/promrelabel/debug.qtpl:176
}
//line lib/promrelabel/debug.qtpl:176
func writemustFormatLabels(qq422016 qtio422016.Writer, s string) {
//line lib/promrelabel/debug.qtpl:176
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promrelabel/debug.qtpl:176
streammustFormatLabels(qw422016, s)
//line lib/promrelabel/debug.qtpl:176
qt422016.ReleaseWriter(qw422016)
//line lib/promrelabel/debug.qtpl:176
}
//line lib/promrelabel/debug.qtpl:176
func mustFormatLabels(s string) string {
//line lib/promrelabel/debug.qtpl:176
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promrelabel/debug.qtpl:176
writemustFormatLabels(qb422016, s)
//line lib/promrelabel/debug.qtpl:176
qs422016 := string(qb422016.B)
//line lib/promrelabel/debug.qtpl:176
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promrelabel/debug.qtpl:176
return qs422016
//line lib/promrelabel/debug.qtpl:176
}

View file

@ -5,32 +5,13 @@ import (
"net/http"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
)
// WriteMetricRelabelDebug serves requests to /metric-relabel-debug page
func WriteMetricRelabelDebug(w http.ResponseWriter, r *http.Request) {
metric := r.FormValue("metric")
relabelConfigs := r.FormValue("relabel_configs")
if metric == "" {
metric = "{}"
}
labels, err := promutils.NewLabelsFromString(metric)
if err != nil {
err = fmt.Errorf("cannot parse metric: %s", err)
WriteMetricRelabelDebugSteps(w, nil, metric, relabelConfigs, err)
return
}
pcs, err := promrelabel.ParseRelabelConfigsData([]byte(relabelConfigs))
if err != nil {
err = fmt.Errorf("cannot parse relabel configs: %s", err)
WriteMetricRelabelDebugSteps(w, nil, metric, relabelConfigs, err)
return
}
dss := newDebugRelabelSteps(pcs, labels, false)
WriteMetricRelabelDebugSteps(w, dss, metric, relabelConfigs, nil)
promrelabel.WriteMetricRelabelDebug(w, metric, relabelConfigs)
}
// WriteTargetRelabelDebug generates response for /target-relabel-debug page
@ -38,118 +19,17 @@ func WriteTargetRelabelDebug(w http.ResponseWriter, r *http.Request) {
targetID := r.FormValue("id")
metric := r.FormValue("metric")
relabelConfigs := r.FormValue("relabel_configs")
var err error
if metric == "" && relabelConfigs == "" {
if targetID == "" {
metric = "{}"
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, nil)
return
}
pcs, labels, ok := getRelabelContextByTargetID(targetID)
if !ok {
err := fmt.Errorf("cannot find target for id=%s", targetID)
err = fmt.Errorf("cannot find target for id=%s", targetID)
targetID = ""
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, err)
return
} else {
metric = labels.String()
relabelConfigs = pcs.String()
}
metric = labels.String()
relabelConfigs = pcs.String()
dss := newDebugRelabelSteps(pcs, labels, true)
WriteTargetRelabelDebugSteps(w, targetID, dss, metric, relabelConfigs, nil)
return
}
if metric == "" {
metric = "{}"
}
labels, err := promutils.NewLabelsFromString(metric)
if err != nil {
err = fmt.Errorf("cannot parse metric: %s", err)
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, err)
return
}
pcs, err := promrelabel.ParseRelabelConfigsData([]byte(relabelConfigs))
if err != nil {
err = fmt.Errorf("cannot parse relabel configs: %s", err)
WriteTargetRelabelDebugSteps(w, targetID, nil, metric, relabelConfigs, err)
return
}
dss := newDebugRelabelSteps(pcs, labels, true)
WriteTargetRelabelDebugSteps(w, targetID, dss, metric, relabelConfigs, nil)
}
func newDebugRelabelSteps(pcs *promrelabel.ParsedConfigs, labels *promutils.Labels, isTargetRelabel bool) []promrelabel.DebugStep {
// The target relabeling below must be in sync with the code at scrapeWorkConfig.getScrapeWork if isTragetRelabeling=true
// and with the code at scrapeWork.addRowToTimeseries when isTargetRelabeling=false
// Prevent from modifying the original labels
labels = labels.Clone()
// Apply relabeling
labelsResult, dss := pcs.ApplyDebug(labels.GetLabels())
labels.Labels = labelsResult
outStr := promrelabel.LabelsToString(labels.GetLabels())
if isTargetRelabel {
// Add missing instance label
if labels.Get("instance") == "" {
address := labels.Get("__address__")
if address != "" {
inStr := outStr
labels.Add("instance", address)
outStr = promrelabel.LabelsToString(labels.GetLabels())
dss = append(dss, promrelabel.DebugStep{
Rule: "add missing instance label from __address__ label",
In: inStr,
Out: outStr,
})
}
}
// Remove labels with __ prefix
inStr := outStr
labels.RemoveLabelsWithDoubleUnderscorePrefix()
outStr = promrelabel.LabelsToString(labels.GetLabels())
if inStr != outStr {
dss = append(dss, promrelabel.DebugStep{
Rule: "remove labels with __ prefix",
In: inStr,
Out: outStr,
})
}
} else {
// Remove labels with __ prefix except of __name__
inStr := outStr
labels.Labels = promrelabel.FinalizeLabels(labels.Labels[:0], labels.Labels)
outStr = promrelabel.LabelsToString(labels.GetLabels())
if inStr != outStr {
dss = append(dss, promrelabel.DebugStep{
Rule: "remove labels with __ prefix except of __name__",
In: inStr,
Out: outStr,
})
}
}
// There is no need in labels' sorting, since promrelabel.LabelsToString() automatically sorts labels.
return dss
}
func getChangedLabelNames(in, out *promutils.Labels) map[string]struct{} {
inMap := in.ToMap()
outMap := out.ToMap()
changed := make(map[string]struct{})
for k, v := range outMap {
inV, ok := inMap[k]
if !ok || inV != v {
changed[k] = struct{}{}
}
}
for k, v := range inMap {
outV, ok := outMap[k]
if !ok || outV != v {
changed[k] = struct{}{}
}
}
return changed
promrelabel.WriteTargetRelabelDebug(w, targetID, metric, relabelConfigs, err)
}

View file

@ -1,433 +0,0 @@
// Code generated by qtc from "relabel_debug.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line lib/promscrape/relabel_debug.qtpl:1
package promscrape
//line lib/promscrape/relabel_debug.qtpl:1
import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
)
//line lib/promscrape/relabel_debug.qtpl:8
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line lib/promscrape/relabel_debug.qtpl:8
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line lib/promscrape/relabel_debug.qtpl:8
func StreamMetricRelabelDebugSteps(qw422016 *qt422016.Writer, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) {
//line lib/promscrape/relabel_debug.qtpl:8
qw422016.N().S(`<!DOCTYPE html><html lang="en"><head>`)
//line lib/promscrape/relabel_debug.qtpl:12
streamcommonHeader(qw422016)
//line lib/promscrape/relabel_debug.qtpl:12
qw422016.N().S(`<title>Metric relabel debug</title></head><body>`)
//line lib/promscrape/relabel_debug.qtpl:16
streamnavbar(qw422016)
//line lib/promscrape/relabel_debug.qtpl:16
qw422016.N().S(`<div class="container-fluid"><a href="https://docs.victoriametrics.com/relabeling.html" target="_blank">Relabeling docs</a>`)
//line lib/promscrape/relabel_debug.qtpl:18
qw422016.N().S(` `)
//line lib/promscrape/relabel_debug.qtpl:18
qw422016.N().S(`<a href="target-relabel-debug">Target relabel debug</a><br>`)
//line lib/promscrape/relabel_debug.qtpl:21
if err != nil {
//line lib/promscrape/relabel_debug.qtpl:22
streamerrorNotification(qw422016, err)
//line lib/promscrape/relabel_debug.qtpl:23
}
//line lib/promscrape/relabel_debug.qtpl:23
qw422016.N().S(`<div class="m-3"><form method="POST">`)
//line lib/promscrape/relabel_debug.qtpl:27
streamrelabelDebugFormInputs(qw422016, metric, relabelConfigs)
//line lib/promscrape/relabel_debug.qtpl:27
qw422016.N().S(`<input type="submit" value="Submit" class="btn btn-primary m-1" /></form></div><div class="row"><main class="col-12">`)
//line lib/promscrape/relabel_debug.qtpl:35
streamrelabelDebugSteps(qw422016, dss)
//line lib/promscrape/relabel_debug.qtpl:35
qw422016.N().S(`</main></div></div></body></html>`)
//line lib/promscrape/relabel_debug.qtpl:41
}
//line lib/promscrape/relabel_debug.qtpl:41
func WriteMetricRelabelDebugSteps(qq422016 qtio422016.Writer, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) {
//line lib/promscrape/relabel_debug.qtpl:41
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promscrape/relabel_debug.qtpl:41
StreamMetricRelabelDebugSteps(qw422016, dss, metric, relabelConfigs, err)
//line lib/promscrape/relabel_debug.qtpl:41
qt422016.ReleaseWriter(qw422016)
//line lib/promscrape/relabel_debug.qtpl:41
}
//line lib/promscrape/relabel_debug.qtpl:41
func MetricRelabelDebugSteps(dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) string {
//line lib/promscrape/relabel_debug.qtpl:41
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promscrape/relabel_debug.qtpl:41
WriteMetricRelabelDebugSteps(qb422016, dss, metric, relabelConfigs, err)
//line lib/promscrape/relabel_debug.qtpl:41
qs422016 := string(qb422016.B)
//line lib/promscrape/relabel_debug.qtpl:41
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promscrape/relabel_debug.qtpl:41
return qs422016
//line lib/promscrape/relabel_debug.qtpl:41
}
//line lib/promscrape/relabel_debug.qtpl:43
func StreamTargetRelabelDebugSteps(qw422016 *qt422016.Writer, targetID string, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) {
//line lib/promscrape/relabel_debug.qtpl:43
qw422016.N().S(`<!DOCTYPE html><html lang="en"><head>`)
//line lib/promscrape/relabel_debug.qtpl:47
streamcommonHeader(qw422016)
//line lib/promscrape/relabel_debug.qtpl:47
qw422016.N().S(`<title>Target relabel debug</title></head><body>`)
//line lib/promscrape/relabel_debug.qtpl:51
streamnavbar(qw422016)
//line lib/promscrape/relabel_debug.qtpl:51
qw422016.N().S(`<div class="container-fluid"><a href="https://docs.victoriametrics.com/relabeling.html" target="_blank">Relabeling docs</a>`)
//line lib/promscrape/relabel_debug.qtpl:53
qw422016.N().S(` `)
//line lib/promscrape/relabel_debug.qtpl:53
qw422016.N().S(`<a href="metric-relabel-debug">Metric relabel debug</a><br/>`)
//line lib/promscrape/relabel_debug.qtpl:56
if err != nil {
//line lib/promscrape/relabel_debug.qtpl:57
streamerrorNotification(qw422016, err)
//line lib/promscrape/relabel_debug.qtpl:58
}
//line lib/promscrape/relabel_debug.qtpl:58
qw422016.N().S(`<div class="m-3"><form method="POST">`)
//line lib/promscrape/relabel_debug.qtpl:62
streamrelabelDebugFormInputs(qw422016, metric, relabelConfigs)
//line lib/promscrape/relabel_debug.qtpl:62
qw422016.N().S(`<input type="hidden" name="id" value="`)
//line lib/promscrape/relabel_debug.qtpl:64
qw422016.E().S(targetID)
//line lib/promscrape/relabel_debug.qtpl:64
qw422016.N().S(`" /><input type="submit" value="Submit" class="btn btn-primary m-1" />`)
//line lib/promscrape/relabel_debug.qtpl:67
if targetID != "" {
//line lib/promscrape/relabel_debug.qtpl:67
qw422016.N().S(`<button type="button" onclick="location.href='target-relabel-debug?id=`)
//line lib/promscrape/relabel_debug.qtpl:68
qw422016.E().S(targetID)
//line lib/promscrape/relabel_debug.qtpl:68
qw422016.N().S(`'" class="btn btn-secondary m-1">Reset</button>`)
//line lib/promscrape/relabel_debug.qtpl:69
}
//line lib/promscrape/relabel_debug.qtpl:69
qw422016.N().S(`</form></div><div class="row"><main class="col-12">`)
//line lib/promscrape/relabel_debug.qtpl:75
streamrelabelDebugSteps(qw422016, dss)
//line lib/promscrape/relabel_debug.qtpl:75
qw422016.N().S(`</main></div></div></body></html>`)
//line lib/promscrape/relabel_debug.qtpl:81
}
//line lib/promscrape/relabel_debug.qtpl:81
func WriteTargetRelabelDebugSteps(qq422016 qtio422016.Writer, targetID string, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) {
//line lib/promscrape/relabel_debug.qtpl:81
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promscrape/relabel_debug.qtpl:81
StreamTargetRelabelDebugSteps(qw422016, targetID, dss, metric, relabelConfigs, err)
//line lib/promscrape/relabel_debug.qtpl:81
qt422016.ReleaseWriter(qw422016)
//line lib/promscrape/relabel_debug.qtpl:81
}
//line lib/promscrape/relabel_debug.qtpl:81
func TargetRelabelDebugSteps(targetID string, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) string {
//line lib/promscrape/relabel_debug.qtpl:81
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promscrape/relabel_debug.qtpl:81
WriteTargetRelabelDebugSteps(qb422016, targetID, dss, metric, relabelConfigs, err)
//line lib/promscrape/relabel_debug.qtpl:81
qs422016 := string(qb422016.B)
//line lib/promscrape/relabel_debug.qtpl:81
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promscrape/relabel_debug.qtpl:81
return qs422016
//line lib/promscrape/relabel_debug.qtpl:81
}
//line lib/promscrape/relabel_debug.qtpl:83
func streamrelabelDebugFormInputs(qw422016 *qt422016.Writer, metric, relabelConfigs string) {
//line lib/promscrape/relabel_debug.qtpl:83
qw422016.N().S(`<div>Relabel configs:<br/><textarea name="relabel_configs" style="width: 100%; height: 15em" class="m-1">`)
//line lib/promscrape/relabel_debug.qtpl:86
qw422016.E().S(relabelConfigs)
//line lib/promscrape/relabel_debug.qtpl:86
qw422016.N().S(`</textarea></div><div>Labels:<br/><textarea name="metric" style="width: 100%; height: 5em" class="m-1">`)
//line lib/promscrape/relabel_debug.qtpl:91
qw422016.E().S(metric)
//line lib/promscrape/relabel_debug.qtpl:91
qw422016.N().S(`</textarea></div>`)
//line lib/promscrape/relabel_debug.qtpl:93
}
//line lib/promscrape/relabel_debug.qtpl:93
func writerelabelDebugFormInputs(qq422016 qtio422016.Writer, metric, relabelConfigs string) {
//line lib/promscrape/relabel_debug.qtpl:93
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promscrape/relabel_debug.qtpl:93
streamrelabelDebugFormInputs(qw422016, metric, relabelConfigs)
//line lib/promscrape/relabel_debug.qtpl:93
qt422016.ReleaseWriter(qw422016)
//line lib/promscrape/relabel_debug.qtpl:93
}
//line lib/promscrape/relabel_debug.qtpl:93
func relabelDebugFormInputs(metric, relabelConfigs string) string {
//line lib/promscrape/relabel_debug.qtpl:93
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promscrape/relabel_debug.qtpl:93
writerelabelDebugFormInputs(qb422016, metric, relabelConfigs)
//line lib/promscrape/relabel_debug.qtpl:93
qs422016 := string(qb422016.B)
//line lib/promscrape/relabel_debug.qtpl:93
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promscrape/relabel_debug.qtpl:93
return qs422016
//line lib/promscrape/relabel_debug.qtpl:93
}
//line lib/promscrape/relabel_debug.qtpl:95
func streamrelabelDebugSteps(qw422016 *qt422016.Writer, dss []promrelabel.DebugStep) {
//line lib/promscrape/relabel_debug.qtpl:96
if len(dss) > 0 {
//line lib/promscrape/relabel_debug.qtpl:96
qw422016.N().S(`<div class="m-3"><b>Original labels:</b> <samp>`)
//line lib/promscrape/relabel_debug.qtpl:98
streammustFormatLabels(qw422016, dss[0].In)
//line lib/promscrape/relabel_debug.qtpl:98
qw422016.N().S(`</samp></div>`)
//line lib/promscrape/relabel_debug.qtpl:100
}
//line lib/promscrape/relabel_debug.qtpl:100
qw422016.N().S(`<table class="table table-striped table-hover table-bordered table-sm"><thead><tr><th scope="col" style="width: 5%">Step</th><th scope="col" style="width: 25%">Relabeling Rule</th><th scope="col" style="width: 35%">Input Labels</th><th scope="col" stile="width: 35%">Output labels</a></tr></thead><tbody>`)
//line lib/promscrape/relabel_debug.qtpl:111
for i, ds := range dss {
//line lib/promscrape/relabel_debug.qtpl:113
inLabels := promutils.MustNewLabelsFromString(ds.In)
outLabels := promutils.MustNewLabelsFromString(ds.Out)
changedLabels := getChangedLabelNames(inLabels, outLabels)
//line lib/promscrape/relabel_debug.qtpl:116
qw422016.N().S(`<tr><td>`)
//line lib/promscrape/relabel_debug.qtpl:118
qw422016.N().D(i)
//line lib/promscrape/relabel_debug.qtpl:118
qw422016.N().S(`</td><td><b><pre class="m-2">`)
//line lib/promscrape/relabel_debug.qtpl:119
qw422016.E().S(ds.Rule)
//line lib/promscrape/relabel_debug.qtpl:119
qw422016.N().S(`</pre></b></td><td><div class="m-2" style="font-size: 0.9em" title="deleted and updated labels highlighted in red">`)
//line lib/promscrape/relabel_debug.qtpl:122
streamlabelsWithHighlight(qw422016, inLabels, changedLabels, "red")
//line lib/promscrape/relabel_debug.qtpl:122
qw422016.N().S(`</div></td><td><div class="m-2" style="font-size: 0.9em" title="added and updated labels highlighted in blue">`)
//line lib/promscrape/relabel_debug.qtpl:127
streamlabelsWithHighlight(qw422016, outLabels, changedLabels, "blue")
//line lib/promscrape/relabel_debug.qtpl:127
qw422016.N().S(`</div></td></tr>`)
//line lib/promscrape/relabel_debug.qtpl:131
}
//line lib/promscrape/relabel_debug.qtpl:131
qw422016.N().S(`</tbody></table>`)
//line lib/promscrape/relabel_debug.qtpl:134
if len(dss) > 0 {
//line lib/promscrape/relabel_debug.qtpl:134
qw422016.N().S(`<div class="m-3"><b>Resulting labels:</b> <samp>`)
//line lib/promscrape/relabel_debug.qtpl:136
streammustFormatLabels(qw422016, dss[len(dss)-1].Out)
//line lib/promscrape/relabel_debug.qtpl:136
qw422016.N().S(`</samp></div>`)
//line lib/promscrape/relabel_debug.qtpl:138
}
//line lib/promscrape/relabel_debug.qtpl:139
}
//line lib/promscrape/relabel_debug.qtpl:139
func writerelabelDebugSteps(qq422016 qtio422016.Writer, dss []promrelabel.DebugStep) {
//line lib/promscrape/relabel_debug.qtpl:139
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promscrape/relabel_debug.qtpl:139
streamrelabelDebugSteps(qw422016, dss)
//line lib/promscrape/relabel_debug.qtpl:139
qt422016.ReleaseWriter(qw422016)
//line lib/promscrape/relabel_debug.qtpl:139
}
//line lib/promscrape/relabel_debug.qtpl:139
func relabelDebugSteps(dss []promrelabel.DebugStep) string {
//line lib/promscrape/relabel_debug.qtpl:139
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promscrape/relabel_debug.qtpl:139
writerelabelDebugSteps(qb422016, dss)
//line lib/promscrape/relabel_debug.qtpl:139
qs422016 := string(qb422016.B)
//line lib/promscrape/relabel_debug.qtpl:139
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promscrape/relabel_debug.qtpl:139
return qs422016
//line lib/promscrape/relabel_debug.qtpl:139
}
//line lib/promscrape/relabel_debug.qtpl:141
func streamlabelsWithHighlight(qw422016 *qt422016.Writer, labels *promutils.Labels, highlight map[string]struct{}, color string) {
//line lib/promscrape/relabel_debug.qtpl:143
labelsList := labels.GetLabels()
metricName := ""
for i, label := range labelsList {
if label.Name == "__name__" {
metricName = label.Value
labelsList = append(labelsList[:i], labelsList[i+1:]...)
break
}
}
//line lib/promscrape/relabel_debug.qtpl:153
if metricName != "" {
//line lib/promscrape/relabel_debug.qtpl:154
if _, ok := highlight["__name__"]; ok {
//line lib/promscrape/relabel_debug.qtpl:154
qw422016.N().S(`<span style="font-weight:bold;color:`)
//line lib/promscrape/relabel_debug.qtpl:155
qw422016.E().S(color)
//line lib/promscrape/relabel_debug.qtpl:155
qw422016.N().S(`">`)
//line lib/promscrape/relabel_debug.qtpl:155
qw422016.E().S(metricName)
//line lib/promscrape/relabel_debug.qtpl:155
qw422016.N().S(`</span>`)
//line lib/promscrape/relabel_debug.qtpl:156
} else {
//line lib/promscrape/relabel_debug.qtpl:157
qw422016.E().S(metricName)
//line lib/promscrape/relabel_debug.qtpl:158
}
//line lib/promscrape/relabel_debug.qtpl:159
if len(labelsList) == 0 {
//line lib/promscrape/relabel_debug.qtpl:159
return
//line lib/promscrape/relabel_debug.qtpl:159
}
//line lib/promscrape/relabel_debug.qtpl:160
}
//line lib/promscrape/relabel_debug.qtpl:160
qw422016.N().S(`{`)
//line lib/promscrape/relabel_debug.qtpl:162
for i, label := range labelsList {
//line lib/promscrape/relabel_debug.qtpl:163
if _, ok := highlight[label.Name]; ok {
//line lib/promscrape/relabel_debug.qtpl:163
qw422016.N().S(`<span style="font-weight:bold;color:`)
//line lib/promscrape/relabel_debug.qtpl:164
qw422016.E().S(color)
//line lib/promscrape/relabel_debug.qtpl:164
qw422016.N().S(`">`)
//line lib/promscrape/relabel_debug.qtpl:164
qw422016.E().S(label.Name)
//line lib/promscrape/relabel_debug.qtpl:164
qw422016.N().S(`=`)
//line lib/promscrape/relabel_debug.qtpl:164
qw422016.E().Q(label.Value)
//line lib/promscrape/relabel_debug.qtpl:164
qw422016.N().S(`</span>`)
//line lib/promscrape/relabel_debug.qtpl:165
} else {
//line lib/promscrape/relabel_debug.qtpl:166
qw422016.E().S(label.Name)
//line lib/promscrape/relabel_debug.qtpl:166
qw422016.N().S(`=`)
//line lib/promscrape/relabel_debug.qtpl:166
qw422016.E().Q(label.Value)
//line lib/promscrape/relabel_debug.qtpl:167
}
//line lib/promscrape/relabel_debug.qtpl:168
if i < len(labelsList)-1 {
//line lib/promscrape/relabel_debug.qtpl:168
qw422016.N().S(`,`)
//line lib/promscrape/relabel_debug.qtpl:168
qw422016.N().S(` `)
//line lib/promscrape/relabel_debug.qtpl:168
}
//line lib/promscrape/relabel_debug.qtpl:169
}
//line lib/promscrape/relabel_debug.qtpl:169
qw422016.N().S(`}`)
//line lib/promscrape/relabel_debug.qtpl:171
}
//line lib/promscrape/relabel_debug.qtpl:171
func writelabelsWithHighlight(qq422016 qtio422016.Writer, labels *promutils.Labels, highlight map[string]struct{}, color string) {
//line lib/promscrape/relabel_debug.qtpl:171
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promscrape/relabel_debug.qtpl:171
streamlabelsWithHighlight(qw422016, labels, highlight, color)
//line lib/promscrape/relabel_debug.qtpl:171
qt422016.ReleaseWriter(qw422016)
//line lib/promscrape/relabel_debug.qtpl:171
}
//line lib/promscrape/relabel_debug.qtpl:171
func labelsWithHighlight(labels *promutils.Labels, highlight map[string]struct{}, color string) string {
//line lib/promscrape/relabel_debug.qtpl:171
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promscrape/relabel_debug.qtpl:171
writelabelsWithHighlight(qb422016, labels, highlight, color)
//line lib/promscrape/relabel_debug.qtpl:171
qs422016 := string(qb422016.B)
//line lib/promscrape/relabel_debug.qtpl:171
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promscrape/relabel_debug.qtpl:171
return qs422016
//line lib/promscrape/relabel_debug.qtpl:171
}
//line lib/promscrape/relabel_debug.qtpl:173
func streammustFormatLabels(qw422016 *qt422016.Writer, s string) {
//line lib/promscrape/relabel_debug.qtpl:174
labels := promutils.MustNewLabelsFromString(s)
//line lib/promscrape/relabel_debug.qtpl:175
streamlabelsWithHighlight(qw422016, labels, nil, "")
//line lib/promscrape/relabel_debug.qtpl:176
}
//line lib/promscrape/relabel_debug.qtpl:176
func writemustFormatLabels(qq422016 qtio422016.Writer, s string) {
//line lib/promscrape/relabel_debug.qtpl:176
qw422016 := qt422016.AcquireWriter(qq422016)
//line lib/promscrape/relabel_debug.qtpl:176
streammustFormatLabels(qw422016, s)
//line lib/promscrape/relabel_debug.qtpl:176
qt422016.ReleaseWriter(qw422016)
//line lib/promscrape/relabel_debug.qtpl:176
}
//line lib/promscrape/relabel_debug.qtpl:176
func mustFormatLabels(s string) string {
//line lib/promscrape/relabel_debug.qtpl:176
qb422016 := qt422016.AcquireByteBuffer()
//line lib/promscrape/relabel_debug.qtpl:176
writemustFormatLabels(qb422016, s)
//line lib/promscrape/relabel_debug.qtpl:176
qs422016 := string(qb422016.B)
//line lib/promscrape/relabel_debug.qtpl:176
qt422016.ReleaseByteBuffer(qb422016)
//line lib/promscrape/relabel_debug.qtpl:176
return qs422016
//line lib/promscrape/relabel_debug.qtpl:176
}

View file

@ -2,6 +2,7 @@
"net/url"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
) %}
@ -44,14 +45,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
{%= commonHeader() %}
{%= htmlcomponents.CommonHeader() %}
<title>Active Targets</title>
</head>
<body>
{%= navbar() %}
{%= htmlcomponents.Navbar() %}
<div class="container-fluid">
{% if tsr.err != nil %}
{%= errorNotification(tsr.err) %}
{%= htmlcomponents.ErrorNotification(tsr.err) %}
{% endif %}
<div class="row">
<main class="col-12">
@ -71,14 +72,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
{%= commonHeader() %}
{%= htmlcomponents.CommonHeader() %}
<title>Discovered Targets</title>
</head>
<body>
{%= navbar() %}
{%= htmlcomponents.Navbar() %}
<div class="container-fluid">
{% if tsr.err != nil %}
{%= errorNotification(tsr.err) %}
{%= htmlcomponents.ErrorNotification(tsr.err) %}
{% endif %}
<div class="row">
<main class="col-12">
@ -94,23 +95,6 @@
</html>
{% endfunc %}
{% func commonHeader() %}
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="static/css/bootstrap.min.css" rel="stylesheet" />
{% endfunc %}
{% func navbar() %}
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="d-flex justify-content-between">
<a href="/" class="navbar-brand d-flex align-items-center ms-3" title="The High Performance Open Source Time Series Database &amp; Monitoring Solution ">
<svg xmlns="http://www.w3.org/2000/svg" id="VM_logo" viewBox="0 0 464.61 533.89" width="20" height="20" class="me-1"><defs><style>.cls-1{fill:#fff;}</style></defs><path class="cls-1" d="M459.86,467.77c9,7.67,24.12,13.49,39.3,13.69v0h1.68v0c15.18-.2,30.31-6,39.3-13.69,47.43-40.45,184.65-166.24,184.65-166.24,36.84-34.27-65.64-68.28-223.95-68.47h-1.68c-158.31.19-260.79,34.2-224,68.47C275.21,301.53,412.43,427.32,459.86,467.77Z" transform="translate(-267.7 -233.05)"/><path class="cls-1" d="M540.1,535.88c-9,7.67-24.12,13.5-39.3,13.7h-1.6c-15.18-.2-30.31-6-39.3-13.7-32.81-28-148.56-132.93-192.16-172.7v60.74c0,6.67,2.55,15.52,7.09,19.68,29.64,27.18,143.94,131.8,185.07,166.88,9,7.67,24.12,13.49,39.3,13.69v0h1.6v0c15.18-.2,30.31-6,39.3-13.69,41.13-35.08,155.43-139.7,185.07-166.88,4.54-4.16,7.09-13,7.09-19.68V363.18C688.66,403,572.91,507.9,540.1,535.88Z" transform="translate(-267.7 -233.05)"/><path class="cls-1" d="M540.1,678.64c-9,7.67-24.12,13.49-39.3,13.69v0h-1.6v0c-15.18-.2-30.31-6-39.3-13.69-32.81-28-148.56-132.94-192.16-172.7v60.73c0,6.67,2.55,15.53,7.09,19.69,29.64,27.17,143.94,131.8,185.07,166.87,9,7.67,24.12,13.5,39.3,13.7h1.6c15.18-.2,30.31-6,39.3-13.7,41.13-35.07,155.43-139.7,185.07-166.87,4.54-4.16,7.09-13,7.09-19.69V505.94C688.66,545.7,572.91,650.66,540.1,678.64Z" transform="translate(-267.7 -233.05)"/></svg>
<strong>VictoriaMetrics</strong>
</a>
</div>
</div>
{% endfunc %}
{% func filtersForm(filter *requestFilter) %}
<div class="row g-3 align-items-center mb-3">
<div class="col-auto">
@ -395,14 +379,4 @@
}
{% endfunc %}
{% func errorNotification(err error) %}
<div class="alert alert-danger d-flex align-items-center" role="alert">
<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Danger:">
<use xlink:href="#exclamation-triangle-fill"/></svg>
<div>
{%s err.Error() %}
</div>
</div>
{% endfunc %}
{% endstripspace %}

File diff suppressed because it is too large Load diff