Skip to content

Commit

Permalink
fix: reload issues with weighted nodes (#132)
Browse files Browse the repository at this point in the history
* Fix unknown status when reloading a node with weight change
* clean up stale nodetracking data
* update deps, and remove a resolver test
  • Loading branch information
rdoorn committed May 19, 2020
1 parent b951386 commit ab6f896
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 36 deletions.
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-asn1-ber/asn1-ber v1.3.1 // indirect
github.com/go-ldap/ldap v3.0.3+incompatible
github.com/miekg/dns v1.1.27
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443
github.com/miekg/dns v1.1.29
github.com/nightlyone/lockfile v1.0.0
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/rdoorn/gorule v0.0.0-20191111095408-9e3c1ea80fdf
github.com/rdoorn/gorule v0.0.0-20191111122559-695f3843704c
github.com/rdoorn/hashstructure v0.0.0-20180705160145-6d677f823801
github.com/rdoorn/tinyresolver v0.0.0-20200117153140-4bc345ff1a2e
github.com/sirupsen/logrus v1.4.2
github.com/rdoorn/tinyresolver v0.0.0-20200519122612-63f81f0f7f0d
github.com/sirupsen/logrus v1.6.0
github.com/stackimpact/stackimpact-go v2.3.10+incompatible
github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c // indirect
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
gopkg.in/ldap.v2 v2.5.1 // indirect
gopkg.in/ldap.v3 v3.1.0 // indirect
gopkg.in/yaml.v2 v2.2.5-0.20191002202810-970885f01c8b
gopkg.in/yaml.v2 v2.3.0
nhooyr.io/websocket v1.6.5
)
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/knq/sysutil v0.0.0-20181215143952-f05b59f0f307/go.mod h1:BjPj+aVjl9FW
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand All @@ -68,8 +70,12 @@ github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc=
github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM=
github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/miekg/dns v1.1.29 h1:xHBEhR+t5RzcFJjBLJlax2daXOrTYtr9z4WdKEfWFzg=
github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443 h1:+2OJrU8cmOstEoh0uQvYemRGVH1O6xtO2oANUWHFnP0=
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443/go.mod h1:JbxfV1Iifij2yhRjXai0oFrbpxszXHRx1E5RuM26o4Y=
github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAmxBiA=
github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI=
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
Expand All @@ -85,6 +91,8 @@ github.com/rdoorn/gorule v0.0.0-20191028142911-03d8545710ac h1:zTaw7QuheXZblxw+R
github.com/rdoorn/gorule v0.0.0-20191028142911-03d8545710ac/go.mod h1:owXaf99rseXLsWD1z35/+BuB5lgviqWbHBvqq2iu8Zw=
github.com/rdoorn/gorule v0.0.0-20191111095408-9e3c1ea80fdf h1:FSLOC7rdaq0yB29bZihFhaWy8/sTjfJBSjEbePhIDnY=
github.com/rdoorn/gorule v0.0.0-20191111095408-9e3c1ea80fdf/go.mod h1:owXaf99rseXLsWD1z35/+BuB5lgviqWbHBvqq2iu8Zw=
github.com/rdoorn/gorule v0.0.0-20191111122559-695f3843704c h1:ObfgfzsOpWYRwatZ5k2BFKXH8aLF91pDkfFD6J+Av2s=
github.com/rdoorn/gorule v0.0.0-20191111122559-695f3843704c/go.mod h1:owXaf99rseXLsWD1z35/+BuB5lgviqWbHBvqq2iu8Zw=
github.com/rdoorn/hashstructure v0.0.0-20180705160145-6d677f823801 h1:jYdx94sLwqrSs8p5QE3lY9BimtDdt8C4f4DT2DMnkJQ=
github.com/rdoorn/hashstructure v0.0.0-20180705160145-6d677f823801/go.mod h1:Y7tOAbJVyxLVjqfIqMeFXaKzktjnOfQmQpDQovKCx/A=
github.com/rdoorn/tinyresolver v0.0.0-20191008124230-0320b16ed71e h1:SVUnFxi1fF4xDlxIKZfWkySl3c7msnZ12Ikt9F1Mues=
Expand All @@ -93,9 +101,15 @@ github.com/rdoorn/tinyresolver v0.0.0-20200117105202-5e93263721b1 h1:nbyTsCUSBoo
github.com/rdoorn/tinyresolver v0.0.0-20200117105202-5e93263721b1/go.mod h1:ZhcbeBaKiUfDkR2pj6uQBC2h71D+Hc5PEQKTWTU1sZQ=
github.com/rdoorn/tinyresolver v0.0.0-20200117153140-4bc345ff1a2e h1:UlJ7WzX2URCAQ0BxRC3r117HKESkvSNyQvMup3QxOtk=
github.com/rdoorn/tinyresolver v0.0.0-20200117153140-4bc345ff1a2e/go.mod h1:ZhcbeBaKiUfDkR2pj6uQBC2h71D+Hc5PEQKTWTU1sZQ=
github.com/rdoorn/tinyresolver v0.0.0-20200519121613-c602cf43001d h1:x+KZKujOBRoR9H2wuqNmxowydJAz4D+5IujXInXhOZM=
github.com/rdoorn/tinyresolver v0.0.0-20200519121613-c602cf43001d/go.mod h1:ZhcbeBaKiUfDkR2pj6uQBC2h71D+Hc5PEQKTWTU1sZQ=
github.com/rdoorn/tinyresolver v0.0.0-20200519122612-63f81f0f7f0d h1:4k3vvTnc2dWg6PnQ+EWSL31E0haa+xFmGj6DsoGsGVU=
github.com/rdoorn/tinyresolver v0.0.0-20200519122612-63f81f0f7f0d/go.mod h1:ZhcbeBaKiUfDkR2pj6uQBC2h71D+Hc5PEQKTWTU1sZQ=
github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stackimpact/stackimpact-go v2.3.10+incompatible h1:ySvQuFaxqpFEMq/IZElqt1nvYgWMoRpkQ9VAzZoDpJ0=
Expand Down Expand Up @@ -128,6 +142,8 @@ golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d h1:2+ZP7EfsZV7Vvmx3TIqSlS
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg=
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -142,6 +158,8 @@ golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 h1:bHNaocaoJxYBo5cw41UyTMLjY
golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476 h1:E7ct1C6/33eOdrGZKMoyntcEvs2dwZnDe30crG5vpYU=
golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -165,6 +183,9 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtD
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c h1:gUYreENmqtjZb2brVfUas1sC6UivSY8XwKwPo8tloLs=
golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down Expand Up @@ -196,6 +217,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5-0.20191002202810-970885f01c8b h1:c7zdkYUaqShimBvZzvhOA+Absl0aDaGKX267vSm0Z7E=
gopkg.in/yaml.v2 v2.2.5-0.20191002202810-970885f01c8b/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/gotestsum v0.3.5/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY=
mvdan.cc/sh v2.6.4+incompatible/go.mod h1:IeeQbZq+x2SUGBensq/jge5lLQbS3XT2ktyp3wrt4x8=
Expand Down
25 changes: 24 additions & 1 deletion internal/core/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (manager *Manager) HealthHandler(healthCheck *healthcheck.Manager) {
func (manager *Manager) InitializeHealthChecks(h *healthcheck.Manager) {
log := logging.For("core/healthcheck/init").WithField("func", "healthcheck")
var expectedWorkers []*healthcheck.Worker
var expectedNodes []string
var newUUIDForExistingWorkers []*healthcheck.Worker
for poolName, pool := range config.Get().Loadbalancer.Pools {
// Create workers for pool checks
var poolWorkers []*healthcheck.Worker
Expand Down Expand Up @@ -126,7 +128,13 @@ func (manager *Manager) InitializeHealthChecks(h *healthcheck.Manager) {
}

// Register all checks applicable to the node UUID
h.SetCheckPool(node.UUID, poolName, backendName, node.Name(), backend.HealthCheckMode, nodeChecks)
new := h.SetCheckPool(node.UUID, poolName, backendName, node.Name(), backend.HealthCheckMode, nodeChecks)
if new {
newUUIDForExistingWorkers = append(newUUIDForExistingWorkers, nodeWorkers...)
}

// keep track of all existing nodes
expectedNodes = append(expectedNodes, node.UUID)

// Register worker for node checks
expectedWorkers = append(expectedWorkers, nodeWorkers...)
Expand All @@ -153,12 +161,23 @@ func (manager *Manager) InitializeHealthChecks(h *healthcheck.Manager) {
expected = append(expected, worker)
}

// Compare UUID of existing workers with collected workers
for eid, eworker := range expected {
// if UUID matches, we don't need to recreate the check
if cworker.UUID() == eworker.UUID() {
log.Debugf("Existing worker check: current:%s new:%s", cworker.UUID(), eworker.UUID())
// we have a matching current with expected check, no need to add it again
expectedWorkers = append(expectedWorkers[:eid], expectedWorkers[eid+1:]...)
found = true

// also check if this is part of the list with new NodeUUID's
for _, nworker := range newUUIDForExistingWorkers {
if cworker.UUID() == nworker.UUID() {
log.Debugf("Refresh worker check: current:%s new:%s", cworker.UUID(), eworker.UUID())

cworker.Poll()
}
}
}
}

Expand All @@ -178,11 +197,15 @@ func (manager *Manager) InitializeHealthChecks(h *healthcheck.Manager) {
// expectedChecks no longer contains the active workers, so these need to be started regardless
log.WithField("count", len(expectedWorkers)).Debug("Workers to be started")
for _, worker := range expectedWorkers {
log.WithField("id", worker.UUID()).Debug("Starting worker")
h.RegisterWorker(worker)
worker.Start()
}

log.WithField("count", len(expectedWorkers)).Debug("Workers running")

// clean up node data
h.CleanNodeTracker(expectedNodes)
}

// reverse an array of strings
Expand Down
27 changes: 14 additions & 13 deletions pkg/dns/dns_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dns

import (
"fmt"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -89,19 +88,21 @@ func TestRecursive(t *testing.T) {
}

// Check for allowed recursive lookup nu.nl
m = new(dnssrv.Msg)
m.SetQuestion("www.nu.nl.", dnssrv.TypeA)
rcode, _ = parseQuery(m, "192.168.0.2:12345")
fmt.Printf("m: %+v", m)

//if !answerTarget(m, "172.217.19.196") {
if !answerType(m, dnssrv.TypeA) {
t.Errorf("Expected 1 records, of type A:%t got:%+v", answerType(m, dnssrv.TypeA), m)
}
/*
m = new(dnssrv.Msg)
m.SetQuestion("www.nu.nl.", dnssrv.TypeA)
rcode, _ = parseQuery(m, "192.168.0.2:12345")
fmt.Printf("m: %+v", m)
//if !answerTarget(m, "172.217.19.196") {
if !answerType(m, dnssrv.TypeA) {
t.Errorf("Expected 1 records, of type A:%t got:%+v", answerType(m, dnssrv.TypeA), m)
}
if rcode != -1 {
t.Errorf("Return code incorrect, got:%d expected:%d", rcode, 0)
}
if rcode != -1 {
t.Errorf("Return code incorrect, got:%d expected:%d", rcode, 0)
}
*/

// Check for denied recursive lookup
m = new(dnssrv.Msg)
Expand Down
23 changes: 23 additions & 0 deletions pkg/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,26 @@ func (m *Manager) sendWorkerUpdate(uuid string) {
}
}
}

// CleanNodeTracker cleans up nodes beeing tracked, but do not exist anymore
func (m *Manager) CleanNodeTracker(expectedNodes []string) {
m.Worker.Lock()
defer m.Worker.Unlock()
var existing []string
for uuid := range m.HealthPoolMap {
existing = append(existing, uuid)
}

for _, exists := range existing {
found := false
for _, expected := range expectedNodes {
if expected == exists {
found = true
}
}

if found == false {
delete(m.HealthPoolMap, exists)
}
}
}
5 changes: 4 additions & 1 deletion pkg/healthcheck/healthcheck_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ func (m *Manager) SetCheckStatus(workerUUID string, status Status, errorMsg []st
}

// SetCheckPool sets which checks for a specified backend are applicable
func (m *Manager) SetCheckPool(nodeUUID string, poolName string, backendName string, nodeName string, match string, checks []string) {
func (m *Manager) SetCheckPool(nodeUUID string, poolName string, backendName string, nodeName string, match string, checks []string) bool {
m.Worker.Lock()
defer m.Worker.Unlock()
new := false
if _, ok := m.HealthPoolMap[nodeUUID]; !ok {
m.HealthPoolMap[nodeUUID] = HealthPool{}
new = true
}
s := m.HealthPoolMap[nodeUUID]
s.Checks = checks
Expand All @@ -53,6 +55,7 @@ func (m *Manager) SetCheckPool(nodeUUID string, poolName string, backendName str
s.NodeName = nodeName
s.Match = match
m.HealthPoolMap[nodeUUID] = s
return new
}

// GetNodeStatus returns the combined status of all checks applicable to a specific backend
Expand Down
62 changes: 50 additions & 12 deletions pkg/healthcheck/healthcheck_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,36 @@ func (w *Worker) Start() {
if result != w.CheckResult || checkerror != previouserror {
log.WithField("checktype", w.Check.Type).WithField("online", result).WithField("error", err).Warn("Healtcheck state changed")
// Send the result to the cluster
checkresult := CheckResult{
PoolName: w.Pool,
BackendName: w.Backend,
ActualStatus: result,
ReportedStatus: w.reportState(result),
NodeName: w.NodeName,
WorkerUUID: w.UUID(),
Description: w.Description(),
}

/*
checkresult := CheckResult{
PoolName: w.Pool,
BackendName: w.Backend,
ActualStatus: result,
ReportedStatus: w.reportState(result),
NodeName: w.NodeName,
WorkerUUID: w.UUID(),
Description: w.Description(),
}
w.CheckResult = result
w.CheckError = ""
if err != nil {
w.CheckError = err.Error()
checkresult.ErrorMsg = append(checkresult.ErrorMsg, w.ErrorMsg())
}
w.update <- checkresult
*/
w.CheckResult = result
w.CheckError = ""

var errorMsg []string
if err != nil {
w.CheckError = err.Error()
checkresult.ErrorMsg = append(checkresult.ErrorMsg, w.ErrorMsg())
errorMsg = append(errorMsg, w.ErrorMsg())
}

w.update <- checkresult
w.SendUpdate(result, errorMsg)
}
timer = time.NewTimer(time.Duration(w.Check.Interval) * time.Second)

Expand All @@ -177,6 +189,32 @@ func (w *Worker) Start() {
}()
}

// SendUpdate sends the updated status to the channel
func (w *Worker) SendUpdate(result Status, errMsg []string) {
checkresult := CheckResult{
PoolName: w.Pool,
BackendName: w.Backend,
ActualStatus: result,
ReportedStatus: w.reportState(result),
NodeName: w.NodeName,
WorkerUUID: w.UUID(),
Description: w.Description(),
ErrorMsg: errMsg,
}

w.update <- checkresult
}

// Poll sends the current status to the channel
func (w *Worker) Poll() {
var errorMsg []string
if w.CheckError != "" {
errorMsg = append(errorMsg, w.CheckError)
}

w.SendUpdate(w.CheckResult, errorMsg)
}

// Stop the worker
func (w *Worker) Stop() {
w.stop <- true
Expand Down

0 comments on commit ab6f896

Please sign in to comment.