Skip to content

Commit

Permalink
Do not throw error on empty indices in Elasticsach rollover lookback (#…
Browse files Browse the repository at this point in the history
…3369)

* es rollover lookback, do not throw error on no indices

Signed-off-by: Jeeva Kandasamy <[email protected]>

* parameters as zap paremeters

Signed-off-by: Jeeva Kandasamy <[email protected]>

* update unit test for no indices

Signed-off-by: Jeeva Kandasamy <[email protected]>

* initialize logger in unit tests

Signed-off-by: Jeeva Kandasamy <[email protected]>
  • Loading branch information
jkandasa committed Nov 3, 2021
1 parent 72f8af5 commit 5b89720
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cmd/es-rollover/app/lookback/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package lookback

import (
"fmt"
"time"

"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/es-rollover/app"
"github.com/jaegertracing/jaeger/pkg/es/client"
"github.com/jaegertracing/jaeger/pkg/es/filter"
Expand All @@ -29,6 +30,7 @@ var timeNow func() time.Time = time.Now
type Action struct {
Config
IndicesClient client.IndexAPI
Logger *zap.Logger
}

// Do the lookback action
Expand All @@ -54,16 +56,19 @@ func (a *Action) lookback(indexSet app.IndexOption) error {
finalIndices := filter.ByDate(excludedWriteIndex, getTimeReference(timeNow(), a.Unit, a.UnitCount))

if len(finalIndices) == 0 {
return fmt.Errorf("no indices to remove from alias %s", readAliasName)
a.Logger.Info("No indices to remove from alias", zap.String("readAliasName", readAliasName))
return nil
}

aliases := make([]client.Alias, 0, len(finalIndices))
a.Logger.Info("About to remove indices", zap.String("readAliasName", readAliasName), zap.Int("indicesCount", len(finalIndices)))

for _, index := range finalIndices {
aliases = append(aliases, client.Alias{
Index: index.Index,
Name: readAliasName,
})
a.Logger.Info("To be removed", zap.String("index", index.Index), zap.String("creationTime", index.CreationTime.String()))
}

return a.IndicesClient.DeleteAlias(aliases)
Expand Down
8 changes: 6 additions & 2 deletions cmd/es-rollover/app/lookback/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/es-rollover/app"
"github.com/jaegertracing/jaeger/pkg/es/client"
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestLookBackAction(t *testing.T) {
expectedErr: errors.New("get indices error"),
},
{
name: "empty indices error",
name: "empty indices",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
},
Expand All @@ -128,16 +129,19 @@ func TestLookBackAction(t *testing.T) {
UseILM: true,
},
},
expectedErr: errors.New("no indices to remove from alias jaeger-span-archive-read"),
expectedErr: nil,
},
}

logger, _ := zap.NewProduction()

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexClient := &mocks.MockIndexAPI{}
lookbackAction := Action{
Config: test.config,
IndicesClient: indexClient,
Logger: logger,
}

test.setupCallExpectations(indexClient)
Expand Down
1 change: 1 addition & 0 deletions cmd/es-rollover/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func main() {
return &lookback.Action{
IndicesClient: indicesClient,
Config: lookbackCfg,
Logger: logger,
}
})
},
Expand Down

0 comments on commit 5b89720

Please sign in to comment.