Skip to content

core-go/health

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Health Check in Microservices

Health Check Definition

A health check in microservices is a mechanism that ensures each service is functioning correctly and is available. It typically involves periodically checking the status of various components of a service and reporting their health.

health

Use Cases of Health Check

Service Availability Monitoring:

  • Scenario: Ensuring that each microservice is up and running.
  • Benefit: Helps in quickly identifying and addressing service outages.

Dependency Checking

  • Scenario: Verifying that all dependencies of a service are available and functioning.
  • Benefit: Ensures the entire application stack is healthy and operational.

Deployment Validation

  • Scenario: Checking the health of services post-deployment to ensure they are functioning as expected.
  • Benefit: Detects deployment issues early, preventing faulty services from affecting the system.

Load Balancing

  • Scenario: Directing traffic only to healthy instances of a service.
  • Benefit: Ensures reliable service delivery by avoiding unhealthy instances.

Auto-scaling

  • Scenario: Scaling up or down based on the health and load of the services.
  • Benefit: Optimizes resource usage and cost efficiency.

Implementation

Tools

  • Spring Boot Actuator, AWS Elastic Load Balancer, Kubernetes liveness and readiness probes

Endpoints:

  • Health check endpoints (e.g., /health, /status) that return the health status of the service.

API Design:

  • Request: GET /health
  • Response:
    {
      "status": "DOWN",
      "details": {
        "sql": {
          "status": "DOWN",
          "data": {
            "error": "pq: database 'demo' does not exist"
          }
        },
        "firestore": {
          "status": "UP"
        },
        "kafka": {
          "status": "UP"
        }
      }
    }

Health Status

  • UP: Indicates that the application is functioning normally and all health checks have passed.
  • DOWN: Indicates that the application is experiencing issues, and one or more health checks have failed.

Implementation of core-go/health

Core Library

  • Purpose: Provides basic health check functionalities
  • Features:
    • Define standard health check interfaces.

      • Model Health
        package health
        
        type Health struct {
          Status  string                 `json:"status,omitempty"`
          Data    map[string]interface{} `json:"data,omitempty"`
          Details map[string]Health      `json:"details,omitempty"`
        }
    • Allow custom health checks with this standard interface Checker:

package health

import "context"

type Checker interface {
  Name() string
  Check(ctx context.Context) (map[string]interface{}, error)
  Build(ctx context.Context, data map[string]interface{}, err error) map[string]interface{}
}
  • Build the response JSON from many custom health checks by this GO function Check
  • Implement basic checks
  • Integration with Existing Systems, by supporting these Go libraries: gin, echo, mux, go-chi

External Service Health Check Library

Cache Health Check Library

Database Health Check Libraries

Message Queue Health Check Libraries

Future Libraries to develop

Cluster Health Check Library

  • Purpose: Ensures the health of the microservices cluster.
  • Features:
    • Check node status, CPU, and memory usage across the cluster.
    • Integrate with orchestration platforms like Kubernetes for liveness and readiness probes.

Metrics and Monitoring Integration Library

  • Purpose: Integrates health checks with monitoring tools.
  • Features:
    • Export health check results to monitoring systems (Prometheus, Grafana, ELK stack).
    • Provide detailed dashboards and alerting mechanisms.

Notification and Alerting Library

  • Purpose: Sends alerts based on health check results.
  • Features:
    • Integrate with notification systems (Slack, PagerDuty, email).
    • Provide configurable thresholds and alerting rules.

Integration with Existing Systems

Benefits and Challenges:

Benefits:

  • Improved Reliability: Continuous monitoring of services ensures quick detection and resolution of issues.
  • Scalability: Supports growth by maintaining health across distributed systems.
  • Better Resource Management: Helps optimize resource usage and prevent failures.

Challenges:

  • Overhead: Adding health checks can introduce some performance overhead.
  • Complexity: Requires careful planning and integration to avoid false positives and negatives.
  • Maintenance: Health check implementations need regular updates to stay relevant and effective.

Appendix

Health Check for nodejs

Database Health Check Libraries

Message Queue Health Check Libraries

Integration with Existing Systems

Installation

Please make sure to initialize a Go module before installing core-go/health:

go get -u github.com/core-go/health

Import:

import "github.com/core-go/health"