From 7d774562c729011c51ca129f7d41125d3578d24f Mon Sep 17 00:00:00 2001 From: 710leo <710leo@gmail.com> Date: Thu, 7 May 2020 22:16:35 +0800 Subject: [PATCH] Add delete index by endpoint api --- src/modules/index/cache/endpoint_map.go | 7 +++++++ src/modules/index/http/routes/index_router.go | 15 +++++++++++++++ src/modules/index/http/routes/routes.go | 1 + 3 files changed, 23 insertions(+) diff --git a/src/modules/index/cache/endpoint_map.go b/src/modules/index/cache/endpoint_map.go index d63dcac0..75959784 100644 --- a/src/modules/index/cache/endpoint_map.go +++ b/src/modules/index/cache/endpoint_map.go @@ -133,3 +133,10 @@ func (e *EndpointIndexMap) GetEndpoints() []string { } return ret } + +func (e *EndpointIndexMap) DelByEndpoint(endpoint string) { + e.Lock() + defer e.Unlock() + + delete(e.M, endpoint) +} diff --git a/src/modules/index/http/routes/index_router.go b/src/modules/index/http/routes/index_router.go index dfab06e5..6188d359 100644 --- a/src/modules/index/http/routes/index_router.go +++ b/src/modules/index/http/routes/index_router.go @@ -40,6 +40,21 @@ func GetMetrics(c *gin.Context) { render.Data(c, resp, nil) } +type EndpointRecv struct { + Endpoints []string `json:"endpoints"` +} + +func DelIdxByEndpoint(c *gin.Context) { + recv := EndpointRecv{} + errors.Dangerous(c.ShouldBindJSON(&recv)) + + for _, endpoint := range recv.Endpoints { + cache.IndexDB.DelByEndpoint(endpoint) + } + + render.Data(c, "ok", nil) +} + type EndpointMetricRecv struct { Endpoints []string `json:"endpoints"` Metrics []string `json:"metrics"` diff --git a/src/modules/index/http/routes/routes.go b/src/modules/index/http/routes/routes.go index 7bff4f7d..c99e0246 100644 --- a/src/modules/index/http/routes/routes.go +++ b/src/modules/index/http/routes/routes.go @@ -16,6 +16,7 @@ func Config(r *gin.Engine) { sys.POST("/metrics", GetMetrics) sys.DELETE("/metrics", DelMetrics) + sys.DELETE("/endpoints", DelIdxByEndpoint) sys.DELETE("/counter", DelCounter) sys.POST("/tagkv", GetTagPairs) sys.POST("/counter/fullmatch", GetIndexByFullTags)