From ba7ff133e630c39cb914d1553988462cdf84135f Mon Sep 17 00:00:00 2001 From: ulricqin Date: Sat, 23 Jul 2022 17:50:16 +0800 Subject: [PATCH] modify prometheus query batch response format (#1068) --- src/webapi/router/router.go | 2 -- src/webapi/router/router_prometheus.go | 19 +++++-------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/webapi/router/router.go b/src/webapi/router/router.go index 26203948..27a00106 100644 --- a/src/webapi/router/router.go +++ b/src/webapi/router/router.go @@ -101,11 +101,9 @@ func configRoute(r *gin.Engine, version string) { if config.C.AnonymousAccess.PromQuerier { pages.Any("/prometheus/*url", prometheusProxy) - pages.POST("/query-range-batch", promBatchQueryRange) } else { pages.Any("/prometheus/*url", auth(), prometheusProxy) - pages.POST("/query-range-batch", auth(), promBatchQueryRange) } diff --git a/src/webapi/router/router_prometheus.go b/src/webapi/router/router_prometheus.go index 624ed936..5bb2b87b 100644 --- a/src/webapi/router/router_prometheus.go +++ b/src/webapi/router/router_prometheus.go @@ -32,21 +32,15 @@ type batchQueryForm struct { func promBatchQueryRange(c *gin.Context) { xcluster := c.GetHeader("X-Cluster") if xcluster == "" { - c.String(500, "X-Cluster is blank") - return + ginx.Bomb(http.StatusBadRequest, "header(X-Cluster) is blank") } var f batchQueryForm - err := c.BindJSON(&f) - if err != nil { - c.String(500, err.Error()) - return - } + ginx.Dangerous(c.BindJSON(&f)) cluster, exist := prom.Clusters.Get(xcluster) if !exist { - c.String(http.StatusBadRequest, "cluster(%s) not found", xcluster) - return + ginx.Bomb(http.StatusBadRequest, "cluster(%s) not found", xcluster) } var lst []model.Value @@ -59,15 +53,12 @@ func promBatchQueryRange(c *gin.Context) { } resp, _, err := cluster.PromClient.QueryRange(context.Background(), item.Query, r) - if err != nil { - c.String(500, err.Error()) - return - } + ginx.Dangerous(err) lst = append(lst, resp) } - c.JSON(200, lst) + ginx.NewRender(c).Data(lst, nil) } func prometheusProxy(c *gin.Context) {