Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: service will never be deregisterd if the status is critical … #101

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,20 @@ func (c *CheckRunner) UpdateCheck(checkID types.CheckID, status, output string)
return
}

// Do nothing if update is idempotent
if check.Status == status && check.Output == output {
check.failureCounter = decrementCounter(check.failureCounter)
check.successCounter = decrementCounter(check.successCounter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the only 2 uses of decrementCounter(). Should probably nuke it as well.

return
}

if status == api.HealthCritical {
check.successCounter = 0
if check.failureCounter < c.CriticalThreshold {
check.failureCounter++
return
}
check.failureCounter = 0

} else {
check.failureCounter = 0
if check.successCounter < c.PassingThreshold {
check.successCounter++
return
}
check.successCounter = 0

}

// Update the critical time tracking
Expand All @@ -319,6 +314,10 @@ func (c *CheckRunner) UpdateCheck(checkID types.CheckID, status, output string)
delete(c.checksCritical, checkID)
}

// Do nothing if update is idempotent
if check.Status == status && check.Output == output {
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure I'm understanding things... moving this return is the 'fix'. So it doesn't skip things between the old return and this one? Wanted to be sure as much of this just seems like a refactor/cleanup but it is fixing something and how this fixes it wasn't called out anywhere (or I missed it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1, the bug is , if check.Status is cirtical at first(which esm got from consul-agent), and esm checked it again and found it's cirtical, then this process will return. But in fact we need to do something with it.
2, I had checked that this bug is since 0350cc6. I just revert the code to before commit 0350cc6.

}
// Defer a sync if the output has changed. This is an optimization around
// frequent updates of output. Instead, we update the output internally,
// and periodically do a write-back to the servers. If there is a status
Expand Down
9 changes: 7 additions & 2 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestCheck_NoFlapping(t *testing.T) {

runner.UpdateCheck(id, api.HealthPassing, "")
assert.Equal(t, 0, originalCheck.failureCounter)
assert.Equal(t, 0, originalCheck.successCounter)
assert.Equal(t, 2, originalCheck.successCounter)
assert.Equal(t, api.HealthPassing, originalCheck.Status)

// test non-consecutive checks: non-consecutive will increment and
Expand All @@ -368,6 +368,11 @@ func TestCheck_NoFlapping(t *testing.T) {
assert.Equal(t, api.HealthPassing, originalCheck.Status)

runner.UpdateCheck(id, api.HealthPassing, "")
assert.Equal(t, 0, originalCheck.failureCounter)
assert.Equal(t, 1, originalCheck.successCounter)
assert.Equal(t, api.HealthPassing, originalCheck.Status)

runner.UpdateCheck(id, api.HealthCritical, "")
assert.Equal(t, 1, originalCheck.failureCounter)
assert.Equal(t, 0, originalCheck.successCounter)
assert.Equal(t, api.HealthPassing, originalCheck.Status)
Expand All @@ -378,7 +383,7 @@ func TestCheck_NoFlapping(t *testing.T) {
assert.Equal(t, api.HealthPassing, originalCheck.Status)

runner.UpdateCheck(id, api.HealthCritical, "")
assert.Equal(t, 0, originalCheck.failureCounter)
assert.Equal(t, 2, originalCheck.failureCounter)
assert.Equal(t, 0, originalCheck.successCounter)
assert.Equal(t, api.HealthCritical, originalCheck.Status)
}