From 903108532c9d772d04925450a85ac4366f766175 Mon Sep 17 00:00:00 2001 From: qrnvttrl Date: Fri, 23 Feb 2024 14:08:07 +0100 Subject: [PATCH 1/7] Add Partitions to HealthResult and Check --- rest/health.go | 11 +++++++---- rest/health_test.go | 23 +++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/rest/health.go b/rest/health.go index db50e19..4562177 100644 --- a/rest/health.go +++ b/rest/health.go @@ -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, map[string]HealthStatus, error) } // HealthResponse is returned by the API when executing a health check. @@ -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. + Partitions map[string]HealthStatus `json:"partitions"` } type healthResource struct { @@ -139,8 +141,9 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo result := chanResult{ name: name, HealthResult: HealthResult{ - Status: HealthStatusHealthy, - Message: "", + Status: HealthStatusHealthy, + Message: "", + Partitions: map[string]HealthStatus{}, }, } defer func() { @@ -148,7 +151,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo }() var err error - result.Status, err = healthCheck.Check(ctx) + result.Status, result.Partitions, err = healthCheck.Check(ctx) if err != nil { result.Message = err.Error() h.log.Errorw("unhealthy service", "name", name, "status", result.Status, "error", err) diff --git a/rest/health_test.go b/rest/health_test.go index 3144d59..4cdb249 100644 --- a/rest/health_test.go +++ b/rest/health_test.go @@ -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, map[string]HealthStatus, error) { + return HealthStatusHealthy, map[string]HealthStatus{"success": HealthStatusHealthy}, nil } type failingCheck struct{} @@ -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, map[string]HealthStatus, error) { + return HealthStatusUnhealthy, map[string]HealthStatus{"fail": HealthStatusUnhealthy}, fmt.Errorf("facing an issue") } func TestNewHealth(t *testing.T) { @@ -73,12 +73,14 @@ func TestNewHealth(t *testing.T) { Message: "facing an issue", Services: map[string]HealthResult{ "success": { - Status: HealthStatusHealthy, - Message: "", + Status: HealthStatusHealthy, + Message: "", + Partitions: map[string]HealthStatus{"success": HealthStatusHealthy}, }, "fail": { - Status: HealthStatusUnhealthy, - Message: "facing an issue", + Status: HealthStatusUnhealthy, + Message: "facing an issue", + Partitions: map[string]HealthStatus{"fail": HealthStatusUnhealthy}, }, }, }, @@ -96,8 +98,9 @@ func TestNewHealth(t *testing.T) { Message: "", Services: map[string]HealthResult{ "success": { - Status: HealthStatusHealthy, - Message: "", + Status: HealthStatusHealthy, + Message: "", + Partitions: map[string]HealthStatus{"success": HealthStatusHealthy}, }, }, }, From 36ecd3db59f8aaaeba1788e8a718fe497f8158b2 Mon Sep 17 00:00:00 2001 From: qrnvttrl Date: Fri, 23 Feb 2024 15:41:59 +0100 Subject: [PATCH 2/7] Changed map to array --- rest/health.go | 12 ++++++------ rest/health_test.go | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/rest/health.go b/rest/health.go index 4562177..4b26526 100644 --- a/rest/health.go +++ b/rest/health.go @@ -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, map[string]HealthStatus, error) + Check(ctx context.Context) (HealthStatus, []string, error) } // HealthResponse is returned by the API when executing a health check. @@ -52,7 +52,7 @@ type HealthResult struct { // 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. - Partitions map[string]HealthStatus `json:"partitions"` + UnhealthyPartitions []string `json:"unhealthy-partitions"` } type healthResource struct { @@ -141,9 +141,9 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo result := chanResult{ name: name, HealthResult: HealthResult{ - Status: HealthStatusHealthy, - Message: "", - Partitions: map[string]HealthStatus{}, + Status: HealthStatusHealthy, + Message: "", + UnhealthyPartitions: []string{}, }, } defer func() { @@ -151,7 +151,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo }() var err error - result.Status, result.Partitions, 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) diff --git a/rest/health_test.go b/rest/health_test.go index 4cdb249..9ae03a1 100644 --- a/rest/health_test.go +++ b/rest/health_test.go @@ -19,8 +19,8 @@ func (e *succeedingCheck) ServiceName() string { return "success" } -func (e *succeedingCheck) Check(ctx context.Context) (HealthStatus, map[string]HealthStatus, error) { - return HealthStatusHealthy, map[string]HealthStatus{"success": HealthStatusHealthy}, nil +func (e *succeedingCheck) Check(ctx context.Context) (HealthStatus, []string, error) { + return HealthStatusHealthy, []string{}, nil } type failingCheck struct{} @@ -29,8 +29,8 @@ func (e *failingCheck) ServiceName() string { return "fail" } -func (e *failingCheck) Check(ctx context.Context) (HealthStatus, map[string]HealthStatus, error) { - return HealthStatusUnhealthy, map[string]HealthStatus{"fail": 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) { @@ -73,14 +73,14 @@ func TestNewHealth(t *testing.T) { Message: "facing an issue", Services: map[string]HealthResult{ "success": { - Status: HealthStatusHealthy, - Message: "", - Partitions: map[string]HealthStatus{"success": HealthStatusHealthy}, + Status: HealthStatusHealthy, + Message: "", + UnhealthyPartitions: []string{}, }, "fail": { - Status: HealthStatusUnhealthy, - Message: "facing an issue", - Partitions: map[string]HealthStatus{"fail": HealthStatusUnhealthy}, + Status: HealthStatusUnhealthy, + Message: "facing an issue", + UnhealthyPartitions: []string{"fail"}, }, }, }, @@ -98,9 +98,9 @@ func TestNewHealth(t *testing.T) { Message: "", Services: map[string]HealthResult{ "success": { - Status: HealthStatusHealthy, - Message: "", - Partitions: map[string]HealthStatus{"success": HealthStatusHealthy}, + Status: HealthStatusHealthy, + Message: "", + UnhealthyPartitions: []string{}, }, }, }, From ad9b4e367f0084201d46367fd4dac4ebf5cbf4bd Mon Sep 17 00:00:00 2001 From: qrnvttrl Date: Mon, 26 Feb 2024 13:10:28 +0100 Subject: [PATCH 3/7] recurse HealthResult --- rest/health.go | 44 +++++++++++---------------- rest/health_test.go | 74 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 44 deletions(-) diff --git a/rest/health.go b/rest/health.go index 4b26526..fee9bda 100644 --- a/rest/health.go +++ b/rest/health.go @@ -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, []string, error) + Check(ctx context.Context) (HealthResult, error) } // HealthResponse is returned by the API when executing a health check. @@ -41,19 +41,12 @@ type HealthResponse struct { Status HealthStatus `json:"status"` // Message gives additional information on the overall health state. Message string `json:"message"` - // Services is map of services by name with their individual health results. - Services map[string]HealthResult `json:"services"` + // provides further information on the result e.g. services or partitions + Information map[string]HealthResult `json:"information"` } // HealthResult holds the health state of a service. -type HealthResult struct { - // Status indicates the health of the service. - 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 HealthResult HealthResponse type healthResource struct { log *zap.SugaredLogger @@ -113,9 +106,9 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo var ( service = request.QueryParameter("service") result = HealthResponse{ - Status: HealthStatusHealthy, - Message: "", - Services: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{}, } resultChan = make(chan chanResult) @@ -141,9 +134,9 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo result := chanResult{ name: name, HealthResult: HealthResult{ - Status: HealthStatusHealthy, - Message: "", - UnhealthyPartitions: []string{}, + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{}, }, } defer func() { @@ -151,7 +144,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo }() var err error - result.Status, result.UnhealthyPartitions, err = healthCheck.Check(ctx) + result.HealthResult, err = healthCheck.Check(ctx) if err != nil { result.Message = err.Error() h.log.Errorw("unhealthy service", "name", name, "status", result.Status, "error", err) @@ -165,8 +158,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo go func() { for r := range resultChan { r := r - result.Services[r.name] = r.HealthResult - + result.Information[r.name] = r.HealthResult } finished <- true }() @@ -182,7 +174,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo <-finished - result.Status = DeriveOverallHealthStatus(result.Services) + result.Status = DeriveOverallHealthStatus(result.Information) err := response.WriteHeaderAndEntity(rc, result) if err != nil { @@ -190,15 +182,15 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo } } -func DeriveOverallHealthStatus(services map[string]HealthResult) HealthStatus { +func DeriveOverallHealthStatus(information map[string]HealthResult) HealthStatus { var ( result = HealthStatusHealthy degraded int unhealthy int ) - for _, service := range services { - switch service.Status { + for _, i := range information { + switch i.Status { case HealthStatusHealthy: case HealthStatusDegraded: degraded++ @@ -209,14 +201,14 @@ func DeriveOverallHealthStatus(services map[string]HealthResult) HealthStatus { } } - if len(services) > 0 { + if len(information) > 0 { if degraded > 0 { result = HealthStatusDegraded } if unhealthy > 0 { result = HealthStatusPartiallyUnhealthy } - if unhealthy == len(services) { + if unhealthy == len(information) { result = HealthStatusUnhealthy } } diff --git a/rest/health_test.go b/rest/health_test.go index 9ae03a1..6dbbbe4 100644 --- a/rest/health_test.go +++ b/rest/health_test.go @@ -19,8 +19,18 @@ func (e *succeedingCheck) ServiceName() string { return "success" } -func (e *succeedingCheck) Check(ctx context.Context) (HealthStatus, []string, error) { - return HealthStatusHealthy, []string{}, nil +func (e *succeedingCheck) Check(ctx context.Context) (HealthResult, error) { + return HealthResult{ + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{ + "successPartition": { + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{}, + }, + }, + }, nil } type failingCheck struct{} @@ -29,8 +39,18 @@ func (e *failingCheck) ServiceName() string { return "fail" } -func (e *failingCheck) Check(ctx context.Context) (HealthStatus, []string, error) { - return HealthStatusUnhealthy, []string{"fail"}, fmt.Errorf("facing an issue") +func (e *failingCheck) Check(ctx context.Context) (HealthResult, error) { + return HealthResult{ + Status: HealthStatusUnhealthy, + Message: "", + Information: map[string]HealthResult{ + "failPartition": { + Status: HealthStatusUnhealthy, + Message: "", + Information: map[string]HealthResult{}, + }, + }, + }, fmt.Errorf("facing an issue") } func TestNewHealth(t *testing.T) { @@ -56,9 +76,9 @@ func TestNewHealth(t *testing.T) { h: nil, }, want: &HealthResponse{ - Status: HealthStatusHealthy, - Message: "", - Services: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{}, }, }, { @@ -71,16 +91,28 @@ func TestNewHealth(t *testing.T) { want: &HealthResponse{ Status: HealthStatusPartiallyUnhealthy, Message: "facing an issue", - Services: map[string]HealthResult{ + Information: map[string]HealthResult{ "success": { - Status: HealthStatusHealthy, - Message: "", - UnhealthyPartitions: []string{}, + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{ + "successPartition": { + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{}, + }, + }, }, "fail": { - Status: HealthStatusUnhealthy, - Message: "facing an issue", - UnhealthyPartitions: []string{"fail"}, + Status: HealthStatusUnhealthy, + Message: "facing an issue", + Information: map[string]HealthResult{ + "failPartition": { + Status: HealthStatusUnhealthy, + Message: "", + Information: map[string]HealthResult{}, + }, + }, }, }, }, @@ -96,11 +128,17 @@ func TestNewHealth(t *testing.T) { want: &HealthResponse{ Status: HealthStatusHealthy, Message: "", - Services: map[string]HealthResult{ + Information: map[string]HealthResult{ "success": { - Status: HealthStatusHealthy, - Message: "", - UnhealthyPartitions: []string{}, + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{ + "successPartition": { + Status: HealthStatusHealthy, + Message: "", + Information: map[string]HealthResult{}, + }, + }, }, }, }, From afe223c6417f48660302b556a6823d2cc17d1f1c Mon Sep 17 00:00:00 2001 From: qrnvttrl Date: Mon, 26 Feb 2024 13:32:21 +0100 Subject: [PATCH 4/7] changed DeriveOverallStatus --- rest/health.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rest/health.go b/rest/health.go index fee9bda..e779481 100644 --- a/rest/health.go +++ b/rest/health.go @@ -190,6 +190,9 @@ func DeriveOverallHealthStatus(information map[string]HealthResult) HealthStatus ) for _, i := range information { + if i.Status == "" { + i.Status = DeriveOverallHealthStatus(i.Information) + } switch i.Status { case HealthStatusHealthy: case HealthStatusDegraded: From 06a9c7eab80ece3d5534dc6d275451408784c325 Mon Sep 17 00:00:00 2001 From: qrnvttrl Date: Mon, 26 Feb 2024 14:42:17 +0100 Subject: [PATCH 5/7] return to name services --- rest/health.go | 32 ++++++++++++++++------------- rest/health_test.go | 50 ++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/rest/health.go b/rest/health.go index e779481..e3b839c 100644 --- a/rest/health.go +++ b/rest/health.go @@ -41,8 +41,12 @@ type HealthResponse struct { Status HealthStatus `json:"status"` // Message gives additional information on the overall health state. Message string `json:"message"` - // provides further information on the result e.g. services or partitions - Information map[string]HealthResult `json:"information"` + // Services contain the individual health results of the services as evaluated by the HealthCheck interface. The overall HealthStatus is then derived automatically from the results of the health checks. + // + // Note that the individual HealthResults evaluated by the HealthCheck interface may again consist of a plurality services. While this is only optional it allows for creating nested health structures. These can be used for more sophisticated scenarios like evaluating platform health describing service availability in different locations or similar. + // + // If using nested HealthResults, the status of the parent service can be derived automatically from the status of its children by leaving the parent's health status field blank. + Services map[string]HealthResult `json:"services"` } // HealthResult holds the health state of a service. @@ -106,9 +110,9 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo var ( service = request.QueryParameter("service") result = HealthResponse{ - Status: HealthStatusHealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Services: map[string]HealthResult{}, } resultChan = make(chan chanResult) @@ -134,9 +138,9 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo result := chanResult{ name: name, HealthResult: HealthResult{ - Status: HealthStatusHealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Services: map[string]HealthResult{}, }, } defer func() { @@ -158,7 +162,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo go func() { for r := range resultChan { r := r - result.Information[r.name] = r.HealthResult + result.Services[r.name] = r.HealthResult } finished <- true }() @@ -174,7 +178,7 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo <-finished - result.Status = DeriveOverallHealthStatus(result.Information) + result.Status = DeriveOverallHealthStatus(result.Services) err := response.WriteHeaderAndEntity(rc, result) if err != nil { @@ -189,11 +193,11 @@ func DeriveOverallHealthStatus(information map[string]HealthResult) HealthStatus unhealthy int ) - for _, i := range information { - if i.Status == "" { - i.Status = DeriveOverallHealthStatus(i.Information) + for _, service := range information { + if service.Status == "" { + service.Status = DeriveOverallHealthStatus(service.Services) } - switch i.Status { + switch service.Status { case HealthStatusHealthy: case HealthStatusDegraded: degraded++ diff --git a/rest/health_test.go b/rest/health_test.go index 6dbbbe4..94e3427 100644 --- a/rest/health_test.go +++ b/rest/health_test.go @@ -23,11 +23,11 @@ func (e *succeedingCheck) Check(ctx context.Context) (HealthResult, error) { return HealthResult{ Status: HealthStatusHealthy, Message: "", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "successPartition": { - Status: HealthStatusHealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Services: map[string]HealthResult{}, }, }, }, nil @@ -43,11 +43,11 @@ func (e *failingCheck) Check(ctx context.Context) (HealthResult, error) { return HealthResult{ Status: HealthStatusUnhealthy, Message: "", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "failPartition": { - Status: HealthStatusUnhealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusUnhealthy, + Message: "", + Services: map[string]HealthResult{}, }, }, }, fmt.Errorf("facing an issue") @@ -76,9 +76,9 @@ func TestNewHealth(t *testing.T) { h: nil, }, want: &HealthResponse{ - Status: HealthStatusHealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Services: map[string]HealthResult{}, }, }, { @@ -91,26 +91,26 @@ func TestNewHealth(t *testing.T) { want: &HealthResponse{ Status: HealthStatusPartiallyUnhealthy, Message: "facing an issue", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "success": { Status: HealthStatusHealthy, Message: "", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "successPartition": { - Status: HealthStatusHealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Services: map[string]HealthResult{}, }, }, }, "fail": { Status: HealthStatusUnhealthy, Message: "facing an issue", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "failPartition": { - Status: HealthStatusUnhealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusUnhealthy, + Message: "", + Services: map[string]HealthResult{}, }, }, }, @@ -128,15 +128,15 @@ func TestNewHealth(t *testing.T) { want: &HealthResponse{ Status: HealthStatusHealthy, Message: "", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "success": { Status: HealthStatusHealthy, Message: "", - Information: map[string]HealthResult{ + Services: map[string]HealthResult{ "successPartition": { - Status: HealthStatusHealthy, - Message: "", - Information: map[string]HealthResult{}, + Status: HealthStatusHealthy, + Message: "", + Services: map[string]HealthResult{}, }, }, }, From 3ed6c6111e8fa8322b7880be954d10d14fc228e1 Mon Sep 17 00:00:00 2001 From: qrnvttrl Date: Mon, 4 Mar 2024 13:36:22 +0100 Subject: [PATCH 6/7] fixed DeriveOverallHealthStatus --- rest/health.go | 9 +++++---- rest/health_test.go | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/rest/health.go b/rest/health.go index e3b839c..049cf93 100644 --- a/rest/health.go +++ b/rest/health.go @@ -186,17 +186,18 @@ func (h *healthResource) check(request *restful.Request, response *restful.Respo } } -func DeriveOverallHealthStatus(information map[string]HealthResult) HealthStatus { +func DeriveOverallHealthStatus(services map[string]HealthResult) HealthStatus { var ( result = HealthStatusHealthy degraded int unhealthy int ) - for _, service := range information { + for k, service := range services { if service.Status == "" { service.Status = DeriveOverallHealthStatus(service.Services) } + services[k] = service switch service.Status { case HealthStatusHealthy: case HealthStatusDegraded: @@ -208,14 +209,14 @@ func DeriveOverallHealthStatus(information map[string]HealthResult) HealthStatus } } - if len(information) > 0 { + if len(services) > 0 { if degraded > 0 { result = HealthStatusDegraded } if unhealthy > 0 { result = HealthStatusPartiallyUnhealthy } - if unhealthy == len(information) { + if unhealthy == len(services) { result = HealthStatusUnhealthy } } diff --git a/rest/health_test.go b/rest/health_test.go index 94e3427..2541b49 100644 --- a/rest/health_test.go +++ b/rest/health_test.go @@ -21,7 +21,6 @@ func (e *succeedingCheck) ServiceName() string { func (e *succeedingCheck) Check(ctx context.Context) (HealthResult, error) { return HealthResult{ - Status: HealthStatusHealthy, Message: "", Services: map[string]HealthResult{ "successPartition": { @@ -41,12 +40,11 @@ func (e *failingCheck) ServiceName() string { func (e *failingCheck) Check(ctx context.Context) (HealthResult, error) { return HealthResult{ - Status: HealthStatusUnhealthy, Message: "", Services: map[string]HealthResult{ "failPartition": { Status: HealthStatusUnhealthy, - Message: "", + Message: "facing an issue", Services: map[string]HealthResult{}, }, }, @@ -109,7 +107,7 @@ func TestNewHealth(t *testing.T) { Services: map[string]HealthResult{ "failPartition": { Status: HealthStatusUnhealthy, - Message: "", + Message: "facing an issue", Services: map[string]HealthResult{}, }, }, From 4763218de4d75ed713dd6c0eafb6941c68652572 Mon Sep 17 00:00:00 2001 From: Quirin Vetterl <140174674+qrnvttrl@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:06:38 +0100 Subject: [PATCH 7/7] Update rest/health.go Co-authored-by: Gerrit --- rest/health.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest/health.go b/rest/health.go index 3d69dee..465ffbd 100644 --- a/rest/health.go +++ b/rest/health.go @@ -194,7 +194,7 @@ func DeriveOverallHealthStatus(services map[string]HealthResult) HealthStatus { ) for k, service := range services { - if service.Status == "" { + if len(service.Services) > 0 && service.Status == "" { service.Status = DeriveOverallHealthStatus(service.Services) } services[k] = service