diff --git a/app/vmselect/main.go b/app/vmselect/main.go index af80bd413..a06e1ac35 100644 --- a/app/vmselect/main.go +++ b/app/vmselect/main.go @@ -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": diff --git a/app/vmselect/prometheus/expand-with-exprs.qtpl b/app/vmselect/prometheus/expand-with-exprs.qtpl index 604f10fd0..d65393cb7 100644 --- a/app/vmselect/prometheus/expand-with-exprs.qtpl +++ b/app/vmselect/prometheus/expand-with-exprs.qtpl @@ -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 %} diff --git a/app/vmselect/prometheus/expand-with-exprs.qtpl.go b/app/vmselect/prometheus/expand-with-exprs.qtpl.go index 2fd45395b..ca91d957f 100644 --- a/app/vmselect/prometheus/expand-with-exprs.qtpl.go +++ b/app/vmselect/prometheus/expand-with-exprs.qtpl.go @@ -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 diff --git a/lib/promrelabel/debug.qtpl b/lib/promrelabel/debug.qtpl index b015de0ff..0b612a165 100644 --- a/lib/promrelabel/debug.qtpl +++ b/lib/promrelabel/debug.qtpl @@ -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) %} diff --git a/lib/promrelabel/debug.qtpl.go b/lib/promrelabel/debug.qtpl.go index fcca1f40b..40f29ec89 100644 --- a/lib/promrelabel/debug.qtpl.go +++ b/lib/promrelabel/debug.qtpl.go @@ -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 diff --git a/lib/promscrape/relabel_debug.go b/lib/promscrape/relabel_debug.go index cc119a671..627bf68f6 100644 --- a/lib/promscrape/relabel_debug.go +++ b/lib/promscrape/relabel_debug.go @@ -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) }