diff --git a/apiserver/eurekaserver/applications.go b/apiserver/eurekaserver/applications.go index feeb6b514..5e561ac74 100644 --- a/apiserver/eurekaserver/applications.go +++ b/apiserver/eurekaserver/applications.go @@ -128,8 +128,10 @@ func (a *ApplicationsBuilder) BuildApplications(oldAppsCache *ApplicationsRespCa hashBuilder[status] = hashBuilder[status] + count } } - newApps.Application = append(newApps.Application, targetApp) - newApps.ApplicationMap[targetApp.Name] = targetApp + if len(targetApp.Instance) > 0 { + newApps.Application = append(newApps.Application, targetApp) + newApps.ApplicationMap[targetApp.Name] = targetApp + } } if oldApps != nil && len(oldApps.Application) != len(newApps.Application) { changed = true @@ -244,7 +246,7 @@ func (a *ApplicationsBuilder) buildDeltaApps(oldAppsCache *ApplicationsRespCache } // 修改,需要比较实例的变更 diffApp := diffApplication(oldApplication, application) - if diffApp != nil { + if diffApp != nil && len(diffApp.Instance) > 0 { newDeltaApps.Application = append(newDeltaApps.Application, diffApp) instCount += len(diffApp.Instance) } diff --git a/apiserver/eurekaserver/replicate.go b/apiserver/eurekaserver/replicate.go index 9cf2f2e61..2f39731f7 100644 --- a/apiserver/eurekaserver/replicate.go +++ b/apiserver/eurekaserver/replicate.go @@ -76,6 +76,13 @@ func (h *EurekaServer) BatchReplication(req *restful.Request, rsp *restful.Respo writeHeader(http.StatusForbidden, rsp) return } + batchResponse, resultCode := h.doBatchReplicate(replicateRequest, token) + if err := writeEurekaResponseWithCode(restful.MIME_JSON, batchResponse, req, rsp, resultCode); nil != err { + log.Errorf("[EurekaServer]fail to write replicate response, client: %s, err: %v", remoteAddr, err) + } +} + +func (h *EurekaServer) doBatchReplicate(replicateRequest *ReplicationList, token string) (*ReplicationListResponse, uint32) { batchResponse := &ReplicationListResponse{ResponseList: []*ReplicationInstanceResponse{}} var resultCode = api.ExecuteSuccess for _, instanceInfo := range replicateRequest.ReplicationList { @@ -87,9 +94,7 @@ func (h *EurekaServer) BatchReplication(req *restful.Request, rsp *restful.Respo } batchResponse.ResponseList = append(batchResponse.ResponseList, resp) } - if err := writeEurekaResponseWithCode(restful.MIME_JSON, batchResponse, req, rsp, resultCode); nil != err { - log.Errorf("[EurekaServer]fail to write replicate response, client: %s, err: %v", remoteAddr, err) - } + return batchResponse, resultCode } func (h *EurekaServer) dispatch(replicationInstance *ReplicationInstance, token string) (*ReplicationInstanceResponse, uint32) { diff --git a/apiserver/eurekaserver/replicate_worker.go b/apiserver/eurekaserver/replicate_worker.go index bc2387c33..970fa9f7c 100644 --- a/apiserver/eurekaserver/replicate_worker.go +++ b/apiserver/eurekaserver/replicate_worker.go @@ -106,6 +106,7 @@ func (r *ReplicateWorker) doBatchReplicate(tasks []*ReplicationInstance) { for _, task := range tasks { replicateInfo = append(replicateInfo, fmt.Sprintf("%s:%s", task.Action, task.Id)) } + log.Infof("start to send replicate text %s, peers %v", string(jsonData), r.peers) for _, peer := range r.peers { go r.doReplicateToPeer(peer, tasks, jsonData, replicateInfo) } @@ -158,6 +159,7 @@ func sendHttpRequest(peer string, jsonData []byte, replicateInfo []string) (*Rep log.Errorf("[EUREKA-SERVER] fail to send replicate request: %v", err) return nil, err } + defer response.Body.Close() respStr, _ := io.ReadAll(response.Body) respObj := &ReplicationListResponse{} err = json.Unmarshal(respStr, respObj) @@ -165,7 +167,6 @@ func sendHttpRequest(peer string, jsonData []byte, replicateInfo []string) (*Rep log.Errorf("[EUREKA-SERVER] fail unmarshal text %s to ReplicationListResponse: %v", string(respStr), err) return nil, err } - _ = response.Body.Close() log.Infof("[EUREKA-SERVER] success to replicate to %s, instances %v", peer, replicateInfo) return respObj, nil } diff --git a/service/healthcheck/report.go b/service/healthcheck/report.go index d430a8ac4..21074dfda 100644 --- a/service/healthcheck/report.go +++ b/service/healthcheck/report.go @@ -79,7 +79,7 @@ func (s *Server) doReport(ctx context.Context, instance *api.Instance) *api.Resp event := &model.InstanceEvent{ Id: ins.ID(), - Instance: instance, + Instance: ins.Proto, EType: model.EventInstanceSendHeartbeat, } event.InjectMetadata(ctx)