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

added more detailed logs around ES communication failure #992

Merged
merged 2 commits into from
Dec 28, 2021
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
12 changes: 12 additions & 0 deletions cmd/fleet/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"net/http"
"os"
"strings"

"github.com/elastic/fleet-server/v7/internal/pkg/dl"
"github.com/elastic/fleet-server/v7/internal/pkg/limit"
Expand Down Expand Up @@ -144,6 +145,17 @@ func NewErrorResp(err error) errResp {
}
}

// Check if we have encountered a connectivity error
// Predicate taken from https://github.com/golang/go/blob/go1.17.5/src/net/dial_test.go#L798
if strings.Contains(err.Error(), "connection refused") {
return errResp{
http.StatusServiceUnavailable,
"ServiceUnavailable",
"Fleet server unable to communicate with Elasticsearch",
zerolog.InfoLevel,
}
}

// Default
return errResp{
StatusCode: http.StatusBadRequest,
Expand Down
13 changes: 13 additions & 0 deletions internal/pkg/coordinator/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ func (m *monitorT) Run(ctx context.Context) (err error) {
// Start timer loop to ensure leadership
lT := time.NewTimer(m.checkInterval)
defer lT.Stop()

// Keep track of errored statuses
erroredOnLastRequest := false
numFailedRequests := 0
for {
select {
case hits := <-s.Output():
err = m.handlePolicies(ctx, hits)
if err != nil {
erroredOnLastRequest = true
numFailedRequests++
m.log.Warn().Err(err).Msgf("Encountered an error while policy leadership changes; continuing to retry.")
}
case <-mT.C:
Expand All @@ -141,13 +147,20 @@ func (m *monitorT) Run(ctx context.Context) (err error) {
case <-lT.C:
err = m.ensureLeadership(ctx)
if err != nil {
erroredOnLastRequest = true
numFailedRequests++
m.log.Warn().Err(err).Msgf("Encountered an error while checking/assigning policy leaders; continuing to retry.")
}
lT.Reset(m.checkInterval)
case <-ctx.Done():
m.releaseLeadership()
return ctx.Err()
}
if err == nil && erroredOnLastRequest {
erroredOnLastRequest = false
m.log.Info().Msgf("Policy leader monitor successfully recovered after %d attempts", numFailedRequests)
numFailedRequests = 0
}
}
}

Expand Down