-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Changes from all commits
05df648
394b5be
bc6fb7f
be63028
282f0e8
30072f0
e6d7bf5
c491195
321999a
7867686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { get } from 'lodash'; | ||
import upgrade from './upgrade_config'; | ||
import { SavedObjectsClient } from '../../../server/saved_objects'; | ||
|
||
export default function (server, { mappings }) { | ||
export default async function (server, { mappings }) { | ||
const config = server.config(); | ||
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin'); | ||
const options = { | ||
index: config.get('kibana.index'), | ||
|
||
const savedObjectsClient = new SavedObjectsClient(config.get('kibana.index'), mappings, callWithInternalUser); | ||
const { saved_objects: configSavedObjects } = await savedObjectsClient.find({ | ||
type: 'config', | ||
body: { | ||
size: 1000, | ||
sort: [ | ||
{ | ||
buildNum: { | ||
order: 'desc', | ||
unmapped_type: get(mappings, 'config.properties.buildNum.type') || 'keyword' | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
page: 1, | ||
perPage: 1000, | ||
sortField: 'buildNum', | ||
sortOrder: 'desc' | ||
}); | ||
|
||
return callWithInternalUser('search', options).then(upgrade(server)); | ||
return await upgrade(server, savedObjectsClient)(configSavedObjects); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,26 @@ import Promise from 'bluebird'; | |
import isUpgradeable from './is_upgradeable'; | ||
import _ from 'lodash'; | ||
|
||
export default function (server) { | ||
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin'); | ||
export default function (server, savedObjectsClient) { | ||
const config = server.config(); | ||
|
||
function createNewConfig() { | ||
return callWithInternalUser('create', { | ||
index: config.get('kibana.index'), | ||
type: 'config', | ||
body: { buildNum: config.get('pkg.buildNum') }, | ||
return savedObjectsClient.create('config', { | ||
buildNum: config.get('pkg.buildNum') | ||
}, { | ||
id: config.get('pkg.version') | ||
}); | ||
} | ||
|
||
return function (response) { | ||
return function (configSavedObjects) { | ||
// Check to see if there are any doc. If not then we set the build number and id | ||
if (response.hits.hits.length === 0) { | ||
if (configSavedObjects.length === 0) { | ||
return createNewConfig(); | ||
} | ||
|
||
// if we already have a the current version in the index then we need to stop | ||
const devConfig = _.find(response.hits.hits, function currentVersion(hit) { | ||
return hit._id !== '@@version' && hit._id === config.get('pkg.version'); | ||
const devConfig = _.find(configSavedObjects, function currentVersion(configSavedObject) { | ||
return configSavedObject.id !== '@@version' && configSavedObject.id === config.get('pkg.version'); | ||
}); | ||
|
||
if (devConfig) { | ||
|
@@ -32,25 +30,22 @@ export default function (server) { | |
|
||
// Look for upgradeable configs. If none of them are upgradeable | ||
// then create a new one. | ||
const body = _.find(response.hits.hits, isUpgradeable.bind(null, server)); | ||
if (!body) { | ||
const configSavedObject = _.find(configSavedObjects, isUpgradeable.bind(null, server)); | ||
if (!configSavedObject) { | ||
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not seeing any There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
server.log(['plugin', 'elasticsearch'], { | ||
tmpl: 'Upgrade config from <%= prevVersion %> to <%= newVersion %>', | ||
prevVersion: body._id, | ||
prevVersion: configSavedObject.id, | ||
newVersion: config.get('pkg.version') | ||
}); | ||
|
||
return callWithInternalUser('create', { | ||
index: config.get('kibana.index'), | ||
type: 'config', | ||
body: body._source, | ||
return savedObjectsClient.create('config', configSavedObject.attributes, { | ||
id: config.get('pkg.version') | ||
}); | ||
}; | ||
|
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.
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?
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.
upgrade
is using the server forserver.log
as well asserver.config()
, so I can't remove passing theserver
to these functions; however, I am now passing thesavedObjectsClient
to theupgrade
function so it's only being constructed once.