-
Notifications
You must be signed in to change notification settings - Fork 79
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
Make Fleet Server components resilient if the indices do not exist #68
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ package coordinator | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"net" | ||
"os" | ||
"runtime" | ||
|
@@ -184,7 +185,11 @@ func (m *monitorT) ensureLeadership(ctx context.Context) error { | |
leaders := map[string]model.PolicyLeader{} | ||
policies, err := dl.QueryLatestPolicies(ctx, m.bulker, dl.WithIndexName(m.policiesIndex)) | ||
if err != nil { | ||
return err | ||
if errors.Is(err, es.ErrIndexNotFound) { | ||
err = nil | ||
} else { | ||
return err | ||
} | ||
} | ||
if len(policies) > 0 { | ||
ids := make([]string, len(policies)) | ||
|
@@ -193,7 +198,11 @@ func (m *monitorT) ensureLeadership(ctx context.Context) error { | |
} | ||
leaders, err = dl.SearchPolicyLeaders(ctx, m.bulker, ids, dl.WithIndexName(m.leadersIndex)) | ||
if err != nil { | ||
return err | ||
if errors.Is(err, es.ErrIndexNotFound) { | ||
err = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, debug log? |
||
} else { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,11 @@ package migrate | |
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
|
||
"github.com/elastic/fleet-server/v7/internal/pkg/bulk" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/dl" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/es" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/model" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/saved" | ||
) | ||
|
@@ -42,12 +45,19 @@ func MigrateEnrollmentAPIKeys(ctx context.Context, sv saved.CRUD, bulker bulk.Bu | |
} | ||
|
||
var recs []model.EnrollmentApiKey | ||
var resHits []es.HitT | ||
res, err := bulker.Search(ctx, []string{dl.FleetEnrollmentAPIKeys}, raw, bulk.WithRefresh()) | ||
if err != nil { | ||
return err | ||
if errors.Is(err, es.ErrIndexNotFound) { | ||
err = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug log? Could we directly return nil here or do we need to run the rest of the code below? |
||
} else { | ||
return err | ||
} | ||
} else { | ||
resHits = res.Hits | ||
} | ||
|
||
for _, hit := range res.Hits { | ||
for _, hit := range resHits { | ||
var rec model.EnrollmentApiKey | ||
err := json.Unmarshal(hit.Source, &rec) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"bytes" | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"sync/atomic" | ||
"time" | ||
|
||
|
@@ -291,7 +292,14 @@ func (m *simpleMonitorT) search(ctx context.Context, tmpl *dsl.Tmpl, params map[ | |
} | ||
|
||
if res.IsError() { | ||
return nil, es.TranslateError(res.StatusCode, esres.Error) | ||
err = es.TranslateError(res.StatusCode, esres.Error) | ||
} | ||
|
||
if err != nil { | ||
if errors.Is(err, es.ErrIndexNotFound) { | ||
return nil, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug log? |
||
} | ||
return nil, err | ||
} | ||
|
||
return esres.Hits.Hits, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
|
||
"github.com/elastic/fleet-server/v7/internal/pkg/bulk" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/dl" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/es" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/model" | ||
"github.com/elastic/fleet-server/v7/internal/pkg/monitor" | ||
) | ||
|
@@ -125,6 +126,11 @@ LOOP: | |
func (m *monitorT) process(ctx context.Context) error { | ||
policies, err := m.policyF(ctx, m.bulker, dl.WithIndexName(m.policiesIndex)) | ||
if err != nil { | ||
if errors.Is(err, es.ErrIndexNotFound) { | ||
err = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug log? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also return here immediately? There won't be any policies yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't know what I was thinking yesterday. will update. |
||
} else { | ||
err = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be |
||
} | ||
return err | ||
} | ||
if len(policies) == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a debug log here to make it easier to debug issues?