improvement: retain a single instance when registering duplicate endp… (#163)
* improvement: retain a single instance when registering duplicate endpoints * chore: update release notes
This commit is contained in:
parent
d851be6a38
commit
a0d28fada9
|
@ -30,6 +30,7 @@ Information about release notes of INFINI Console is provided here.
|
|||
- Enhance LDAP authentication logging (#156)
|
||||
- Optimize UI for copying metric requests (#155)
|
||||
- Enhance deletion tips by adding cluster info for indices
|
||||
- Retain a single instance when registering duplicate endpoints (#163)
|
||||
|
||||
## 1.28.2 (2025-02-15)
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ title: "版本历史"
|
|||
- 增强 LDAP 身份验证的日志记录 (#156)
|
||||
- 优化监控报表里拷贝指标请求的 UI (#155)
|
||||
- 删除索引提示增加集群信息 (#162)
|
||||
- 自动注册实例时相同 endpoint 的实例不再重复注册 (#163)
|
||||
|
||||
## 1.28.2 (2025-02-15)
|
||||
|
||||
|
|
|
@ -85,6 +85,11 @@ func (h APIHandler) registerInstance(w http.ResponseWriter, req *http.Request, p
|
|||
err := h.DecodeJSON(req, obj)
|
||||
if err != nil {
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if obj.Endpoint == "" {
|
||||
h.WriteError(w, "empty endpoint", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
oldInst := &model.Instance{}
|
||||
|
@ -95,8 +100,28 @@ func (h APIHandler) registerInstance(w http.ResponseWriter, req *http.Request, p
|
|||
h.WriteError(w, errMsg, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = orm.Create(nil, obj)
|
||||
err, result := orm.GetBy("endpoint", obj.Endpoint, oldInst)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(result.Result) > 0 {
|
||||
buf := util.MustToJSONBytes(result.Result[0])
|
||||
util.MustFromJSONBytes(buf, &oldInst)
|
||||
if oldInst.ID != "" {
|
||||
//keep old created time
|
||||
obj.Created = oldInst.Created
|
||||
log.Infof("remove old instance [%s] with the same endpoint %s", oldInst.ID, oldInst.Endpoint)
|
||||
err = orm.Delete(nil, oldInst)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
err = orm.Save(nil, obj)
|
||||
if err != nil {
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue