Skip to content

Commit

Permalink
feat: logging for ping result
Browse files Browse the repository at this point in the history
  • Loading branch information
erayarslan committed Jun 4, 2024
1 parent cdae629 commit 5205200
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions couchbase/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ func getServiceEndpoint(result *gocbcore.PingResult, serviceType gocbcore.Servic
return ""
}

func printLatenciesOfServiceEndpoints(result *gocbcore.PingResult) {
for serviceType, service := range result.Services {
for _, serviceResult := range service {
if serviceResult.Error == nil {
logger.Log.Debug(
"ping result for serviceType(memd,mgmt): %v, endpoint: %v, latency: %vms, state(ok,timeout,err): %v",
serviceType, serviceResult.Endpoint, serviceResult.Latency.Milliseconds(), serviceResult.State,
)
} else {
logger.Log.Warn(
"ping result get err for serviceType(memd,mgmt): %v, endpoint: %v, latency: %vms, state(ok,timeout,err): %v, err: %v",
serviceType, serviceResult.Endpoint, serviceResult.Latency.Milliseconds(), serviceResult.State, serviceResult.Error.Error(),
)
}
}
}
}

func (s *client) Ping() (*models.PingResult, error) {
ctx, cancel := context.WithTimeout(context.Background(), s.config.HealthCheck.Timeout)
defer cancel()
Expand All @@ -81,6 +99,10 @@ func (s *client) Ping() (*models.PingResult, error) {
if err == nil {
pingResult.MemdEndpoint = getServiceEndpoint(result, gocbcore.MemdService)
pingResult.MgmtEndpoint = getServiceEndpoint(result, gocbcore.MgmtService)

if result != nil {
printLatenciesOfServiceEndpoints(result)
}
}

if pingResult.MemdEndpoint == "" || pingResult.MgmtEndpoint == "" {
Expand Down

0 comments on commit 5205200

Please sign in to comment.