Skip to content

Commit

Permalink
Extend es-rollover and es-index-cleaner to support rolling dependenci…
Browse files Browse the repository at this point in the history
…es indices

Signed-off-by: Christian Rohmann <[email protected]>
  • Loading branch information
frittentheke committed Feb 1, 2022
1 parent 82a1d09 commit a3cb643
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
7 changes: 5 additions & 2 deletions cmd/es-index-cleaner/app/index_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (i *IndexFilter) filter(indices []client.Index) []client.Index {
// archive works only for rollover
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-span-archive-\\d{6}", i.IndexPrefix))
} else if i.Rollover {
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service)-\\d{6}", i.IndexPrefix))
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service|dependencies)-\\d{6}", i.IndexPrefix))
} else {
reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service|dependencies)-\\d{4}%s\\d{2}%s\\d{2}", i.IndexPrefix, i.IndexDateSeparator, i.IndexDateSeparator))
}
Expand All @@ -58,7 +58,10 @@ func (i *IndexFilter) filter(indices []client.Index) []client.Index {
for _, in := range indices {
if reg.MatchString(in.Index) {
// index in write alias cannot be removed
if in.Aliases[i.IndexPrefix+"jaeger-span-write"] || in.Aliases[i.IndexPrefix+"jaeger-service-write"] || in.Aliases[i.IndexPrefix+"jaeger-span-archive-write"] {
if in.Aliases[i.IndexPrefix+"jaeger-span-write"] ||
in.Aliases[i.IndexPrefix+"jaeger-service-write"] ||
in.Aliases[i.IndexPrefix+"jaeger-span-archive-write"] ||
in.Aliases[i.IndexPrefix+"jaeger-dependencies-write"] {
continue
}
filtered = append(filtered, in)
Expand Down
5 changes: 5 additions & 0 deletions cmd/es-rollover/app/index_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func RolloverIndices(archive bool, prefix string) []IndexOption {
Mapping: "jaeger-service",
indexType: "jaeger-service",
},
{
prefix: prefix,
Mapping: "jaeger-dependencies",
indexType: "jaeger-dependencies",
},
}
}

Expand Down
14 changes: 14 additions & 0 deletions cmd/es-rollover/app/index_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func TestRolloverIndices(t *testing.T) {
writeAliasName: "jaeger-service-write",
initialRolloverIndex: "jaeger-service-000001",
},
{
templateName: "jaeger-dependencies",
mapping: "jaeger-dependencies",
readAliasName: "jaeger-dependencies-read",
writeAliasName: "jaeger-dependencies-write",
initialRolloverIndex: "jaeger-dependencies-000001",
},
},
},
{
Expand Down Expand Up @@ -99,6 +106,13 @@ func TestRolloverIndices(t *testing.T) {
writeAliasName: "mytenant-jaeger-service-write",
initialRolloverIndex: "mytenant-jaeger-service-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
6 changes: 3 additions & 3 deletions plugin/storage/integration/es_index_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestIndexCleaner(t *testing.T) {
envVars: []string{},
expectedIndices: []string{
archiveIndexName,
"jaeger-span-000001", "jaeger-service-000001", "jaeger-span-000002", "jaeger-service-000002",
"jaeger-span-000001", "jaeger-service-000001", "jaeger-dependencies-000001", "jaeger-span-000002", "jaeger-service-000002", "jaeger-dependencies-000002",
"jaeger-span-archive-000001", "jaeger-span-archive-000002",
},
},
Expand All @@ -100,7 +100,7 @@ func TestIndexCleaner(t *testing.T) {
envVars: []string{"ROLLOVER=true"},
expectedIndices: []string{
archiveIndexName, spanIndexName, serviceIndexName, dependenciesIndexName,
"jaeger-span-000002", "jaeger-service-000002",
"jaeger-span-000002", "jaeger-service-000002", "jaeger-dependencies-000002",
"jaeger-span-archive-000001", "jaeger-span-archive-000002",
},
},
Expand All @@ -109,7 +109,7 @@ func TestIndexCleaner(t *testing.T) {
envVars: []string{"ARCHIVE=true"},
expectedIndices: []string{
archiveIndexName, spanIndexName, serviceIndexName, dependenciesIndexName,
"jaeger-span-000001", "jaeger-service-000001", "jaeger-span-000002", "jaeger-service-000002",
"jaeger-span-000001", "jaeger-service-000001", "jaeger-dependencies-000001", "jaeger-span-000002", "jaeger-service-000002", "jaeger-dependencies-000002",
"jaeger-span-archive-000002",
},
},
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/integration/es_index_rollover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func runCreateIndicesWithILM(t *testing.T, ilmPolicyName string) {
assert.Empty(t, indices)

} else {
expectedIndices := []string{"jaeger-span-000001", "jaeger-service-000001"}
expectedIndices := []string{"jaeger-span-000001", "jaeger-service-000001", "jaeger-dependencies-000001"}
t.Run(fmt.Sprintf("NoPrefix"), func(t *testing.T) {
runIndexRolloverWithILMTest(t, client, "", expectedIndices, envVars, ilmPolicyName)
})
Expand All @@ -101,7 +101,7 @@ func runCreateIndicesWithILM(t *testing.T, ilmPolicyName string) {
}

func runIndexRolloverWithILMTest(t *testing.T, client *elastic.Client, prefix string, expectedIndices, envVars []string, ilmPolicyName string) {
writeAliases := []string{"jaeger-service-write", "jaeger-span-write"}
writeAliases := []string{"jaeger-service-write", "jaeger-span-write", "jaeger-dependencies-write"}

// make sure ES is cleaned before test
cleanES(t, client, ilmPolicyName)
Expand Down

0 comments on commit a3cb643

Please sign in to comment.