From 07d71039eba3fd156302ae47b85eede28c1b202d Mon Sep 17 00:00:00 2001 From: chen zhengwei Date: Mon, 23 Nov 2020 14:55:53 +0800 Subject: [PATCH] Set default separator to '-', remove 'none' config Signed-off-by: Chen Zhengwei Signed-off-by: chen zhengwei --- plugin/storage/es/esCleaner.py | 13 +++---------- plugin/storage/es/options.go | 24 +++++++----------------- plugin/storage/es/options_test.go | 29 +++++++++++++++++------------ 3 files changed, 27 insertions(+), 39 deletions(-) diff --git a/plugin/storage/es/esCleaner.py b/plugin/storage/es/esCleaner.py index 4b83f8d2db0..336704cf03d 100755 --- a/plugin/storage/es/esCleaner.py +++ b/plugin/storage/es/esCleaner.py @@ -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) @@ -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") diff --git a/plugin/storage/es/options.go b/plugin/storage/es/options.go index 68f1c16da43..bba622d67e6 100644 --- a/plugin/storage/es/options.go +++ b/plugin/storage/es/options.go @@ -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) @@ -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, @@ -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) } diff --git a/plugin/storage/es/options_test.go b/plugin/storage/es/options_test.go index f25c25eeae9..1f7762f8a0f 100644 --- a/plugin/storage/es/options_test.go +++ b/plugin/storage/es/options_test.go @@ -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", @@ -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) @@ -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) }) } }