-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[abandoned][es] Add index rollover mode that can choose day and hour #2935
Changes from 2 commits
328939c
9e49fc7
1e2affd
ff61a02
29ca0e1
0435ed9
b79d7a7
7e564d4
5824c2e
6d8982f
c8e5556
278203c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ const ( | |
suffixTimeout = ".timeout" | ||
suffixIndexPrefix = ".index-prefix" | ||
suffixIndexDateSeparator = ".index-date-separator" | ||
suffixIndexRotate = ".index-rotate" | ||
suffixTagsAsFields = ".tags-as-fields" | ||
suffixTagsAsFieldsAll = suffixTagsAsFields + ".all" | ||
suffixTagsAsFieldsInclude = suffixTagsAsFields + ".include" | ||
|
@@ -65,6 +66,8 @@ const ( | |
defaultRemoteReadClusters = "" | ||
// default separator for Elasticsearch index date layout. | ||
defaultIndexDateSeparator = "-" | ||
|
||
defaultIndexRotate = "day" | ||
) | ||
|
||
// TODO this should be moved next to config.Configuration struct (maybe ./flags package) | ||
|
@@ -205,7 +208,11 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) { | |
flagSet.String( | ||
nsConfig.namespace+suffixIndexDateSeparator, | ||
defaultIndexDateSeparator, | ||
"Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20 \".") | ||
"Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20\".") | ||
flagSet.String( | ||
nsConfig.namespace+suffixIndexRotate, | ||
defaultIndexRotate, | ||
"Optional rotation opportunity of Jaeger indices. For example \"day\" creates \"jaeger-span-yyyy-HH-dd\" every day after UTC 12AM. Valid opportunity: [hour, day]") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As you suggested, I would add a reference to the alternative esRollover and ILM solutions. |
||
flagSet.Bool( | ||
nsConfig.namespace+suffixTagsAsFieldsAll, | ||
nsConfig.Tags.AllAsFields, | ||
|
@@ -295,7 +302,6 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) { | |
cfg.BulkFlushInterval = v.GetDuration(cfg.namespace + suffixBulkFlushInterval) | ||
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout) | ||
cfg.IndexPrefix = v.GetString(cfg.namespace + suffixIndexPrefix) | ||
cfg.IndexDateLayout = initDateLayout(v.GetString(cfg.namespace + suffixIndexDateSeparator)) | ||
cfg.Tags.AllAsFields = v.GetBool(cfg.namespace + suffixTagsAsFieldsAll) | ||
cfg.Tags.Include = v.GetString(cfg.namespace + suffixTagsAsFieldsInclude) | ||
cfg.Tags.File = v.GetString(cfg.namespace + suffixTagsFile) | ||
|
@@ -317,6 +323,19 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) { | |
if len(remoteReadClusters) > 0 { | ||
cfg.RemoteReadClusters = strings.Split(remoteReadClusters, ",") | ||
} | ||
|
||
indexRotate := strings.ToLower(v.GetString(cfg.namespace + suffixIndexRotate)) | ||
|
||
switch indexRotate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can DRY and simplify to something like:
|
||
case "day": | ||
cfg.IndexDateLayout = initDateLayoutDay(v.GetString(cfg.namespace + suffixIndexDateSeparator)) | ||
|
||
case "hour": | ||
cfg.IndexDateLayout = initDateLayoutHours(v.GetString(cfg.namespace + suffixIndexDateSeparator)) | ||
|
||
default: | ||
cfg.IndexDateLayout = initDateLayoutDay(v.GetString(cfg.namespace + suffixIndexDateSeparator)) | ||
} | ||
} | ||
|
||
// GetPrimary returns primary configuration. | ||
|
@@ -343,6 +362,10 @@ func stripWhiteSpace(str string) string { | |
return strings.Replace(str, " ", "", -1) | ||
} | ||
|
||
func initDateLayout(separator string) string { | ||
func initDateLayoutDay(separator string) string { | ||
return fmt.Sprintf("2006%s01%s02", separator, separator) | ||
} | ||
|
||
func initDateLayoutHours(separator string) string { | ||
return fmt.Sprintf("2006%s01%s02%s15", separator, separator, separator) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,8 +200,12 @@ func timeRangeIndices(indexName, indexDateLayout string, startTime time.Time, en | |
firstIndex := indexWithDate(indexName, indexDateLayout, startTime) | ||
currentIndex := indexWithDate(indexName, indexDateLayout, endTime) | ||
for currentIndex != firstIndex { | ||
indices = append(indices, currentIndex) | ||
endTime = endTime.Add(-24 * time.Hour) | ||
if len(indices) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be simplified:
|
||
indices = append(indices, currentIndex) | ||
} else if indices[len(indices)-1] != currentIndex { | ||
indices = append(indices, currentIndex) | ||
} | ||
endTime = endTime.Add(-1 * time.Hour) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this will do 24 iterations on every invocation, even though the default is daily rotation? Could we make this more efficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok let me take a look |
||
currentIndex = indexWithDate(indexName, indexDateLayout, endTime) | ||
} | ||
indices = append(indices, firstIndex) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES uses the term
Rollover
, I think we should stay consistent with terminology.