diff --git a/plugin/api/alerting/rule.go b/plugin/api/alerting/rule.go index 45e81f44..aa2ce41e 100644 --- a/plugin/api/alerting/rule.go +++ b/plugin/api/alerting/rule.go @@ -5,6 +5,7 @@ package alerting import ( + "errors" "fmt" log "github.com/cihub/seelog" "github.com/r3labs/diff/v2" @@ -21,6 +22,7 @@ import ( "infini.sh/framework/core/queue" "infini.sh/framework/core/task" "infini.sh/framework/core/util" + elastic2 "infini.sh/framework/modules/elastic" "infini.sh/framework/modules/elastic/api" "infini.sh/framework/modules/elastic/common" "net/http" @@ -109,13 +111,17 @@ func (alertAPI *AlertAPI) getRule(w http.ResponseWriter, req *http.Request, ps h obj := alerting.Rule{} obj.ID = id - exists, err := orm.Get(&obj) - if !exists || err != nil { + _, err := orm.Get(&obj) + if err != nil { + if errors.Is(err, elastic2.ErrNotFound){ + alertAPI.WriteJSON(w, util.MapStr{ + "_id": id, + "found": false, + }, http.StatusNotFound) + return + } log.Error(err) - alertAPI.WriteJSON(w, util.MapStr{ - "_id": id, - "found": false, - }, http.StatusNotFound) + alertAPI.WriteError(w, err.Error(), http.StatusInternalServerError) return } @@ -134,11 +140,15 @@ func (alertAPI *AlertAPI) getRuleDetail(w http.ResponseWriter, req *http.Request exists, err := orm.Get(&obj) if !exists || err != nil { + if errors.Is(err, elastic2.ErrNotFound){ + alertAPI.WriteJSON(w, util.MapStr{ + "_id": id, + "found": false, + }, http.StatusNotFound) + return + } log.Error(err) - alertAPI.WriteJSON(w, util.MapStr{ - "_id": id, - "found": false, - }, http.StatusNotFound) + alertAPI.WriteError(w, err.Error(), http.StatusInternalServerError) return } metricExpression, _ := obj.Metrics.GenerateExpression() diff --git a/plugin/migration/api.go b/plugin/migration/api.go index 9cc5274f..e988ef76 100644 --- a/plugin/migration/api.go +++ b/plugin/migration/api.go @@ -289,12 +289,12 @@ func (h *APIHandler) stopDataMigrationTask(w http.ResponseWriter, req *http.Requ }, http.StatusNotFound) return } - if task2.IsEnded(obj.Status) { - h.WriteJSON(w, util.MapStr{ - "success": true, - }, 200) - return - } + //if task2.IsEnded(obj.Status) { + // h.WriteJSON(w, util.MapStr{ + // "success": true, + // }, 200) + // return + //} //query all pipeline task(scroll/bulk_indexing) and then stop it err = stopPipelineTasks(id) if err != nil {