Skip to content

Commit

Permalink
Set default separator to '-', remove 'none' config
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Zhengwei <[email protected]>

Signed-off-by: chen zhengwei <[email protected]>
  • Loading branch information
sniperking1234 committed Nov 23, 2020
1 parent 7aef0b3 commit 07d7103
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
13 changes: 3 additions & 10 deletions plugin/storage/es/esCleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main():
prefix = os.getenv("INDEX_PREFIX", '')
if prefix != '':
prefix += '-'
separator = os.getenv("INDEX_DATE_SEPARATOR", '')
separator = os.getenv("INDEX_DATE_SEPARATOR", '-')

if str2bool(os.getenv("ARCHIVE", 'false')):
filter_archive_indices_rollover(ilo, prefix)
Expand All @@ -54,15 +54,8 @@ def main():


def filter_main_indices(ilo, prefix, separator):
date_regex = "\d{4}-\d{2}-\d{2}"
time_string = "%Y-%m-%d"
if separator != "":
if separator == "none":
date_regex = "\d{4}\d{2}\d{2}"
time_string = "%Y%m%d"
else:
date_regex = "\d{4}" + separator + "\d{2}" + separator + "\d{2}"
time_string = "%Y" + separator + "%m" + separator + "%d"
date_regex = "\d{4}" + separator + "\d{2}" + separator + "\d{2}"
time_string = "%Y" + separator + "%m" + separator + "%d"

ilo.filter_by_regex(kind='regex', value=prefix + "jaeger-(span|service|dependencies)-" + date_regex)
empty_list(ilo, "No indices to delete")
Expand Down
24 changes: 7 additions & 17 deletions plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ const (

// default number of documents to return from a query (elasticsearch allowed limit)
// see search.max_buckets and index.max_result_window
defaultMaxDocCount = 10_000
defaultServerURL = "http://127.0.0.1:9200"
defaultIndexDateLayout = "2006-01-02" // date format for index e.g. 2020-01-20
defaultMaxDocCount = 10_000
defaultServerURL = "http://127.0.0.1:9200"
// default separator for Elasticsearch index date layout.
defaultIndexDateSeparator = "-"
)

// TODO this should be moved next to config.Configuration struct (maybe ./flags package)
Expand Down Expand Up @@ -215,8 +216,8 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
"Optional prefix of Jaeger indices. For example \"production\" creates \"production-jaeger-*\".")
flagSet.String(
nsConfig.namespace+suffixIndexDateSeparator,
"",
"Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20 \".")
defaultIndexDateSeparator,
"Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20 \". This config is "+defaultIndexDateSeparator+" by default")
flagSet.Bool(
nsConfig.namespace+suffixTagsAsFieldsAll,
nsConfig.Tags.AllAsFields,
Expand Down Expand Up @@ -335,16 +336,5 @@ func stripWhiteSpace(str string) string {
}

func initDateLayout(separator string) string {
var dateLayout string
if separator != "" {
switch separator {
case "none":
dateLayout = "20060102"
default:
dateLayout = fmt.Sprintf("2006%s01%s02", separator, separator)
}
} else {
dateLayout = defaultIndexDateLayout
}
return dateLayout
return fmt.Sprintf("2006%s01%s02", separator, separator)
}
29 changes: 17 additions & 12 deletions plugin/storage/es/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestOptionsWithFlags(t *testing.T) {
"--es.max-span-age=48h",
"--es.num-shards=20",
"--es.num-replicas=10",
"--es.index-date-separator=none",
"--es.index-date-separator=-",
// a couple overrides
"--es.aux.server-urls=3.3.3.3, 4.4.4.4",
"--es.aux.max-span-age=24h",
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, "!", primary.Tags.DotReplacement)
assert.Equal(t, "./file.txt", primary.Tags.File)
assert.Equal(t, "test,tags", primary.Tags.Include)
assert.Equal(t, "20060102", primary.IndexDateLayout)
assert.Equal(t, "2006-01-02", primary.IndexDateLayout)

aux := opts.Get("es.aux")
assert.Equal(t, []string{"3.3.3.3", "4.4.4.4"}, aux.Servers)
Expand Down Expand Up @@ -153,21 +153,26 @@ func TestMaxDocCount(t *testing.T) {
}
}

func TestDateLayout(t *testing.T) {
func TestIndexDateSeparator(t *testing.T) {
testCases := []struct {
name string
separator string
wantLayout string
name string
flags []string
wantDateLayout string
}{
{"default", "", "2006-01-02"},
{"crossbar", "-", "2006-01-02"},
{"normal separator", ".", "2006.01.02"},
{"none separator", "none", "20060102"},
{"not defined", []string{}, "2006-01-02"},
{"empty string", []string{"--es.index-date-separator="}, "20060102"},
{"normal separator", []string{"--es.index-date-separator=."}, "2006.01.02"},
{"crossbar", []string{"--es.index-date-separator=-"}, "2006-01-02"},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dateLayout := initDateLayout(tc.separator)
assert.Equal(t, dateLayout, tc.wantLayout)
opts := NewOptions("es")
v, command := config.Viperize(opts.AddFlags)
command.ParseFlags(tc.flags)
opts.InitFromViper(v)

primary := opts.GetPrimary()
assert.Equal(t, tc.wantDateLayout, primary.IndexDateLayout)
})
}
}

0 comments on commit 07d7103

Please sign in to comment.