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

Disable dynamic/Implement static mappings #10638

Merged
merged 16 commits into from
Apr 25, 2017

Conversation

jbudz
Copy link
Member

@jbudz jbudz commented Mar 1, 2017

Currently Kibana creates most mappings for the .kibana index on the client as needed. This code is split up between separate applications, and in some cases mappings aren't defined. This makes it difficult for external tools or kibana plugins to push .kibana data with correct mappings and can cause unexpected errors. In 6.0 we will also need to reindex and a complete definition will help with this.

When a new .kibana index is created, this disables dynamic mappings for everything except .kibana/config, disables dynamic type creation, and pushes all mappings.

Scenarios from this PR:

  1. Kibana index exists with partial mappings
    • No mappings are pushed, client side code pushes mappings if needed
    • If there aren't client side mappings defined, dynamic mapping is still enabled and is created if needed
    • Tools that push dashboards will continue to have wrong mappings
  2. Kibana index doesn't exist
    • Push full mappings, strict mappings
    • Tools that push dashboards will now have the correct mappings

Closes #4964

@jbudz jbudz requested review from tylersmalley and epixa March 1, 2017 17:22
@jbudz jbudz added the Team:Operations Team label for Operations Team label Mar 1, 2017
config: {
dynamic: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

we might be able to get away with enabled: false on this, thoughts? buildNum is used but otherwise we aren't searching

@epixa
Copy link
Contributor

epixa commented Mar 1, 2017

@Bargs Am I dreaming, or did you also take a swing at dynamic mappings in the past?

Copy link
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

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

Can we avoid having parallel mapping definitions in the codebase e.g.

const mapping = mappingSetup.expandShorthand({
?

@@ -1,16 +1,223 @@
export const mappings = {
'_default_': {
'dynamic': 'false'
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be strict shouldn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in de9d04a

'_default_': {
'dynamic': 'false'
},
dashboard: {
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like these mappings should be a part of each individual plugin's definition rather than crammed into the elasticsearch plugin, doesn't it? Feel free to ignore me if that's already the plan and this is just a stopgap.

Copy link
Member Author

@jbudz jbudz Mar 1, 2017

Choose a reason for hiding this comment

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

👍 working on this one now. The plan is to expose a registerMappings method on the elasticsearch plugin. I was concerned there could be timing issues when collecting these registrations, but it looks like it will work from the plugin's init method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 00cd9e0

@Bargs
Copy link
Contributor

Bargs commented Mar 1, 2017

@epixa nah, you might be thinking of the work I did on string -> text/keyword.

@jbudz
Copy link
Member Author

jbudz commented Mar 1, 2017

Agree on removing client side mappings but I left them in for 5.x reasons. Currently these will only be applied if the Kibana index doesn't exist. If it already exists but doesn't have the full set of mappings we want the client side mappings to happen. I'd like some idempotent put mapping operation to happen on startup but we'll need to get the functionality in for reindexing .kibana at the same time.

@jbudz jbudz force-pushed the feature/disable-dynamic-mappings branch 2 times, most recently from a872e9c to 02e24fc Compare March 1, 2017 23:54
@jbudz jbudz requested a review from spalger March 21, 2017 18:24
@spalger spalger changed the title Disable dynamic mappings Disable dynamic/Implement static mappings Mar 21, 2017
@epixa
Copy link
Contributor

epixa commented Mar 25, 2017

This has conflicts, FYI

@jbudz jbudz force-pushed the feature/disable-dynamic-mappings branch 2 times, most recently from 6cf51bd to a28b530 Compare March 27, 2017 20:47
@jbudz
Copy link
Member Author

jbudz commented Mar 28, 2017

jenkins, test this

1 similar comment
@jbudz
Copy link
Member Author

jbudz commented Mar 28, 2017

jenkins, test this

@epixa epixa added the blocker label Mar 28, 2017
};

export function assignMappings(mappings) {
Object.assign(defaultMappings, mappings);
Copy link
Contributor

@tylersmalley tylersmalley Mar 30, 2017

Choose a reason for hiding this comment

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

Are we concerned with, or should we provide protections against, someone overwriting our properties stored in the mappings?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 7f333ed

@spalger
Copy link
Contributor

spalger commented Mar 31, 2017

This needs to make sure that each mapping exists even before creating a .kibana index. If a user upgrades to this implementation after starting kibana but before saving a dashboard, or installs a new plugin which adds new mappings, the .kibana index won't have the correct mappings.

@jbudz jbudz force-pushed the feature/disable-dynamic-mappings branch from a28b530 to 7f333ed Compare March 31, 2017 15:16
@jbudz
Copy link
Member Author

jbudz commented Mar 31, 2017

@spalger my thoughts were to address that with the later upgrade process. As it stands now, I left all of the client side code to create mappings if the type doesn't exist. Eventually the checks won't be needed with the upgrade process in place, so instead of transitioning the client side checks to the server I opted for not doing anything.

A couple scenarios from this PR:

  1. Kibana index exists with partial mappings
    • No mappings are pushed, client side code pushes mappings if needed
    • If there aren't client side mappings defined, dynamic mapping is still enabled and is created if needed
    • Tools that push dashboards will continue to have wrong mappings
  2. Kibana index doesn't exist
    • Push full mappings, strict mappings
    • Tools that push dashboards will now have the correct mappings
  3. With the upgrade tool:
    • We remove client side mappings
    • If the mappings are wrong, we reindex with full mappings

The only case this covers is plugins or services pushing visualizations, dashboards post startup, which isn't needed for 5.4. It's fairly low impact, but may be safer to roll together with the upgrade tool. Any thoughts on edge cases I'm missing? Or waiting to include this with a more thorough upgrade process?

@tylersmalley
Copy link
Contributor

Jenkins, test it

@Bargs
Copy link
Contributor

Bargs commented Apr 24, 2017

LGTM

@jbudz jbudz force-pushed the feature/disable-dynamic-mappings branch from c46ee79 to 6adb460 Compare April 25, 2017 15:23
@jbudz jbudz merged commit ea7bfcc into elastic:master Apr 25, 2017
jbudz added a commit to jbudz/kibana that referenced this pull request Apr 25, 2017
* Disable dynamic mappings

* Disable automatic type creation

* Centralize .kibana mappings

* Use dynamic strict instead of false

* Register mappings per plugin

* Check for registered mapping conflicts

* Expose mappings on server scope instead of module

* Stub elasticsearch mappings class

* Add tests for KibanaMappings class

* [mappings tests] to.an -> to.be.an

* Return on mapping conflict and include plugin id if provided

* [uiExports] Add mappings uiExport type

* Use uiExports config in mappings tests

* Clean up ui_mappings test

* Revert plugin require ordering

* Pull uiExports mappings from kibana object isntead of kbnServer
@epixa
Copy link
Contributor

epixa commented Apr 25, 2017

@jbudz Don't forget to backport this

jbudz added a commit that referenced this pull request Apr 25, 2017
* Disable dynamic/Implement static mappings (#10638)

* Disable dynamic mappings

* Disable automatic type creation

* Centralize .kibana mappings

* Use dynamic strict instead of false

* Register mappings per plugin

* Check for registered mapping conflicts

* Expose mappings on server scope instead of module

* Stub elasticsearch mappings class

* Add tests for KibanaMappings class

* [mappings tests] to.an -> to.be.an

* Return on mapping conflict and include plugin id if provided

* [uiExports] Add mappings uiExport type

* Use uiExports config in mappings tests

* Clean up ui_mappings test

* Revert plugin require ordering

* Pull uiExports mappings from kibana object isntead of kbnServer

* [test] Update index mapping to look for keyword
@jbudz
Copy link
Member Author

jbudz commented Apr 25, 2017

5.x: d5dda02

@spalger
Copy link
Contributor

spalger commented Apr 25, 2017

🎉

}
}

export { MappingsCollection };
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future, we should not export raw objects like this. This is not valid JavaScript, it's just something that babel supports because it happens to behave similarly to CommonJS modules. Export the class itself instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants