-
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
Support configurable date separator for Elasticsearch index names #2637
Support configurable date separator for Elasticsearch index names #2637
Conversation
Signed-off-by: Chen Zhengwei <[email protected]> Signed-off-by: chen zhengwei <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #2637 +/- ##
=======================================
Coverage 95.54% 95.54%
=======================================
Files 214 214
Lines 9535 9546 +11
=======================================
+ Hits 9110 9121 +11
Misses 346 346
Partials 79 79
Continue to review full report at Codecov.
|
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.
Thanks for putting this together! I have a few comments about simplifying the flag default value and how we define the empty separator. Let me know what you think.
plugin/storage/es/esCleaner.py
Outdated
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" |
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.
If we follow the suggestion above, then this could reduce down to:
date_regex = "\d{4}" + separator + "\d{2}" + separator + "\d{2}"
time_string = "%Y" + separator + "%m" + separator + "%d"
Otherwise, could simplify the original logic to:
if not separator:
separator = "-"
elif separator == "none":
separator = ""
date_regex = "\d{4}" + separator + "\d{2}" + separator + "\d{2}"
time_string = "%Y" + separator + "%m" + separator + "%d"
plugin/storage/es/options_test.go
Outdated
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
dateLayout := initDateLayout(tc.separator) | ||
assert.Equal(t, dateLayout, tc.wantLayout) |
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.
Expectation comes first, i.e. assert.Equal(t, tc.wantLayout, dateLayout)
plugin/storage/es/options.go
Outdated
@@ -210,6 +213,10 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) { | |||
nsConfig.namespace+suffixIndexPrefix, | |||
nsConfig.IndexPrefix, | |||
"Optional prefix of Jaeger indices. For example \"production\" creates \"production-jaeger-*\".") | |||
flagSet.String( | |||
nsConfig.namespace+suffixIndexDateSeparator, | |||
"", |
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.
Could we set the default to what we want which is "-"
?
plugin/storage/es/esCleaner.py
Outdated
@@ -33,14 +34,15 @@ def main(): | |||
prefix = os.getenv("INDEX_PREFIX", '') | |||
if prefix != '': | |||
prefix += '-' | |||
separator = os.getenv("INDEX_DATE_SEPARATOR", '') |
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.
As in other comments, I think we should default this to the default we want which is '-'
?
If users want the empty separator, they can export INDEX_DATE_SEPARATOR=''
, which seems more intuitive to me.
Signed-off-by: Chen Zhengwei <[email protected]> Signed-off-by: chen zhengwei <[email protected]>
@albertteoh I made some changes, please review it again. Thank you! |
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.
Looks good to me, @sniperking1234 thanks! I've added a few minor comments.
plugin/storage/es/options_test.go
Outdated
@@ -55,10 +55,12 @@ func TestOptionsWithFlags(t *testing.T) { | |||
"--es.max-span-age=48h", | |||
"--es.num-shards=20", | |||
"--es.num-replicas=10", | |||
"--es.index-date-separator=-", |
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.
I prefer testing "--es.index-date-separator="
here because it's a unique case of passing in an empty value along with other flags. The "--es.aux.index-date-separator=."
below will test for a value passed in.
TestIndexDateSeparator
will then test the different possible separator inputs.
plugin/storage/es/options_test.go
Outdated
flags []string | ||
wantDateLayout string | ||
}{ | ||
{"not defined", []string{}, "2006-01-02"}, |
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.
I would also add tests for the following:
/
. Example:2006/01/02
''
. Example:2006''01''02
. I know it's odd to add such a test but I think it communicates two two things to developers:- Separators are currently not limited to single chars, unless if we enforce single char separators in this PR.
- Attempting to pass in an empty quoted string will actually use the quotes literally as separators.
Signed-off-by: Chen Zhengwei <[email protected]> Signed-off-by: chen zhengwei <[email protected]>
986b44c
to
4f722a1
Compare
plugin/storage/es/options_test.go
Outdated
{"dot separator", []string{"--es.index-date-separator=."}, "2006.01.02"}, | ||
{"crossbar separator", []string{"--es.index-date-separator=-"}, "2006-01-02"}, | ||
{"backslash separator", []string{"--es.index-date-separator=/"}, "2006/01/02"}, | ||
{"multiple characters separator", []string{"--es.index-date-separator=' '"}, "2006' '01' '02"}, |
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.
I actually meant empty string ''
to make it clear that empty quoted string is not treated as an empty separator :)
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.
Updated. Please check if the description of the test is appropriate.
Signed-off-by: Chen Zhengwei <[email protected]> Signed-off-by: chen zhengwei <[email protected]>
c84eb95
to
7b4e2de
Compare
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.
LGTM, @sniperking1234, thanks!
CI failed in TestReload unit test, but passed in my local test. How to fix it? |
@sniperking1234 it looks like the test is flaky, #2644. |
|
plugin/storage/es/options.go
Outdated
flagSet.String( | ||
nsConfig.namespace+suffixIndexDateSeparator, | ||
defaultIndexDateSeparator, | ||
"Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20 \". Default: '"+defaultIndexDateSeparator+"'") |
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.
you do not need to explain the default value in the description, it will be printed automatically
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.
Sorry @sniperking1234 , this was my suggestion. Thanks, @yurishkuro, I should've picked up on that!
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.
@albertteoh It doesn't matter. I've commit the code.
I restarted the jobs. |
Signed-off-by: Chen Zhengwei <[email protected]> Signed-off-by: chen zhengwei <[email protected]>
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.
@albertteoh any more feedback?
Nope, LGTM (besides needing a rebase), thanks @yurishkuro @sniperking1234. |
Which problem is this PR solving?
Jaeger can customize the es date format.
Short description of the changes
2006-01-02
, it won't affect the old version.none
, there is no separation in the time format. Like20201120
.I don't know if this change is appropriate,.If so, I will modify the spark dependency and operator projects.