• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gatewayd-io / gatewayd / 12458569615

22 Dec 2024 11:28PM UTC coverage: 62.62% (+0.2%) from 62.449%
12458569615

push

github

web-flow
Add Raft Node Support for Health Checks and Metrics Collection (#643)

* Add Raft health monitoring and metrics

Add functionality to monitor Raft node health status and expose key metrics:
- Add new Prometheus metrics for Raft health status, leader status, and last contact latency
- Implement GetHealthStatus() method to track node health state
- Monitor leadership status and communication with leader
- Track last contact time with leader
- Add helper functions for metric value conversion and time parsing

The metrics will help monitor cluster health and leadership changes in production.

* feat: Integrate Raft node health checks into API

- Added Raft node dependency to `Options` and `HealthChecker` structs.
- Updated `liveness` function to include Raft node health status.
- Modified health check logic in `healthcheck.go` and `http_server.go` to consider Raft node status.
- Enhanced `healthcheck_test.go` to include tests for Raft node integration.
- Ensured Raft node is properly initialized and cleaned up in tests.

* Add TestGetHealthStatus to verify Raft node health

- Introduced a new test `TestGetHealthStatus` to check the health status of Raft nodes.
- The test covers three scenarios:
  1. When the node is the leader, it should be healthy and recognize itself as the leader.
  2. When the node is a follower, it should be healthy and recognize the leader.
  3. When no leader is available, the node should not be healthy and should report an error.
- Utilized temporary directories and a test logger for setup.
- Ensured proper shutdown of nodes after tests to prevent resource leaks.

* fix lint issues

- Corrected variable naming from `leaderId` to `leaderID` for consistency.
- Added missing periods to comments for proper punctuation.
- Used `%w` in `fmt.Errorf` for error wrapping.

* Add RaftNode to API configuration in run command

- Updated the `runCmd` in `cmd/run.go` to include `RaftNode` in the API configuration.
- This change ensures that the ... (continued)

55 of 64 new or added lines in 5 files covered. (85.94%)

5 existing lines in 1 file now uncovered.

5096 of 8138 relevant lines covered (62.62%)

17.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/api/utils.go
1
package api
2

3
import (
4
        "github.com/gatewayd-io/gatewayd/network"
5
        "github.com/gatewayd-io/gatewayd/raft"
6
)
7

8
func liveness(servers map[string]*network.Server, raftNode *raft.Node) bool {
3✔
9
        for _, v := range servers {
6✔
10
                if !v.IsRunning() {
5✔
11
                        return false
2✔
12
                }
2✔
13
        }
14
        if raftNode != nil {
2✔
15
                if !raftNode.GetHealthStatus().IsHealthy {
1✔
NEW
16
                        return false
×
NEW
17
                }
×
18
        }
19
        return true
1✔
20
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc