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) {
|
2023-01-05 11:26:47 +00:00
|
|
|
targetID := r.FormValue("id")
|
2022-12-10 10:09:21 +00:00
|
|
|
metric := r.FormValue("metric")
|
|
|
|
relabelConfigs := r.FormValue("relabel_configs")
|
2023-01-05 11:26:47 +00:00
|
|
|
var err error
|
|
|
|
|
2023-01-06 00:35:20 +00:00
|
|
|
if metric == "" && relabelConfigs == "" && targetID != "" {
|
2023-01-05 11:26:47 +00: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 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
|
|
|
|
2023-01-06 00:35:20 +00:00
|
|
|
if metric == "" && relabelConfigs == "" && targetID != "" {
|
2023-01-05 11:26:47 +00:00
|
|
|
pcs, labels, ok := getTargetRelabelContextByTargetID(targetID)
|
2022-12-10 20:44:09 +00:00
|
|
|
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
|
|
|
}
|