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.
- You can refer to Microservice Health Check at my Linked In for more details.
- Scenario: Ensuring that each microservice is up and running.
- Benefit: Helps in quickly identifying and addressing service outages.
- Scenario: Verifying that all dependencies of a service are available and functioning.
- Benefit: Ensures the entire application stack is healthy and operational.
- 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.
- Scenario: Directing traffic only to healthy instances of a service.
- Benefit: Ensures reliable service delivery by avoiding unhealthy instances.
- Scenario: Scaling up or down based on the health and load of the services.
- Benefit: Optimizes resource usage and cost efficiency.
- Spring Boot Actuator, AWS Elastic Load Balancer, Kubernetes liveness and readiness probes
- Health check endpoints (e.g., /health, /status) that return the health status of the service.
- Request: GET /health
- Response:
{ "status": "DOWN", "details": { "sql": { "status": "DOWN", "data": { "error": "pq: database 'demo' does not exist" } }, "firestore": { "status": "UP" }, "kafka": { "status": "UP" } } }
- 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
- 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"` }
- Model Health
-
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
- Purpose: Monitors the availability of external services.
- Features:
- Check HTTP/HTTPS endpoints for expected responses.
- http client. The sample is at go-sql-hexagonal-architecture-sample.
- Measure response time and reliability.
- Check HTTP/HTTPS endpoints for expected responses.
- Purpose: Verifies the status of cache services.
- Features:
- Check connectivity to cache servers (Redis, Memcached).
- Redis:
- go-redis/redis to support redis/go-redis. The sample is at go-admin.
- garyburd/redigo to support gomodule/redigo.
- Redis:
- Validate cache hit/miss ratio and performance metrics.
- Check connectivity to cache servers (Redis, Memcached).
- Purpose: Monitors the health of database connections
- Features:
- Check connectivity and response time for various databases (SQL, NoSQL).
- sql. The sample is at go-sql-sample.
- mongo to support mongo-driver/mongo. The sample is at go-mongo-sample.
- dynamodb to support aws/aws-sdk-go/service/dynamodb. The sample is at go-dynamodb-tutorial.
- firestore to support go/firestore. The sample is at go-firestore-sample.
- elasticsearch to support elastic/go-elasticsearch. The sample is at go-elasticsearch-sample.
- cassandra to support apache/cassandra-gocql-driver. The sample is at go-cassandra-sample.
- hive to support beltran/gohive. The sample is at go-hive-sample.
- Provide detailed status messages and error handling.
- Check connectivity and response time for various databases (SQL, NoSQL).
- Purpose: Ensures message queues are operational.
- Features:
- Check connectivity and queue depth for different message brokers.
- Amazon SQS: support aws-sdk-go/service/sqs. The sample is at go-amazon-sqs-sample.
- Google Pub/Sub: support go/pubsub. The sample is at go-pubsub-sample.
- Kafka: support 3 GO libraries: segmentio/kafka-go, IBM/sarama and confluent. The sample is at go-kafka-sample.
- NATS: support nats.go. The sample is at go-nats-sample.
- Active MQ: support go-stomp. The sample is at go-active-mq-sample.
- RabbitMQ: support rabbitmq/amqp091-go. The sample is at go-rabbit-mq-sample.
- IBM MQ: support ibmmq. The sample is at go-ibm-mq-sample.
- Monitor message lag and processing time (Not yet implemented)
- Check connectivity and queue depth for different message brokers.
- 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.
- 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.
- Purpose: Sends alerts based on health check results.
- Features:
- Integrate with notification systems (Slack, PagerDuty, email).
- Provide configurable thresholds and alerting rules.
- Designed to integrate seamlessly with existing Go libraries: Gorilla mux, Go-chi, Echo and Gin.
- handler, to support Gorilla mux and Go-chi. The sample is at go-sql-sample.
- echo handler to support Echo. The sample is at go-sql-echo-sample.
- gin handler to support Gin. The sample is at go-sql-gin-sample.
- 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.
- 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.
- Redis: redis-plus, to support redis.
- Mongo: mongodb-extension, to support mongodb. The sample is at mongo-modular-sample.
- My SQL: mysql2-core, to support mysql2. The sample is at sql-modular-sample.
- Oracle: oracle-core, to support oracledb.
- Postgres: pg-extension, to support pg.
- MS SQL: mssql-core, to support mssql.
- SQLite: sqlite3-core to support sqlite3.
- Kafka: kafka-plus, to support kafkajs. The sample is at kafka-sample.
- RabbitMQ: rabbitmq-ext, to support amqplib. The sample is at rabbitmq-sample.
- Google Pub/Sub: google-pubsub, to support @google-cloud/pubsub. The sample is at pubsub-sample
- IBM MQ: ibmmq-plus, to support ibmmq. The sample is at ibmmq-sample.
- Active MQ: activemq, to support amqplib. The sample is at activemq-sample.
- NATS: nats-plus, to support nats. The sample is at nats-sample.
- for nodejs, we have express-ext to integrate with express. The sample is at is at mongo-modular-sample.
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"