{% import ( "fmt" "github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" ) %} {% stripspace %} {% func RelabelDebugSteps(targetURL, targetID, format string, dss []DebugStep, metric, relabelConfigs string, err error) %} {% if format == "json" %} {%= RelabelDebugStepsJSON(targetURL, targetID, dss, metric, relabelConfigs, err) %} {% else %} {%= RelabelDebugStepsHTML(targetURL, targetID, dss, metric, relabelConfigs, err) %} {% endif %} {% endfunc %} {% func RelabelDebugStepsHTML(targetURL, targetID string, dss []DebugStep, metric, relabelConfigs string, err error) %} {%= htmlcomponents.CommonHeader() %} Metric relabel debug {%= htmlcomponents.Navbar() %}
Relabeling docs{% space %} {% if targetURL != "" %} Metric relabel debug {% else %} Target relabel debug {% endif %}
{% if err != nil %} {%= htmlcomponents.ErrorNotification(err) %} {% endif %}
{%= relabelDebugFormInputs(metric, relabelConfigs) %} {% if targetID != "" %} {% endif %} {% if targetID != "" %} {% endif %}
{%= relabelDebugSteps(dss, targetURL, targetID) %}
{% endfunc %} {% func relabelDebugFormInputs(metric, relabelConfigs string) %}
Relabel configs:
Labels:
{% endfunc %} {% func relabelDebugSteps(dss []DebugStep, targetURL, targetID string) %} {% if len(dss) > 0 %}
Original labels: {%= mustFormatLabels(dss[0].In) %}
{% endif %} {% for i, ds := range dss %} {% code inLabels := promutils.MustNewLabelsFromString(ds.In) outLabels := promutils.MustNewLabelsFromString(ds.Out) changedLabels := getChangedLabelNames(inLabels, outLabels) %} {% endfor %}
Step Relabeling Rule Input Labels Output labels
{%d i %}
{%s ds.Rule %}
{%= labelsWithHighlight(inLabels, changedLabels, "red") %}
{%= labelsWithHighlight(outLabels, changedLabels, "blue") %}
{% if len(dss) > 0 %}
Resulting labels: {%= mustFormatLabels(dss[len(dss)-1].Out) %} {% if targetURL != "" %}
Target URL:{% space %}{%s targetURL %} {% if targetID != "" %} {% space %} (response) {% endif %}
{% endif %}
{% endif %} {% endfunc %} {% func RelabelDebugStepsJSON(targetURL, targetID string, dss []DebugStep, metric, relabelConfigs string, err error) %} { {% if err != nil %} "status": "error", "error": {%q= fmt.Sprintf("Error: %s", err) %} {% else %} "status": "success", {% if len(dss) > 0 %} "originalLabels": {%q= mustFormatLabels(dss[0].In) %}, "resultingLabels": {%q= mustFormatLabels(dss[len(dss)-1].Out) %}, {% endif %} "steps": [ {% for i, ds := range dss %} {% code inLabels := promutils.MustNewLabelsFromString(ds.In) outLabels := promutils.MustNewLabelsFromString(ds.Out) changedLabels := getChangedLabelNames(inLabels, outLabels) %} { "inLabels": {%q= labelsWithHighlight(inLabels, changedLabels, "red") %}, "outLabels": {%q= labelsWithHighlight(outLabels, changedLabels, "blue") %}, "rule": {%q= ds.Rule %} } {% if i != len(dss)-1 %},{% endif %} {% endfor %} ] {% endif %} } {% endfunc %} {% func labelsWithHighlight(labels *promutils.Labels, highlight map[string]struct{}, color string) %} {% code labelsList := labels.GetLabels() metricName := "" for i, label := range labelsList { if label.Name == "__name__" { metricName = label.Value labelsList = append(labelsList[:i], labelsList[i+1:]...) break } } %} {% if metricName != "" %} {% if _, ok := highlight["__name__"]; ok %} {%s metricName %} {% else %} {%s metricName %} {% endif %} {% if len(labelsList) == 0 %}{% return %}{% endif %} {% endif %} { {% for i, label := range labelsList %} {% if _, ok := highlight[label.Name]; ok %} {%s label.Name %}={%q label.Value %} {% else %} {%s label.Name %}={%q label.Value %} {% endif %} {% if i < len(labelsList)-1 %},{% space %}{% endif %} {% endfor %} } {% endfunc %} {% func mustFormatLabels(s string) %} {% code labels := promutils.MustNewLabelsFromString(s) %} {%= labelsWithHighlight(labels, nil, "") %} {% endfunc %} {% endstripspace %}