app/vmselect: small cleanup after 4f3f9950d0

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3807
This commit is contained in:
Aliaksandr Valialkin 2023-05-08 14:57:09 -07:00
parent 1db9b78b88
commit ec3943d14a
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
6 changed files with 41 additions and 37 deletions

View file

@ -468,7 +468,6 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
return true
case "/metric-relabel-debug":
promscrapeMetricRelabelDebugRequests.Inc()
httpserver.EnableCORS(w, r)
promscrape.WriteMetricRelabelDebug(w, r)
return true
case "/target-relabel-debug":

View file

@ -67,11 +67,11 @@ textarea { margin: 1em }
{% code expr, err := metricsql.Parse(q) %}
{% if err != nil %}
"status": "error",
"error": {%q fmt.Sprintf("Cannot parse query: %s", err) %}
"error": {%q= fmt.Sprintf("Cannot parse query: %s", err) %}
{% else %}
{% code expr = metricsql.Optimize(expr) %}
"status": "success",
"expr": {%qz expr.AppendString(nil) %}
"expr": {%qz= expr.AppendString(nil) %}
{% endif %}
}
{% endfunc %}

View file

@ -145,7 +145,7 @@ func StreamExpandWithExprsJSONResponse(qw422016 *qt422016.Writer, q string) {
//line app/vmselect/prometheus/expand-with-exprs.qtpl:68
qw422016.N().S(`"status": "error","error":`)
//line app/vmselect/prometheus/expand-with-exprs.qtpl:70
qw422016.E().Q(fmt.Sprintf("Cannot parse query: %s", err))
qw422016.N().Q(fmt.Sprintf("Cannot parse query: %s", err))
//line app/vmselect/prometheus/expand-with-exprs.qtpl:71
} else {
//line app/vmselect/prometheus/expand-with-exprs.qtpl:72
@ -154,7 +154,7 @@ func StreamExpandWithExprsJSONResponse(qw422016 *qt422016.Writer, q string) {
//line app/vmselect/prometheus/expand-with-exprs.qtpl:72
qw422016.N().S(`"status": "success","expr":`)
//line app/vmselect/prometheus/expand-with-exprs.qtpl:74
qw422016.E().QZ(expr.AppendString(nil))
qw422016.N().QZ(expr.AppendString(nil))
//line app/vmselect/prometheus/expand-with-exprs.qtpl:75
}
//line app/vmselect/prometheus/expand-with-exprs.qtpl:75

View file

@ -138,33 +138,33 @@ function submitRelabelDebugForm(e) {
{% 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= string(mustFormatLabels(dss[0].In)) %},
"resultingLabels": {%q= string(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 %}
]
{
{% 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) %}

View file

@ -354,11 +354,11 @@ func StreamRelabelDebugStepsJSON(qw422016 *qt422016.Writer, targetURL, targetID
//line lib/promrelabel/debug.qtpl:147
qw422016.N().S(`"originalLabels":`)
//line lib/promrelabel/debug.qtpl:148
qw422016.N().Q(string(mustFormatLabels(dss[0].In)))
qw422016.N().Q(mustFormatLabels(dss[0].In))
//line lib/promrelabel/debug.qtpl:148
qw422016.N().S(`,"resultingLabels":`)
//line lib/promrelabel/debug.qtpl:149
qw422016.N().Q(string(mustFormatLabels(dss[len(dss)-1].Out)))
qw422016.N().Q(mustFormatLabels(dss[len(dss)-1].Out))
//line lib/promrelabel/debug.qtpl:149
qw422016.N().S(`,`)
//line lib/promrelabel/debug.qtpl:150

View file

@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
)
@ -15,10 +16,6 @@ func WriteMetricRelabelDebug(w http.ResponseWriter, r *http.Request) {
format := r.FormValue("format")
var err error
if format == "json" {
w.Header().Set("Content-Type", "application/json")
}
if metric == "" && relabelConfigs == "" && targetID != "" {
pcs, labels, ok := getMetricRelabelContextByTargetID(targetID)
if !ok {
@ -29,6 +26,10 @@ func WriteMetricRelabelDebug(w http.ResponseWriter, r *http.Request) {
relabelConfigs = pcs.String()
}
}
if format == "json" {
httpserver.EnableCORS(w, r)
w.Header().Set("Content-Type", "application/json")
}
promrelabel.WriteMetricRelabelDebug(w, targetID, metric, relabelConfigs, format, err)
}
@ -50,5 +51,9 @@ func WriteTargetRelabelDebug(w http.ResponseWriter, r *http.Request) {
relabelConfigs = pcs.String()
}
}
if format == "json" {
httpserver.EnableCORS(w, r)
w.Header().Set("Content-Type", "application/json")
}
promrelabel.WriteTargetRelabelDebug(w, targetID, metric, relabelConfigs, format, err)
}