fix getting alerting rule 404

This commit is contained in:
liugq 2023-04-03 18:05:27 +08:00
parent abe7acf177
commit 272f29403d
2 changed files with 26 additions and 16 deletions

View File

@ -5,6 +5,7 @@
package alerting package alerting
import ( import (
"errors"
"fmt" "fmt"
log "github.com/cihub/seelog" log "github.com/cihub/seelog"
"github.com/r3labs/diff/v2" "github.com/r3labs/diff/v2"
@ -21,6 +22,7 @@ import (
"infini.sh/framework/core/queue" "infini.sh/framework/core/queue"
"infini.sh/framework/core/task" "infini.sh/framework/core/task"
"infini.sh/framework/core/util" "infini.sh/framework/core/util"
elastic2 "infini.sh/framework/modules/elastic"
"infini.sh/framework/modules/elastic/api" "infini.sh/framework/modules/elastic/api"
"infini.sh/framework/modules/elastic/common" "infini.sh/framework/modules/elastic/common"
"net/http" "net/http"
@ -109,13 +111,17 @@ func (alertAPI *AlertAPI) getRule(w http.ResponseWriter, req *http.Request, ps h
obj := alerting.Rule{} obj := alerting.Rule{}
obj.ID = id obj.ID = id
exists, err := orm.Get(&obj) _, err := orm.Get(&obj)
if !exists || err != nil { if err != nil {
if errors.Is(err, elastic2.ErrNotFound){
alertAPI.WriteJSON(w, util.MapStr{
"_id": id,
"found": false,
}, http.StatusNotFound)
return
}
log.Error(err) log.Error(err)
alertAPI.WriteJSON(w, util.MapStr{ alertAPI.WriteError(w, err.Error(), http.StatusInternalServerError)
"_id": id,
"found": false,
}, http.StatusNotFound)
return return
} }
@ -134,11 +140,15 @@ func (alertAPI *AlertAPI) getRuleDetail(w http.ResponseWriter, req *http.Request
exists, err := orm.Get(&obj) exists, err := orm.Get(&obj)
if !exists || err != nil { 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) log.Error(err)
alertAPI.WriteJSON(w, util.MapStr{ alertAPI.WriteError(w, err.Error(), http.StatusInternalServerError)
"_id": id,
"found": false,
}, http.StatusNotFound)
return return
} }
metricExpression, _ := obj.Metrics.GenerateExpression() metricExpression, _ := obj.Metrics.GenerateExpression()

View File

@ -289,12 +289,12 @@ func (h *APIHandler) stopDataMigrationTask(w http.ResponseWriter, req *http.Requ
}, http.StatusNotFound) }, http.StatusNotFound)
return return
} }
if task2.IsEnded(obj.Status) { //if task2.IsEnded(obj.Status) {
h.WriteJSON(w, util.MapStr{ // h.WriteJSON(w, util.MapStr{
"success": true, // "success": true,
}, 200) // }, 200)
return // return
} //}
//query all pipeline task(scroll/bulk_indexing) and then stop it //query all pipeline task(scroll/bulk_indexing) and then stop it
err = stopPipelineTasks(id) err = stopPipelineTasks(id)
if err != nil { if err != nil {