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

2813 - Move all mapping related code to mappings package. #2822

Merged
merged 6 commits into from
Feb 26, 2021

Conversation

bhiravabhatla
Copy link
Contributor

@bhiravabhatla bhiravabhatla commented Feb 22, 2021

Signed-off-by: santosh [email protected]

Resolves #2813

Which problem is this PR solving?

  • Move all mapping related code to mappings package.
  • Implement Feedback on refactoring mappings code

Short description of the changes

  • Create a struct SpanServiceMappingsBuilder and move all functions like GetSpanServiceMappings, FixMapping, LoadMapping to take that struct as receiver instead of passing a dozen parameters to them.
  • Move all the mapping-related business into mappings package, instead of being in the factory
  • Rename ESPrefix to IndexPrefix to be more readable

@bhiravabhatla bhiravabhatla requested a review from a team as a code owner February 22, 2021 04:16
@bhiravabhatla
Copy link
Contributor Author

@albertteoh /@yurishkuro. Could not implement below points -

  • This will also allow to omit assigning the es.TemplateBuilder field (it should default to es.TextTemplateBuilder{} automatically), keeping the code cleaner yet still providing testability.
  • Use that struct directly to pass values to tmpl.Execute(), instead of declaring an inner struct.

As I needed to pass the template builder interface for mocking in tests.

@bhiravabhatla
Copy link
Contributor Author

Would look at failing integration tests.

@codecov
Copy link

codecov bot commented Feb 22, 2021

Codecov Report

Merging #2822 (3922dcc) into master (c01aa2b) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2822      +/-   ##
==========================================
+ Coverage   95.92%   95.95%   +0.03%     
==========================================
  Files         222      223       +1     
  Lines        9696     9695       -1     
==========================================
+ Hits         9301     9303       +2     
+ Misses        325      323       -2     
+ Partials       70       69       -1     
Impacted Files Coverage Δ
cmd/esmapping-generator/app/flags.go 100.00% <100.00%> (ø)
cmd/esmapping-generator/app/renderer/render.go 100.00% <100.00%> (ø)
plugin/storage/es/dependencystore/storage.go 91.11% <100.00%> (ø)
plugin/storage/es/factory.go 97.61% <100.00%> (-0.60%) ⬇️
plugin/storage/es/mappings/mapping.go 100.00% <100.00%> (ø)
plugin/storage/integration/integration.go 77.90% <0.00%> (+0.55%) ⬆️
cmd/query/app/server.go 97.08% <0.00%> (+1.45%) ⬆️

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 c01aa2b...3922dcc. Read the comment docs.

plugin/storage/es/mappings/mapping.go Outdated Show resolved Hide resolved
plugin/storage/es/mappings/mapping.go Outdated Show resolved Hide resolved
@bhiravabhatla
Copy link
Contributor Author

Wierd, integration tests passed locally on elasticsearch v7.3.0.

@bhiravabhatla
Copy link
Contributor Author

Wierd, integration tests passed locally on elasticsearch v7.3.0.

Ok, I am able reproduce locally as well. Not entirely sure whats causing this though. Will spend some time on this

@bhiravabhatla
Copy link
Contributor Author

I am seeing this in my elasticsearch logs during the test runs.

"stacktrace": ["org.elasticsearch.transport.RemoteTransportException: [ca859ca2c689][127.0.0.1:9300][indices:data/read/search[phase/query]]", "Caused by: java.lang.IllegalArgumentException: Fielddata is disabled on text fields by default. Set fielddata=true on [serviceName] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
@albertteoh / @yurishkuro - Any idea on this.

@albertteoh
Copy link
Contributor

albertteoh commented Feb 22, 2021

Fielddata is disabled on text fields by default. Set fielddata=true on [serviceName] ...

I saw this once when I had index mapping issues; I think it means your serviceName field was set to type text which is what ES sets for strings if there is no existing template (dynamic mapping). If it's type text, it means individual words in the string cannot be indexed, I think.

I would suggest querying ES on both your span and service mappings to confirm this is indeed the case (type is text instead of keyword):

GET jaeger-span-write/_mapping
GET jaeger-service-write/_mapping

And check your templates to ensure serviceName is present and correct (should set type to keyword) in both the mappings:

GET _template/jaeger-span
GET _template/jaeger-service

And from there, it's just a matter of pinning down the root cause from what's changed in this PR.

@bhiravabhatla
Copy link
Contributor Author

Fielddata is disabled on text fields by default. Set fielddata=true on [serviceName] ...

I saw this once when I had index mapping issues; I think it means your serviceName field was set to type text which is what ES sets for strings if there is no existing template (dynamic mapping). If it's type text, it means individual words in the string cannot be indexed, I think.

I would suggest querying ES on both your span and service mappings to confirm this is indeed the case (type is text instead of keyword):

GET jaeger-span-write/_mapping
GET jaeger-service-write/_mapping

And check your templates to ensure serviceName is present and correct (should set type to keyword) in both the mappings:

GET _template/jaeger-span
GET _template/jaeger-service

And from there, it's just a matter of pinning down the root cause from what's changed in this PR.

Thank you @albertteoh - that helped. Index template pattern was the issue, index prefix was getting suffixed with "-" twice. Added a suffix check to avoid it. Tests passed locally.

Comment on lines +164 to +168
args args
mockNewTextTemplateBuilder func() es.TemplateBuilder
Copy link
Member

Choose a reason for hiding this comment

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

I would just use MappingBuilder struct directly, there's no benefit in the indirections

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dint get this.

Copy link
Member

Choose a reason for hiding this comment

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

rather than defining a struct for tests and copying values into it, just use MappingBuilder struct directly when defining test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not part of this commit. Will work on it now.

want := ""
if tt.esVersion == 7 {
want, err = mb.fixMapping("/" + tt.mapping + "-7.json")
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could move this to after the else to remove duplication

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 dint get this - you want me to move require.NoError(t, err) after else?

plugin/storage/es/mappings/mapping_test.go Outdated Show resolved Hide resolved
plugin/storage/es/mappings/mapping_test.go Outdated Show resolved Hide resolved
plugin/storage/es/mappings/mapping.go Show resolved Hide resolved
plugin/storage/es/mappings/mapping.go Outdated Show resolved Hide resolved
plugin/storage/es/mappings/mapping_test.go Outdated Show resolved Hide resolved

//go:embed *.json
// MAPPINGS contains embeded index templates.
var MAPPINGS embed.FS
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be public?

Suggested change
var MAPPINGS embed.FS
var mappingsFS embed.FS

@yurishkuro yurishkuro merged commit e4cacd0 into jaegertracing:master Feb 26, 2021
albertteoh pushed a commit to albertteoh/jaeger that referenced this pull request Mar 5, 2021
…#2822)

* 2813 - Move all mapping related code to mappings package & implement @yurishkuro's feedback on refactoring

Signed-off-by: santosh <[email protected]>

* 2813 - Fix name of the index templates

Signed-off-by: santosh <[email protected]>

* 2813 - Rename ESPrefix to IndexPrefix for clarity & Implement @yurishkuro's feedback

Signed-off-by: santosh <[email protected]>

* 2813 - Fix fmt issue

Signed-off-by: santosh <[email protected]>

* 2813 - Fix issue with adding hyphen to index prefix

Signed-off-by: santosh <[email protected]>

* 2813 - Used golang embed package instead of esc to embed index templates & implement feedback on tests

Signed-off-by: santosh <[email protected]>
@jpkrohling jpkrohling added this to the Release 1.23.0 milestone Jun 4, 2021
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.

Refactor Elasticsearch mapping code to implement cleaner design
4 participants