Skip to content

Commit

Permalink
Update graceful handling for missing indices to accommodate the new f…
Browse files Browse the repository at this point in the history
…leet system indices plugin (#205) (#231)

* Update the no index found handling to accommodate the new fleet system indices plugin

* Add logging

(cherry picked from commit 85d0ebf)

Co-authored-by: Aleksandr Maus <[email protected]>
  • Loading branch information
mergify[bot] and aleksmaus authored Apr 13, 2021
1 parent a4be496 commit c5e7d9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/pkg/dl/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package dl

import (
"context"
"errors"

"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
"github.com/elastic/fleet-server/v7/internal/pkg/dsl"
"github.com/elastic/fleet-server/v7/internal/pkg/es"
"github.com/elastic/fleet-server/v7/internal/pkg/model"
"github.com/rs/zerolog/log"
)

const (
Expand Down Expand Up @@ -83,6 +86,10 @@ func FindActions(ctx context.Context, bulker bulk.Bulk, tmpl *dsl.Tmpl, params m
func findActions(ctx context.Context, bulker bulk.Bulk, tmpl *dsl.Tmpl, index string, params map[string]interface{}) ([]model.Action, error) {
res, err := Search(ctx, bulker, tmpl, index, params)
if err != nil {
if errors.Is(err, es.ErrIndexNotFound) {
log.Debug().Str("index", index).Msg(es.ErrIndexNotFound.Error())
err = nil
}
return nil, err
}

Expand Down
11 changes: 9 additions & 2 deletions internal/pkg/dl/policies_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ package dl
import (
"context"
"encoding/json"
"errors"
"sync"
"time"

"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
"github.com/elastic/fleet-server/v7/internal/pkg/dsl"
"github.com/elastic/fleet-server/v7/internal/pkg/es"
"github.com/elastic/fleet-server/v7/internal/pkg/model"
"sync"
"time"
"github.com/rs/zerolog/log"
)

var (
Expand Down Expand Up @@ -48,6 +51,10 @@ func SearchPolicyLeaders(ctx context.Context, bulker bulk.Bulk, ids []string, op
}
res, err := bulker.Search(ctx, []string{o.indexName}, data)
if err != nil {
if errors.Is(err, es.ErrIndexNotFound) {
log.Debug().Str("index", o.indexName).Msg(es.ErrIndexNotFound.Error())
err = nil
}
return
}

Expand Down

0 comments on commit c5e7d9a

Please sign in to comment.