Skip to content

Commit

Permalink
Allow health services to be omitted. (#138)
Browse files Browse the repository at this point in the history
* Allow health services to be omitted.

* Fix tests.
  • Loading branch information
Gerrit91 authored Apr 2, 2024
1 parent 2162c32 commit 74e9c4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion rest/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type HealthResponse struct {
// 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"`
Services map[string]HealthResult `json:"services,omitempty"`
}

// HealthResult holds the health state of a service.
Expand Down
30 changes: 12 additions & 18 deletions rest/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ func (e *succeedingCheck) Check(ctx context.Context) (HealthResult, error) {
Message: "",
Services: map[string]HealthResult{
"successPartition": {
Status: HealthStatusHealthy,
Message: "",
Services: map[string]HealthResult{},
Status: HealthStatusHealthy,
Message: "",
},
},
}, nil
Expand All @@ -43,9 +42,8 @@ func (e *failingCheck) Check(ctx context.Context) (HealthResult, error) {
Message: "",
Services: map[string]HealthResult{
"failPartition": {
Status: HealthStatusUnhealthy,
Message: "facing an issue",
Services: map[string]HealthResult{},
Status: HealthStatusUnhealthy,
Message: "facing an issue",
},
},
}, fmt.Errorf("facing an issue")
Expand Down Expand Up @@ -73,9 +71,8 @@ func TestNewHealth(t *testing.T) {
h: nil,
},
want: &HealthResponse{
Status: HealthStatusHealthy,
Message: "",
Services: map[string]HealthResult{},
Status: HealthStatusHealthy,
Message: "",
},
},
{
Expand All @@ -94,9 +91,8 @@ func TestNewHealth(t *testing.T) {
Message: "",
Services: map[string]HealthResult{
"successPartition": {
Status: HealthStatusHealthy,
Message: "",
Services: map[string]HealthResult{},
Status: HealthStatusHealthy,
Message: "",
},
},
},
Expand All @@ -105,9 +101,8 @@ func TestNewHealth(t *testing.T) {
Message: "facing an issue",
Services: map[string]HealthResult{
"failPartition": {
Status: HealthStatusUnhealthy,
Message: "facing an issue",
Services: map[string]HealthResult{},
Status: HealthStatusUnhealthy,
Message: "facing an issue",
},
},
},
Expand All @@ -131,9 +126,8 @@ func TestNewHealth(t *testing.T) {
Message: "",
Services: map[string]HealthResult{
"successPartition": {
Status: HealthStatusHealthy,
Message: "",
Services: map[string]HealthResult{},
Status: HealthStatusHealthy,
Message: "",
},
},
},
Expand Down

0 comments on commit 74e9c4c

Please sign in to comment.