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

ES Healthcheck v6 mapping compatibility #12714

Merged
merged 10 commits into from
Jul 10, 2017

Conversation

kobelb
Copy link
Contributor

@kobelb kobelb commented Jul 7, 2017

Resolves #12669

return createNewConfig();
}

// if the build number is still the template string (which it wil be in development)
// then we need to set it to the max interger. Otherwise we will set it to the build num
body._source.buildNum = config.get('pkg.buildNum');
configSavedObject.attributes.buildNum = config.get('pkg.buildNum');
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use configSavedObject.get('buildNum') here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not seeing any get/set methods on the configSavedObject.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point - that is on the client-side. Sometime in the future I should move the SavedObject to common and use for both client and server-side.

@@ -6,8 +6,8 @@ async function getStatsForType(savedObjectsClient, type) {
return { total };
}

export async function getStats(kibanaIndex, callAdminCluster) {
const savedObjectsClient = new SavedObjectsClient(kibanaIndex, callAdminCluster);
export async function getStats(kibanaIndex, mappings, callAdminCluster) {
Copy link
Contributor

@tylersmalley tylersmalley Jul 7, 2017

Choose a reason for hiding this comment

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

Would be it easier to simply pass the savedObjectsClient here instead of all it's dependencies?

const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('admin');
const callAdminCluster = (...args) => callWithRequest(req, ...args);
const savedObjectsClient = new SavedObjectsClient(config.get('kibana.index'), callAdminCluster);
const savedObjectsClient = req.getSavedObjectsClient();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


export default function (server, { mappings }) {
export default async function (server, { mappings }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since server is just used to create the savedObjectsClient, how about updating these to simply accept the savedObjectsClient and we create it once in the health check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

upgrade is using the server for server.log as well as server.config(), so I can't remove passing the server to these functions; however, I am now passing the savedObjectsClient to the upgrade function so it's only being constructed once.

if (sortField) {
const value = {
order: sortOrder,
unmapped_type: get(mappings, `${type}.properties.${sortField}.type`)
Copy link
Contributor

Choose a reason for hiding this comment

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

For v6 mappings, this path would be doc.properties.${type}.properties.${sortField}.type

Could look something like this:

    const v5MappingType = get(mappings, `${type}.properties.${sortField}.type`);
    const v6MappingType = get(mappings, `doc.properties.${type}.properties.${sortField}.type`);
    const mappingType = v5MappingType || v6MappingType;

    const value = {
      order: sortOrder,
      unmapped_type: mappingType
    };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure these mapping paths will change for v6? As far as I can tell, these mappings are being specified by https://github.com/elastic/kibana/blob/master/src/core_plugins/kibana/mappings.json and I didn't see any changes to this for v6.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right - found this when working on getting Kibana to work against ES master. Updating the mapping definition is definitely what caused it.

@tylersmalley tylersmalley mentioned this pull request Jul 9, 2017
7 tasks
Copy link
Contributor

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for taking on this issue @kobelb!

@nreese nreese self-requested a review July 10, 2017 14:26
if (sortField) {
const value = {
order: sortOrder,
unmapped_type: get(mappings, `${type}.properties.${sortField}.type`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance that sortField or type could have a . in the value? If so, then the second parameter of lodash get should be an array like [type, 'properties', sortField, 'type']

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 currently because of https://www.elastic.co/guide/en/elasticsearch/reference/2.4/dots-in-names.html . However, I do see the benefit of not having to manually create this path string and prefer the approach that you've recommended as it's safe if Elasticsearch does decide to allow dots in field names.

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

LGTM

@epixa epixa added the blocker label Jul 10, 2017
@kobelb kobelb merged commit 3db8e3a into elastic:master Jul 10, 2017
@kobelb kobelb deleted the healthcheck-compatibility branch July 10, 2017 19:15
kobelb added a commit to kobelb/kibana that referenced this pull request Jul 10, 2017
* Beginning to update the healthcheck to use the SavedObjectsClient

Some tests are still broken
The sort method on the SavedObjectsClient isn't there yet

* Adding sort to create_find_query

* Fixing the tests

* Fixing upgrade_config tests

* Making the SavedObjectsClient be dependant on the mappings to enable
sorting

* Fixing disabled tests

* Fiixng test wording

* Passing the savedObjectsClient to the stats route handler

* Passing the savedObjectsClient to upgradeConfig from migratConfig

* Using array of keys with _.get instead of manual string concatenation
kobelb added a commit that referenced this pull request Jul 11, 2017
* Beginning to update the healthcheck to use the SavedObjectsClient

Some tests are still broken
The sort method on the SavedObjectsClient isn't there yet

* Adding sort to create_find_query

* Fixing the tests

* Fixing upgrade_config tests

* Making the SavedObjectsClient be dependant on the mappings to enable
sorting

* Fixing disabled tests

* Fiixng test wording

* Passing the savedObjectsClient to the stats route handler

* Passing the savedObjectsClient to upgradeConfig from migratConfig

* Using array of keys with _.get instead of manual string concatenation
@kobelb
Copy link
Contributor Author

kobelb commented Jul 11, 2017

Backported
5.x/5.6 - 683a29c

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.

5 participants