{% import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/htmlcomponents" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" ) %} {% stripspace %} {% func RelabelDebugSteps(targetURL string, 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 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 %}