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 return true
case "/metric-relabel-debug": case "/metric-relabel-debug":
promscrapeMetricRelabelDebugRequests.Inc() promscrapeMetricRelabelDebugRequests.Inc()
httpserver.EnableCORS(w, r)
promscrape.WriteMetricRelabelDebug(w, r) promscrape.WriteMetricRelabelDebug(w, r)
return true return true
case "/target-relabel-debug": case "/target-relabel-debug":

View file

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

View file

@ -145,7 +145,7 @@ func StreamExpandWithExprsJSONResponse(qw422016 *qt422016.Writer, q string) {
//line app/vmselect/prometheus/expand-with-exprs.qtpl:68 //line app/vmselect/prometheus/expand-with-exprs.qtpl:68
qw422016.N().S(`"status": "error","error":`) qw422016.N().S(`"status": "error","error":`)
//line app/vmselect/prometheus/expand-with-exprs.qtpl:70 //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 //line app/vmselect/prometheus/expand-with-exprs.qtpl:71
} else { } else {
//line app/vmselect/prometheus/expand-with-exprs.qtpl:72 //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 //line app/vmselect/prometheus/expand-with-exprs.qtpl:72
qw422016.N().S(`"status": "success","expr":`) qw422016.N().S(`"status": "success","expr":`)
//line app/vmselect/prometheus/expand-with-exprs.qtpl:74 //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
} }
//line app/vmselect/prometheus/expand-with-exprs.qtpl:75 //line app/vmselect/prometheus/expand-with-exprs.qtpl:75

View file

@ -145,8 +145,8 @@ function submitRelabelDebugForm(e) {
{% else %} {% else %}
"status": "success", "status": "success",
{% if len(dss) > 0 %} {% if len(dss) > 0 %}
"originalLabels": {%q= string(mustFormatLabels(dss[0].In)) %}, "originalLabels": {%q= mustFormatLabels(dss[0].In) %},
"resultingLabels": {%q= string(mustFormatLabels(dss[len(dss)-1].Out)) %}, "resultingLabels": {%q= mustFormatLabels(dss[len(dss)-1].Out) %},
{% endif %} {% endif %}
"steps": [ "steps": [
{% for i, ds := range dss %} {% for i, ds := range dss %}

View file

@ -354,11 +354,11 @@ func StreamRelabelDebugStepsJSON(qw422016 *qt422016.Writer, targetURL, targetID
//line lib/promrelabel/debug.qtpl:147 //line lib/promrelabel/debug.qtpl:147
qw422016.N().S(`"originalLabels":`) qw422016.N().S(`"originalLabels":`)
//line lib/promrelabel/debug.qtpl:148 //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 //line lib/promrelabel/debug.qtpl:148
qw422016.N().S(`,"resultingLabels":`) qw422016.N().S(`,"resultingLabels":`)
//line lib/promrelabel/debug.qtpl:149 //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 //line lib/promrelabel/debug.qtpl:149
qw422016.N().S(`,`) qw422016.N().S(`,`)
//line lib/promrelabel/debug.qtpl:150 //line lib/promrelabel/debug.qtpl:150

View file

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