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:
silenceqi 2025-02-24 11:20:45 +08:00 committed by GitHub
parent d851be6a38
commit a0d28fada9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View File

@ -30,6 +30,7 @@ Information about release notes of INFINI Console is provided here.
- Enhance LDAP authentication logging (#156) - Enhance LDAP authentication logging (#156)
- Optimize UI for copying metric requests (#155) - Optimize UI for copying metric requests (#155)
- Enhance deletion tips by adding cluster info for indices - Enhance deletion tips by adding cluster info for indices
- Retain a single instance when registering duplicate endpoints #163
## 1.28.2 (2025-02-15) ## 1.28.2 (2025-02-15)

View File

@ -30,6 +30,7 @@ title: "版本历史"
- 增强 LDAP 身份验证的日志记录 (#156) - 增强 LDAP 身份验证的日志记录 (#156)
- 优化监控报表里拷贝指标请求的 UI (#155) - 优化监控报表里拷贝指标请求的 UI (#155)
- 删除索引提示增加集群信息 (#162) - 删除索引提示增加集群信息 (#162)
- 自动注册实例时相同 endpoint 的实例不再重复注册 (#163)
## 1.28.2 (2025-02-15) ## 1.28.2 (2025-02-15)

View File

@ -85,6 +85,11 @@ func (h APIHandler) registerInstance(w http.ResponseWriter, req *http.Request, p
err := h.DecodeJSON(req, obj) err := h.DecodeJSON(req, obj)
if err != nil { if err != nil {
h.WriteError(w, err.Error(), http.StatusInternalServerError) h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
if obj.Endpoint == "" {
h.WriteError(w, "empty endpoint", http.StatusInternalServerError)
return
} }
oldInst := &model.Instance{} oldInst := &model.Instance{}
@ -95,8 +100,28 @@ func (h APIHandler) registerInstance(w http.ResponseWriter, req *http.Request, p
h.WriteError(w, errMsg, http.StatusInternalServerError) h.WriteError(w, errMsg, http.StatusInternalServerError)
return return
} }
err, result := orm.GetBy("endpoint", obj.Endpoint, oldInst)
err = orm.Create(nil, obj) 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 { if err != nil {
h.WriteError(w, err.Error(), http.StatusInternalServerError) h.WriteError(w, err.Error(), http.StatusInternalServerError)
return return