2022-12-10 10:09:21 +00:00
|
|
|
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) {
|
|
|
|
metric := r.FormValue("metric")
|
|
|
|
relabelConfigs := r.FormValue("relabel_configs")
|
2023-01-04 07:26:27 +00:00
|
|
|
promrelabel.WriteMetricRelabelDebug(w, metric, relabelConfigs)
|
2022-12-10 10:09:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WriteTargetRelabelDebug generates response for /target-relabel-debug page
|
2022-12-10 20:44:09 +00:00
|
|
|
func WriteTargetRelabelDebug(w http.ResponseWriter, r *http.Request) {
|
2022-12-10 10:09:21 +00:00
|
|
|
targetID := r.FormValue("id")
|
2022-12-10 20:44:09 +00:00
|
|
|
metric := r.FormValue("metric")
|
|
|
|
relabelConfigs := r.FormValue("relabel_configs")
|
2023-01-04 07:26:27 +00:00
|
|
|
var err error
|
2022-12-10 20:44:09 +00:00
|
|
|
|
|
|
|
if metric == "" && relabelConfigs == "" {
|
|
|
|
pcs, labels, ok := getRelabelContextByTargetID(targetID)
|
|
|
|
if !ok {
|
2023-01-04 07:26:27 +00:00
|
|
|
err = fmt.Errorf("cannot find target for id=%s", targetID)
|
2022-12-10 20:44:09 +00:00
|
|
|
targetID = ""
|
2023-01-04 07:26:27 +00:00
|
|
|
} else {
|
|
|
|
metric = labels.String()
|
|
|
|
relabelConfigs = pcs.String()
|
2022-12-10 10:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-04 07:26:27 +00:00
|
|
|
promrelabel.WriteTargetRelabelDebug(w, targetID, metric, relabelConfigs, err)
|
2022-12-10 10:09:21 +00:00
|
|
|
}
|