Skip to content

Commit

Permalink
Fixed getting the individual pod severity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorin Buliarca committed Mar 2, 2018
1 parent 3dfda66 commit 4feb9ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 4 additions & 2 deletions checkerService.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ func (hs *k8sHealthcheckService) getIndividualPodSeverity(pod pod, appPort int32
}

finalSeverity := uint8(2)
checkFailed := bool(false)
for _, check := range health.Checks {
if !check.OK {
checkFailed = true
if check.Severity < finalSeverity {
return check.Severity, true, nil
return check.Severity, checkFailed, nil
}
}
}

return finalSeverity, false, nil
return finalSeverity, checkFailed, nil
}

func (hs *k8sHealthcheckService) getHealthChecksForPod(pod pod, appPort int32) (healthcheckResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (m *MockService) getPodsForService(serviceName string) ([]pod, error) {
case "invalidNameForService":
return []pod{}, errors.New("invalid pod name")
case "resilient-notok-sev1":
return createPods(0, []int{1, 1}), nil
return createPods(0, []int{2, 1}), nil
case "resilient-notok-sev2":
return createPods(0, []int{2, 2}), nil
case "resilient-halfok-sev1":
Expand Down
28 changes: 27 additions & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ const (
"name": ""
}
]
}`
validFailingHealthCheckResponseBodyWithSeverity2 = `{
"schemaVersion": 1,
"name": "CMSNotifierApplication",
"description": "CMSNotifierApplication",
"checks": [
{
"checkOutput": "",
"panicGuide": "",
"lastUpdated": "",
"ok": false,
"severity": 2,
"businessImpact": "",
"technicalSummary": "",
"name": ""
}
]
}`
validPassingHealthCheckResponseBody = `{
"schemaVersion": 1,
Expand Down Expand Up @@ -140,11 +157,20 @@ func TestGetIndividualPodSeverityErrorWhilePodHealthCheck(t *testing.T) {

func TestGetIndividualPodSeverityValidPodHealth(t *testing.T) {
service := initializeMockService(initializeMockHTTPClient(http.StatusOK, validFailingHealthCheckResponseBody))
severity, _, err := service.getIndividualPodSeverity(pod{name: "test", ip: validIP}, 8080)
severity, checkFailed, err := service.getIndividualPodSeverity(pod{name: "test", ip: validIP}, 8080)
assert.Nil(t, err)
assert.True(t, checkFailed)
assert.Equal(t, validSeverity, severity)
}

func TestGetIndividualPodSeverityValidPodHealth_Severity2(t *testing.T) {
service := initializeMockService(initializeMockHTTPClient(http.StatusOK, validFailingHealthCheckResponseBodyWithSeverity2))
severity, checkFailed, err := service.getIndividualPodSeverity(pod{name: "test", ip: validIP}, 8080)
assert.Nil(t, err)
assert.True(t, checkFailed)
assert.Equal(t, uint8(2), severity)
}

func TestCheckPodHealthFailingChecks(t *testing.T) {
service := initializeMockService(initializeMockHTTPClient(http.StatusOK, validFailingHealthCheckResponseBody))
err := service.checkPodHealth(pod{name: "test", ip: validIP}, 8080)
Expand Down

0 comments on commit 4feb9ee

Please sign in to comment.