Skip to content

Explicit healty states #1890

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

Merged
merged 5 commits into from
Dec 11, 2019
Merged
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
18 changes: 13 additions & 5 deletions pkg/ring/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,20 @@ func (d *Desc) TokensFor(id string) (tokens, other []uint32) {

// IsHealthy checks whether the ingester appears to be alive and heartbeating
func (i *IngesterDesc) IsHealthy(op Operation, heartbeatTimeout time.Duration) bool {
if op == Write && i.State != ACTIVE {
return false
} else if op == Read && i.State == JOINING {
return false
healthy := false

switch op {
case Write:
healthy = (i.State == ACTIVE)

case Read:
healthy = (i.State == ACTIVE) || (i.State == LEAVING) || (i.State == PENDING)

case Reporting:
healthy = true
}
return time.Now().Sub(time.Unix(i.Timestamp, 0)) <= heartbeatTimeout

return healthy && time.Now().Sub(time.Unix(i.Timestamp, 0)) <= heartbeatTimeout
}

// Merge merges other ring into this one. Returns sub-ring that represents the change,
Expand Down
48 changes: 28 additions & 20 deletions pkg/ring/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,39 @@ func TestIngesterDesc_IsHealthy(t *testing.T) {
t.Parallel()

tests := map[string]struct {
ingester *IngesterDesc
timeout time.Duration
writeExpected bool
readExpected bool
ingester *IngesterDesc
timeout time.Duration
writeExpected bool
readExpected bool
reportExpected bool
}{
"ALIVE ingester with last keepalive newer than timeout": {
ingester: &IngesterDesc{State: ACTIVE, Timestamp: time.Now().Add(-30 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: true,
readExpected: true,
ingester: &IngesterDesc{State: ACTIVE, Timestamp: time.Now().Add(-30 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: true,
readExpected: true,
reportExpected: true,
},
"ALIVE ingester with last keepalive older than timeout": {
ingester: &IngesterDesc{State: ACTIVE, Timestamp: time.Now().Add(-90 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: false,
readExpected: false,
ingester: &IngesterDesc{State: ACTIVE, Timestamp: time.Now().Add(-90 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: false,
readExpected: false,
reportExpected: false,
},
"JOINING ingester with last keepalive newer than timeout": {
ingester: &IngesterDesc{State: JOINING, Timestamp: time.Now().Add(-30 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: false,
readExpected: false,
ingester: &IngesterDesc{State: JOINING, Timestamp: time.Now().Add(-30 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: false,
readExpected: false,
reportExpected: true,
},
"LEAVING ingester with last keepalive newer than timeout": {
ingester: &IngesterDesc{State: LEAVING, Timestamp: time.Now().Add(-30 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: false,
readExpected: true,
ingester: &IngesterDesc{State: LEAVING, Timestamp: time.Now().Add(-30 * time.Second).Unix()},
timeout: time.Minute,
writeExpected: false,
readExpected: true,
reportExpected: true,
},
}

Expand All @@ -51,6 +56,9 @@ func TestIngesterDesc_IsHealthy(t *testing.T) {

actual = testData.ingester.IsHealthy(Read, testData.timeout)
assert.Equal(t, testData.readExpected, actual)

actual = testData.ingester.IsHealthy(Reporting, testData.timeout)
assert.Equal(t, testData.reportExpected, actual)
})
}
}
Expand Down