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