Skip to content

Commit

Permalink
Merge pull request #1493 from holden-cpu/dev
Browse files Browse the repository at this point in the history
[fix] Add sync connection status
  • Loading branch information
humingcheng authored Nov 22, 2024
2 parents b76d2fc + feadce1 commit b0ed15b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions syncer/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
)

const (
HealthStatusConnected = "CONNECTED"
HealthStatusAbnormal = "ABNORMAL"
HealthStatusClose = "CLOSE"
HealthStatusAuthFail = "AuthFail"
HealthStatusConnected = "CONNECTED"
HealthStatusAbnormal = "ABNORMAL"
HealthStatusClose = "CLOSE"
HealthStatusAuthFail = "AuthFail"
HealthStatusPeerUnimplemented = "UNIMPLEMENTED"

RbacAllowedAccountName = "sync-user"
RbacAllowedRoleName = "sync-admin"
Expand Down
12 changes: 11 additions & 1 deletion syncer/service/admin/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (

"github.com/go-chassis/go-chassis/v2/server/restful"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"github.com/apache/servicecomb-service-center/client"
"github.com/apache/servicecomb-service-center/pkg/log"
Expand Down Expand Up @@ -136,10 +138,18 @@ func getPeerStatus(peerInfo *PeerInfo) string {
}))
}
reply, err := set.EventServiceClient.Health(ctx, &v1sync.HealthRequest{})
if err != nil || reply == nil {
if err != nil {
if s, ok := status.FromError(err); ok && s.Code() == codes.Unimplemented {
log.Error("get peer health failed", err)
return rpc.HealthStatusPeerUnimplemented
}
log.Error("get peer health failed", err)
return rpc.HealthStatusAbnormal
}
if reply == nil {
log.Error("get peer health failed, reply is nil, but no error", err)
return rpc.HealthStatusAbnormal
}
reportClockDiff(peerInfo.Peer.Name, local, reply.LocalTimestamp)
return reply.Status
}
Expand Down

0 comments on commit b0ed15b

Please sign in to comment.