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

Do not throw error on empty indices in Elasticsach rollover lookback #3369

Merged
merged 6 commits into from
Nov 3, 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
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