Health Check

Health Check

Background

Dubbo-go has a built-in health check service based on the triple protocol to help users manage and monitor the health status of services. You can view the complete example source code here.

Usage

  • The framework automatically registers the health check service grpc.health.v1.Health into the framework after starting via instance, which records and exposes the health status of each triple service.
  • The health check service can check the status of services in the framework by making an HTTP request or through client calls to the health check service. The interface called is grpc.health.v1.Health, and the method is check.

1. Call the health check service through the client

Start the service in dubbo-go-samples/healthcheck/go-server, and the status of greet.GreetService can be viewed through the client below.

  1. package main
  2. import (
  3. "context"
  4. "dubbo.apache.org/dubbo-go/v3/client"
  5. _ "dubbo.apache.org/dubbo-go/v3/imports"
  6. health "dubbo.apache.org/dubbo-go/v3/protocol/triple/health/triple_health"
  7. "github.com/dubbogo/gost/log/logger"
  8. )
  9. func main() {
  10. cli, err := client.NewClient(
  11. client.WithClientURL("tri://127.0.0.1:20000"),
  12. )
  13. if err != nil {
  14. panic(err)
  15. }
  16. svc, err := health.NewHealth(cli)
  17. if err != nil {
  18. panic(err)
  19. }
  20. check, err := svc.Check(context.Background(), &health.HealthCheckRequest{Service: "greet.GreetService"})
  21. if err != nil {
  22. logger.Error(err)
  23. } else {
  24. logger.Info("greet.GreetService's health", check.String())
  25. }
  26. watch, err := svc.Watch(context.Background(), &health.HealthCheckRequest{Service: "greet.GreetService"})
  27. if err != nil {
  28. logger.Error(err)
  29. } else {
  30. if watch.Recv() {
  31. logger.Info("greet.GreetService's health", watch.Msg().String())
  32. }
  33. }
  34. }

Once started, the following output will appear

  1. [greet.GreetService's health status:SERVING]
  2. [greet.GreetService's health status:SERVING]

2. Check the health status of the service by making an HTTP request

Start the service in dubbo-go-samples/healthcheck/go-server, and make the HTTP request below to view the status of greet.GreetService:

  1. POST /grpc.health.v1.Health/Check
  2. Host: 127.0.0.1:20000
  3. Content-Type: application/json
  4. {"service":"greet.GreetService"}

The following output will appear

  1. {
  2. "status": "SERVING"
  3. }

More Content

It is worth noting that the current framework does not yet establish a complete service status management mechanism. The dubbo-go framework will set all loaded services to SERVING status, but there is currently no NOT SERVING setting mechanism (to set the service status to NOT SERVING under a specific condition).

If necessary, users can extend the dubbo-go framework to provide complete service status management capabilities, allowing for real-time updated service status queries and traffic forwarding based on service status.

Reference materials:

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)