{% import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" ) %} {% stripspace %} {% func MetricRelabelDebugSteps(dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) %} {%= commonHeader() %} Metric relabel debug {%= navbar() %}
Relabeling docs{% space %} Target relabel debug
{% if err != nil %} {%= errorNotification(err) %} {% endif %}
{%= relabelDebugFormInputs(metric, relabelConfigs) %}
{%= relabelDebugSteps(dss) %}
{% endfunc %} {% func TargetRelabelDebugSteps(targetID string, dss []promrelabel.DebugStep, metric, relabelConfigs string, err error) %} {%= commonHeader() %} Target relabel debug {%= navbar() %}
Relabeling docs{% space %} Metric relabel debug
{% if err != nil %} {%= errorNotification(err) %} {% endif %}
{%= relabelDebugFormInputs(metric, relabelConfigs) %} {% if targetID != "" %} {% endif %}
{%= relabelDebugSteps(dss) %}
{% endfunc %} {% func relabelDebugFormInputs(metric, relabelConfigs string) %}
Relabel configs:
Labels:
{% endfunc %} {% func relabelDebugSteps(dss []promrelabel.DebugStep) %} {% 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) %}
{% 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 %}