Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partitions in health checks #129

Merged
merged 8 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions rest/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type HealthCheck interface {
// ServiceName returns the name of the service that is health checked.
ServiceName() string
// Check is a function returning a service status and an error.
Check(ctx context.Context) (HealthStatus, error)
Check(ctx context.Context) (HealthStatus, []string, error)
Gerrit91 marked this conversation as resolved.
Show resolved Hide resolved
}

// HealthResponse is returned by the API when executing a health check.
Expand All @@ -51,6 +51,8 @@ type HealthResult struct {
Status HealthStatus `json:"status"`
// Message gives additional information on the health of a service.
Message string `json:"message"`
// Services is map of partitions by name with their individual health results.
UnhealthyPartitions []string `json:"unhealthy-partitions"`
}

type healthResource struct {
Expand Down Expand Up @@ -139,16 +141,17 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo
result := chanResult{
name: name,
HealthResult: HealthResult{
Status: HealthStatusHealthy,
Message: "",
Status: HealthStatusHealthy,
Message: "",
UnhealthyPartitions: []string{},
},
}
defer func() {
resultChan <- result
}()

var err error
result.Status, err = healthCheck.Check(ctx)
result.Status, result.UnhealthyPartitions, err = healthCheck.Check(ctx)
if err != nil {
result.Message = err.Error()
h.log.Errorw("unhealthy service", "name", name, "status", result.Status, "error", err)
Expand Down
23 changes: 13 additions & 10 deletions rest/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (e *succeedingCheck) ServiceName() string {
return "success"
}

func (e *succeedingCheck) Check(ctx context.Context) (HealthStatus, error) {
return HealthStatusHealthy, nil
func (e *succeedingCheck) Check(ctx context.Context) (HealthStatus, []string, error) {
return HealthStatusHealthy, []string{}, nil
}

type failingCheck struct{}
Expand All @@ -29,8 +29,8 @@ func (e *failingCheck) ServiceName() string {
return "fail"
}

func (e *failingCheck) Check(ctx context.Context) (HealthStatus, error) {
return HealthStatusUnhealthy, fmt.Errorf("facing an issue")
func (e *failingCheck) Check(ctx context.Context) (HealthStatus, []string, error) {
return HealthStatusUnhealthy, []string{"fail"}, fmt.Errorf("facing an issue")
}

func TestNewHealth(t *testing.T) {
Expand Down Expand Up @@ -73,12 +73,14 @@ func TestNewHealth(t *testing.T) {
Message: "facing an issue",
Services: map[string]HealthResult{
"success": {
Status: HealthStatusHealthy,
Message: "",
Status: HealthStatusHealthy,
Message: "",
UnhealthyPartitions: []string{},
},
"fail": {
Status: HealthStatusUnhealthy,
Message: "facing an issue",
Status: HealthStatusUnhealthy,
Message: "facing an issue",
UnhealthyPartitions: []string{"fail"},
},
},
},
Expand All @@ -96,8 +98,9 @@ func TestNewHealth(t *testing.T) {
Message: "",
Services: map[string]HealthResult{
"success": {
Status: HealthStatusHealthy,
Message: "",
Status: HealthStatusHealthy,
Message: "",
UnhealthyPartitions: []string{},
},
},
},
Expand Down
Loading