Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: retain a single instance when registering duplicate endp… #163

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content.en/docs/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions docs/content.zh/docs/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ title: "版本历史"
- 增强 LDAP 身份验证的日志记录 (#156)
- 优化监控报表里拷贝指标请求的 UI (#155)
- 删除索引提示增加集群信息 (#162)
- 自动注册实例时相同 endpoint 的实例不再重复注册 (#163)

## 1.28.2 (2025-02-15)

Expand Down
29 changes: 27 additions & 2 deletions plugin/managed/server/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
Expand Down
Loading