Skip to content

Commit

Permalink
Merge pull request #16 from Financial-Times/fix/stickiness
Browse files Browse the repository at this point in the history
Fixing stickiness
  • Loading branch information
tamas-molnar authored Jan 29, 2018
2 parents c4cb6b5 + fec188b commit e0d8669
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cachingController.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"fmt"
fthealth "github.com/Financial-Times/go-fthealth/v1a"
"math"
"reflect"
"time"

fthealth "github.com/Financial-Times/go-fthealth/v1a"
)

const (
Expand Down Expand Up @@ -100,7 +101,6 @@ func (c *healthCheckController) getMeasuredServices() map[string]measuredService
}

func findShortestPeriod(categories map[string]category) time.Duration {

if len(categories) == 0 {
return defaultRefreshPeriod
}
Expand Down
12 changes: 8 additions & 4 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"fmt"
fthealth "github.com/Financial-Times/go-fthealth/v1a"
"sort"
"sync"
"time"

fthealth "github.com/Financial-Times/go-fthealth/v1a"
)

type healthCheckController struct {
Expand Down Expand Up @@ -93,11 +94,12 @@ func (c *healthCheckController) buildServicesHealthResult(providedCategories []s
if useCache {
desc = "Health of the whole cluster served from cache."
checkResults, _ = c.collectChecksFromCachesFor(matchingCategories)

} else {
checkResults, _ = c.runServiceChecksFor(matchingCategories)
}

c.disableStickyFailingCategories(matchingCategories, checkResults)

finalOk, finalSeverity := getFinalResult(checkResults, matchingCategories)

health := fthealth.HealthResult{
Expand Down Expand Up @@ -159,6 +161,10 @@ func (c *healthCheckController) runServiceChecksFor(categories map[string]catego
services := c.healthCheckService.getServicesMapByNames(serviceNames)
healthChecks := c.runServiceChecksByServiceNames(services, categories)

return healthChecks, categorisedResults
}

func (c *healthCheckController) disableStickyFailingCategories(categories map[string]category, healthChecks []fthealth.CheckResult) {
for catIndex, category := range categories {
if !isEnabledAndSticky(category) {
continue
Expand All @@ -179,8 +185,6 @@ func (c *healthCheckController) runServiceChecksFor(categories map[string]catego
}
}
}

return healthChecks, categorisedResults
}

func isEnabledAndSticky(category category) bool {
Expand Down
16 changes: 10 additions & 6 deletions controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"errors"
"fmt"
fthealth "github.com/Financial-Times/go-fthealth/v1a"
"github.com/stretchr/testify/assert"
"net/http"
"os"
"testing"
"time"

fthealth "github.com/Financial-Times/go-fthealth/v1a"
"github.com/stretchr/testify/assert"
)

const (
Expand Down Expand Up @@ -361,8 +362,9 @@ func TestRunServiceChecksForStickyCategory(t *testing.T) {
}

controller := initializeMockController("test", nil)
checkResult, _ := controller.runServiceChecksFor(categories)
assert.NotNil(t, checkResult)
hc, categories, _, _ := controller.buildServicesHealthResult([]string{"test", "publishing"}, false)

assert.NotNil(t, hc)
assert.False(t, categories["test"].isEnabled)
}

Expand All @@ -384,8 +386,10 @@ func TestRunServiceChecksForStickyCategoryUpdateError(t *testing.T) {
}

controller := initializeMockController("test", nil)
checkResult, _ := controller.runServiceChecksFor(categories)
assert.NotNil(t, checkResult)
hc, categories, _, _ := controller.buildServicesHealthResult([]string{"test", "publishing", nonExistingCategoryName}, true)

assert.NotNil(t, hc)
assert.False(t, hc.Ok)
assert.False(t, categories["test"].isEnabled)
}

Expand Down
14 changes: 7 additions & 7 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"revisionTime": "2016-08-26T23:14:08Z"
},
{
"checksumSHA1": "PjqKI0KCcrl2MtsgUvzkwaLpSdI=",
"checksumSHA1": "9lOtRfhl48QxUwyx3YJNekCLTPE=",
"path": "golang.org/x/text/cases",
"revision": "2910a502d2bf9e43193af9d68ca516529614eed3",
"revisionTime": "2016-07-21T22:28:28Z"
Expand All @@ -374,7 +374,7 @@
"revisionTime": "2016-07-21T22:28:28Z"
},
{
"checksumSHA1": "DkHDKdSD4pSdH9iLx22i1UcPNJI=",
"checksumSHA1": "vbYsvMa+yYFTrmD0bIVhA36DpgQ=",
"path": "golang.org/x/text/language",
"revision": "2910a502d2bf9e43193af9d68ca516529614eed3",
"revisionTime": "2016-07-21T22:28:28Z"
Expand All @@ -392,7 +392,7 @@
"revisionTime": "2016-07-21T22:28:28Z"
},
{
"checksumSHA1": "8RJL5ieyKa9ZW82mtoNuQYID2fw=",
"checksumSHA1": "1IuvLthKYvAb/tapHq+e/OH7KNk=",
"path": "golang.org/x/text/secure/precis",
"revision": "2910a502d2bf9e43193af9d68ca516529614eed3",
"revisionTime": "2016-07-21T22:28:28Z"
Expand All @@ -404,19 +404,19 @@
"revisionTime": "2016-07-21T22:28:28Z"
},
{
"checksumSHA1": "JGgdtPIIUWvKfX7N4bnbudwi6H0=",
"checksumSHA1": "2IEszVJvEtg9W9g2zuZsbxZNW/k=",
"path": "golang.org/x/text/unicode/bidi",
"revision": "2910a502d2bf9e43193af9d68ca516529614eed3",
"revisionTime": "2016-07-21T22:28:28Z"
},
{
"checksumSHA1": "zH09KVkfc23XyOWpkigO3ifVOmk=",
"checksumSHA1": "pDDMc5yLVQ2xeR9CajcgIJODPcw=",
"path": "golang.org/x/text/unicode/norm",
"revision": "2910a502d2bf9e43193af9d68ca516529614eed3",
"revisionTime": "2016-07-21T22:28:28Z"
},
{
"checksumSHA1": "DU2uVxLEIj5lMcT+oFt49xKxLdY=",
"checksumSHA1": "BU+BXnKIUJk/ncvbmW4v9248JWg=",
"path": "golang.org/x/text/width",
"revision": "2910a502d2bf9e43193af9d68ca516529614eed3",
"revisionTime": "2016-07-21T22:28:28Z"
Expand Down Expand Up @@ -494,7 +494,7 @@
"revisionTime": "2015-09-24T14:23:14Z"
},
{
"checksumSHA1": "hBin8FR+b38/hbMfFwH2YIGsSQc=",
"checksumSHA1": "SSbMBSzzGF6XGcEnH5SijHEWLjA=",
"path": "k8s.io/client-go",
"revision": "e121606b0d09b2e1c467183ee46217fa85a6b672",
"tree": true,
Expand Down

0 comments on commit e0d8669

Please sign in to comment.