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

app/health: fix peer and error checks #2411

Merged
merged 2 commits into from
Jul 7, 2023
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
19 changes: 11 additions & 8 deletions app/health/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ type query func(name string, selector labelSelector, reducer seriesReducer) (flo
// checks is a list of health checks.
var checks = []check{
{
Name: "error_logs",
Description: "Error logs detected that require human intervention.",
Severity: severityCritical,
Func: func(q query, _ Metadata) (bool, error) {
// TODO(corver): Change this to critical on any error once we aligned with only logging errors when human intervention is required.
Name: "high_error_log_rate",
Description: "High rate of error logs. Please check the logs for more details.",
Severity: severityWarning,
Func: func(q query, m Metadata) (bool, error) {
increase, err := q("app_log_error_total", noLabels, increase)
if err != nil {
return false, err
}

return increase > 0, nil
return increase > 2*float64(m.NumValidators), nil // Allow 2 errors per validator.
},
},
{
Name: "high_warning_log_rate",
Description: "High rate of warning logs. Please check the logs for more details.",
Severity: severityCritical,
Severity: severityWarning,
Func: func(q query, m Metadata) (bool, error) {
increase, err := q("app_log_warning_total", noLabels, increase)
if err != nil {
Expand Down Expand Up @@ -83,12 +84,14 @@ var checks = []check{
Description: "Not connected to at least quorum peers. Check logs for networking issue or coordinate with peers.",
Severity: severityCritical,
Func: func(q query, m Metadata) (bool, error) {
max, err := q("ping_success", countNonZeroLabels, gaugeMax)
max, err := q("p2p_ping_success", countNonZeroLabels, gaugeMax)
if err != nil {
return false, err
}

return max < float64(m.QuorumPeers), nil
required := float64(m.QuorumPeers) - 1 // Exclude self

return max < required, nil
},
},
{
Expand Down
18 changes: 10 additions & 8 deletions app/health/checks_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestInsufficientPeerCheck(t *testing.T) {
QuorumPeers: 2,
}
checkName := "insufficient_connected_peers"
metricName := "ping_success"
metricName := "p2p_ping_success"

peer1 := genLabels("peer", "1")
peer2 := genLabels("peer", "2")
Expand Down Expand Up @@ -216,8 +216,10 @@ func TestBNSyncingCheck(t *testing.T) {
}

func TestErrorLogsCheck(t *testing.T) {
m := Metadata{}
checkName := "error_logs"
m := Metadata{
NumValidators: 10,
}
checkName := "high_error_log_rate"
metricName := "app_log_error_total"

t.Run("no data", func(t *testing.T) {
Expand All @@ -236,15 +238,15 @@ func TestErrorLogsCheck(t *testing.T) {
)
})

t.Run("single error", func(t *testing.T) {
testCheck(t, m, checkName, true,
genFam(metricName, genCounter(nil, 0, 0, 1)),
t.Run("too few", func(t *testing.T) {
testCheck(t, m, checkName, false,
genFam(metricName, genCounter(nil, 0, 0, 10)),
)
})

t.Run("multiple errors", func(t *testing.T) {
t.Run("sufficient", func(t *testing.T) {
testCheck(t, m, checkName, true,
genFam(metricName, genCounter(nil, 10, 20, 30, 40, 50)),
genFam(metricName, genCounter(nil, 10, 20, 30, 40, 500)),
)
})
}
Expand Down