Skip to content
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

Merged
merged 9 commits into from
Dec 3, 2020

Conversation

sniperking1234
Copy link
Contributor

@sniperking1234 sniperking1234 commented Nov 20, 2020

Which problem is this PR solving?

Short description of the changes

  • User can configure the date separator to change the date format.
  • Default date formate is 2006-01-02, it won't affect the old version.
  • If the separator is none, there is no separation in the time format. Like 20201120.

I don't know if this change is appropriate,.If so, I will modify the spark dependency and operator projects.

Signed-off-by: Chen Zhengwei <chenzhengwei@inspur.com>

Signed-off-by: chen zhengwei <chenzhengwei@inspur.com>
@codecov
Copy link

codecov bot commented Nov 20, 2020

Codecov Report

Merging #2637 (21a34c0) into master (ea127a1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
plugin/storage/es/dependencystore/storage.go 91.11% <100.00%> (+0.20%) ⬆️
plugin/storage/es/factory.go 100.00% <100.00%> (ø)
plugin/storage/es/options.go 100.00% <100.00%> (ø)
plugin/storage/es/spanstore/index_utils.go 100.00% <100.00%> (ø)
plugin/storage/es/spanstore/reader.go 100.00% <100.00%> (ø)
plugin/storage/es/spanstore/writer.go 100.00% <100.00%> (ø)
plugin/storage/integration/integration.go 77.34% <0.00%> (-0.56%) ⬇️
cmd/collector/app/server/zipkin.go 76.92% <0.00%> (+3.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea127a1...21a34c0. Read the comment docs.

Copy link
Contributor

@albertteoh albertteoh left a 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/options.go Show resolved Hide resolved
plugin/storage/es/options.go Show resolved Hide resolved
Comment on lines 57 to 65
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"
Copy link
Contributor

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"

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dateLayout := initDateLayout(tc.separator)
assert.Equal(t, dateLayout, tc.wantLayout)
Copy link
Contributor

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)

@@ -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,
"",
Copy link
Contributor

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 "-"?

@@ -33,14 +34,15 @@ def main():
prefix = os.getenv("INDEX_PREFIX", '')
if prefix != '':
prefix += '-'
separator = os.getenv("INDEX_DATE_SEPARATOR", '')
Copy link
Contributor

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 <chenzhengwei@inspur.com>

Signed-off-by: chen zhengwei <chenzhengwei@inspur.com>
@sniperking1234
Copy link
Contributor Author

@albertteoh I made some changes, please review it again. Thank you!

Copy link
Contributor

@albertteoh albertteoh left a 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.go Outdated Show resolved Hide resolved
plugin/storage/es/options_test.go Outdated Show resolved Hide resolved
@@ -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=-",
Copy link
Contributor

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.

flags []string
wantDateLayout string
}{
{"not defined", []string{}, "2006-01-02"},
Copy link
Contributor

@albertteoh albertteoh Nov 23, 2020

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 <chenzhengwei@inspur.com>

Signed-off-by: chen zhengwei <chenzhengwei@inspur.com>
{"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"},
Copy link
Contributor

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 :)

Copy link
Contributor Author

@sniperking1234 sniperking1234 Nov 23, 2020

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.

plugin/storage/es/options_test.go Outdated Show resolved Hide resolved
Signed-off-by: Chen Zhengwei <chenzhengwei@inspur.com>

Signed-off-by: chen zhengwei <chenzhengwei@inspur.com>
Copy link
Contributor

@albertteoh albertteoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @sniperking1234, thanks!

@sniperking1234
Copy link
Contributor Author

CI failed in TestReload unit test, but passed in my local test. How to fix it?

@yurishkuro
Copy link
Member

@sniperking1234 it looks like the test is flaky, #2644.

@sniperking1234
Copy link
Contributor Author

image
@yurishkuro Is there any way to rerun the test or fix this error? I think I'm stuck in these tests. 😂

flagSet.String(
nsConfig.namespace+suffixIndexDateSeparator,
defaultIndexDateSeparator,
"Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20 \". Default: '"+defaultIndexDateSeparator+"'")
Copy link
Member

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

Copy link
Contributor

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!

Copy link
Contributor Author

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.

@yurishkuro
Copy link
Member

I restarted the jobs.

Signed-off-by: Chen Zhengwei <chenzhengwei@inspur.com>

Signed-off-by: chen zhengwei <chenzhengwei@inspur.com>
Copy link
Member

@yurishkuro yurishkuro left a 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?

@albertteoh
Copy link
Contributor

albertteoh commented Dec 3, 2020

@albertteoh any more feedback?

Nope, LGTM (besides needing a rebase), thanks @yurishkuro @sniperking1234.

@yurishkuro yurishkuro changed the title Add elasticsearch storage date format config. Support configurable date separator for Elasticsearch index names Dec 3, 2020
@yurishkuro yurishkuro merged commit 6c2be45 into jaegertracing:master Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elasticsearch storage can not customize the date format
3 participants