mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-05 01:01:09 +01:00
4f3f9950d0
* feat: add metric relabel debug (#3807) * fix: add link to relabeling cookbook * lib/promrelabel: merge, fix conflicts * lib/promrelabel: fix diff * docs/vmui: add metric relabel playground --------- Co-authored-by: dmitryk-dk <kozlovdmitriyy@gmail.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package promscrape
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
|
)
|
|
|
|
// WriteMetricRelabelDebug serves requests to /metric-relabel-debug page
|
|
func WriteMetricRelabelDebug(w http.ResponseWriter, r *http.Request) {
|
|
targetID := r.FormValue("id")
|
|
metric := r.FormValue("metric")
|
|
relabelConfigs := r.FormValue("relabel_configs")
|
|
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 {
|
|
err = fmt.Errorf("cannot find target for id=%s", targetID)
|
|
targetID = ""
|
|
} else {
|
|
metric = labels.String()
|
|
relabelConfigs = pcs.String()
|
|
}
|
|
}
|
|
promrelabel.WriteMetricRelabelDebug(w, targetID, metric, relabelConfigs, format, err)
|
|
}
|
|
|
|
// WriteTargetRelabelDebug generates response for /target-relabel-debug page
|
|
func WriteTargetRelabelDebug(w http.ResponseWriter, r *http.Request) {
|
|
targetID := r.FormValue("id")
|
|
metric := r.FormValue("metric")
|
|
relabelConfigs := r.FormValue("relabel_configs")
|
|
format := r.FormValue("format")
|
|
var err error
|
|
|
|
if metric == "" && relabelConfigs == "" && targetID != "" {
|
|
pcs, labels, ok := getTargetRelabelContextByTargetID(targetID)
|
|
if !ok {
|
|
err = fmt.Errorf("cannot find target for id=%s", targetID)
|
|
targetID = ""
|
|
} else {
|
|
metric = labels.String()
|
|
relabelConfigs = pcs.String()
|
|
}
|
|
}
|
|
promrelabel.WriteTargetRelabelDebug(w, targetID, metric, relabelConfigs, format, err)
|
|
}
|