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

Add flag to enable/disable dependencies on rollover #3705

Merged
merged 1 commit into from
May 27, 2022
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
34 changes: 19 additions & 15 deletions cmd/es-rollover/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@ import (
)

const (
indexPrefix = "index-prefix"
archive = "archive"
username = "es.username"
password = "es.password"
useILM = "es.use-ilm"
ilmPolicyName = "es.ilm-policy-name"
timeout = "timeout"
indexPrefix = "index-prefix"
archive = "archive"
username = "es.username"
password = "es.password"
useILM = "es.use-ilm"
ilmPolicyName = "es.ilm-policy-name"
timeout = "timeout"
skipDependencies = "skip-dependencies"
)

// Config holds the global configurations for the es rollover, common to all actions
type Config struct {
IndexPrefix string
Archive bool
Username string
Password string
TLSEnabled bool
ILMPolicyName string
UseILM bool
Timeout int
IndexPrefix string
Archive bool
Username string
Password string
TLSEnabled bool
ILMPolicyName string
UseILM bool
Timeout int
SkipDependencies bool
}

// AddFlags adds flags
Expand All @@ -51,6 +53,8 @@ func AddFlags(flags *flag.FlagSet) {
flags.Bool(useILM, false, "Use ILM to manage jaeger indices")
flags.String(ilmPolicyName, "jaeger-ilm-policy", "The name of the ILM policy to use if ILM is active")
flags.Int(timeout, 120, "Number of seconds to wait for master node response")
flags.Bool(skipDependencies, false, "Disable rollover for dependencies index")

}

// InitFromViper initializes config from viper.Viper.
Expand Down
14 changes: 10 additions & 4 deletions cmd/es-rollover/app/index_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type IndexOption struct {
}

// RolloverIndices return an array of indices to rollover
func RolloverIndices(archive bool, prefix string) []IndexOption {
func RolloverIndices(archive bool, skipDependencies bool, prefix string) []IndexOption {
if archive {
return []IndexOption{
{
Expand All @@ -41,7 +41,8 @@ func RolloverIndices(archive bool, prefix string) []IndexOption {
},
}
}
return []IndexOption{

indexOptions := []IndexOption{
{
prefix: prefix,
Mapping: "jaeger-span",
Expand All @@ -52,12 +53,17 @@ func RolloverIndices(archive bool, prefix string) []IndexOption {
Mapping: "jaeger-service",
indexType: "jaeger-service",
},
{
}

if !skipDependencies {
indexOptions = append(indexOptions, IndexOption{
prefix: prefix,
Mapping: "jaeger-dependencies",
indexType: "jaeger-dependencies",
},
})
}

return indexOptions
}

func (i *IndexOption) IndexName() string {
Expand Down
39 changes: 34 additions & 5 deletions cmd/es-rollover/app/index_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func TestRolloverIndices(t *testing.T) {
}

tests := []struct {
name string
archive bool
prefix string
expected []expectedValues
name string
archive bool
prefix string
skipDependencies bool
expected []expectedValues
}{
{
name: "Empty prefix",
Expand Down Expand Up @@ -73,6 +74,13 @@ func TestRolloverIndices(t *testing.T) {
writeAliasName: "mytenant-jaeger-span-archive-write",
initialRolloverIndex: "mytenant-jaeger-span-archive-000001",
},
{
mapping: "jaeger-dependencies",
templateName: "mytenant-jaeger-dependencies",
readAliasName: "mytenant-jaeger-dependencies-read",
writeAliasName: "mytenant-jaeger-dependencies-write",
initialRolloverIndex: "mytenant-jaeger-dependencies-000001",
},
},
},
{
Expand Down Expand Up @@ -115,14 +123,35 @@ func TestRolloverIndices(t *testing.T) {
},
},
},
{
name: "dependency enable",
prefix: "mytenant",
skipDependencies: true,
expected: []expectedValues{
{
mapping: "jaeger-span",
templateName: "mytenant-jaeger-span",
readAliasName: "mytenant-jaeger-span-read",
writeAliasName: "mytenant-jaeger-span-write",
initialRolloverIndex: "mytenant-jaeger-span-000001",
},
{
mapping: "jaeger-service",
templateName: "mytenant-jaeger-service",
readAliasName: "mytenant-jaeger-service-read",
writeAliasName: "mytenant-jaeger-service-write",
initialRolloverIndex: "mytenant-jaeger-service-000001",
},
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.prefix != "" {
test.prefix += "-"
}
result := RolloverIndices(test.archive, test.prefix)
result := RolloverIndices(test.archive, test.skipDependencies, test.prefix)
for i, r := range result {
assert.Equal(t, test.expected[i].templateName, r.TemplateName())
assert.Equal(t, test.expected[i].mapping, r.Mapping)
Expand Down
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/init/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c Action) Do() error {
return fmt.Errorf("ILM is supported only for ES version 7+")
}
}
rolloverIndices := app.RolloverIndices(c.Config.Archive, c.Config.IndexPrefix)
rolloverIndices := app.RolloverIndices(c.Config.Archive, c.Config.SkipDependencies, c.Config.IndexPrefix)
for _, indexName := range rolloverIndices {
if err := c.init(version, indexName); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/lookback/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Action struct {

// Do the lookback action
func (a *Action) Do() error {
rolloverIndices := app.RolloverIndices(a.Config.Archive, a.Config.IndexPrefix)
rolloverIndices := app.RolloverIndices(a.Config.Archive, a.Config.SkipDependencies, a.Config.IndexPrefix)
for _, indexName := range rolloverIndices {
if err := a.lookback(indexName); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/rollover/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Action struct {

// Do the rollover action
func (a *Action) Do() error {
rolloverIndices := app.RolloverIndices(a.Config.Archive, a.Config.IndexPrefix)
rolloverIndices := app.RolloverIndices(a.Config.Archive, a.Config.SkipDependencies, a.Config.IndexPrefix)
for _, indexName := range rolloverIndices {
if err := a.rollover(indexName); err != nil {
return err
Expand Down