Check plugin version on startup#8283
Conversation
bd08c6c to
92f1b90
Compare
92f1b90 to
922c04a
Compare
Bargs
left a comment
There was a problem hiding this comment.
I tested this with xpack and ran into some possible issues (or maybe this behavior is intended?). When I changed the version number in the main xpack package.json, I got the warning message as expected. But when I changed the version number of an individual plugin (reporting) it didn't report any errors and did not disabled the plugin.
A couple other general thoughts:
- Did you consider putting this logic in the
./plugins/scanmodule? It seems like that would be a natural place for this version check, so that invalid plugins never get added to the plugin list in the first place. - Beyond the scope of this PR, but I'm just curious if there's been talk of allowing ranges in a plugin's
kibana.version
.gitignore
Outdated
| .htpasswd | ||
| .eslintcache | ||
| plugins | ||
| /plugins |
There was a problem hiding this comment.
This change promoted me to look more into the .gitignore rules. I'm guessing this rule was mistakenly matching more than just the root level plugins directory? While we're tightening things down, should we make it /plugins/ so that it specifically matches a directory? http://stackoverflow.com/questions/24139478/when-to-use-leading-slash-in-gitignore
There was a problem hiding this comment.
I'm all for tightening up this file. I'm guessing we're ignoring more that we intend here. I don't think this PR is the right place to do it, and that it deserves it's own. I modified the plugin ignore setting because it directly affects this PR.
There was a problem hiding this comment.
Yup, I only meant this one line, sorry if it sounded like I was implying we change the whole file
There was a problem hiding this comment.
Love how I dragged my feet about your suggestion, and then didn't actually apply it. updated.
There was a problem hiding this comment.
To clarify, I meant we could change this one line to /plugins/
src/server/plugins/check_version.js
Outdated
| @@ -0,0 +1,34 @@ | |||
| import pluginInit from './plugin_init'; | |||
There was a problem hiding this comment.
This looks to be an unused import
There was a problem hiding this comment.
right you are, Ken
src/server/plugins/check_version.js
Outdated
| import { cleanVersion, versionSatisfies } from '../../utils/version'; | ||
| import _ from 'lodash'; | ||
|
|
||
| module.exports = async function (kbnServer, server, config) { |
src/server/plugins/check_version.js
Outdated
| const version = _.get(plugin, 'pkg.kibana.version', _.get(plugin, 'pkg.version')); | ||
| const name = _.get(plugin, 'pkg.name'); | ||
|
|
||
| if (version === 'kibana') continue; |
There was a problem hiding this comment.
Using continue can make loops really difficult to reason about. Why not include this bit of logic in versionSatisfies? Then any calling code won't have to worry about this special condition.
There was a problem hiding this comment.
Since both the plugin install process and this check use the version.js file, I don't want to move the check into versionSatisfies. I'll clean it up in check_version.js
src/server/plugins/check_version.js
Outdated
| cleanVersion(version), | ||
| cleanVersion(kbnServer.version))) { | ||
| warningMessages.add(`Plugin "${name}" expected Kibana version "${version}" and was disabled.`); | ||
| plugins.delete(plugin); |
There was a problem hiding this comment.
The indentation here is really hard for me to read. Would something like this be better?
if (!versionSatisfies(
cleanVersion(version),
cleanVersion(kbnServer.version))) {
warningMessages.add(`Plugin "${name}" expected Kibana version "${version}" and was disabled.`);
plugins.delete(plugin);
}
src/server/plugins/check_version.js
Outdated
| if (!versionSatisfies( | ||
| cleanVersion(version), | ||
| cleanVersion(kbnServer.version))) { | ||
| warningMessages.add(`Plugin "${name}" expected Kibana version "${version}" and was disabled.`); |
There was a problem hiding this comment.
Maybe include the actual Kibana version in the error message, just to users don't have to go digging for it?
There was a problem hiding this comment.
I thought about it, but was worried that it would be too wordy.
There was a problem hiding this comment.
Plugin "${name}" was disabled because it expected Kibana version "${version}", and found "${kbnServer.version}". ?
src/server/plugins/check_version.js
Outdated
| } | ||
|
|
||
| //because a plugin pack can contain more than one actual plugin, (for example x-pack) | ||
| //we make sure that the warning messages are unique |
There was a problem hiding this comment.
I'm not really sure what this comment means. The code below doesn't seem to do any de-duping.
There was a problem hiding this comment.
I'm using a Set() object to collect the warning messages. I'll move the comment to the variable declaration.
Correct. It only warns once. x-pack is installed as a collection of plugins. The root package.json file describes the version of the pack as a whole, and is therefor what I should be checking, IMO. @w33ble, @tsullivan can you chime in on this?
I did, and decided that putting it into it's own check after scanning all of the plugins was a cleaner way of doing it. @spalger, what do you think?
At the moment, it is intentionally a direct match. That is one of the reasons I have this in another module though, because it should make it easier to implement once we widen that version range. |
e88ecca to
2802410
Compare
|
Changes look great! I guess at the moment the only reason a plugin would have a different version than its pack is due to a build error. If someone has a broken pack, it seems like we should warn them and disable the entire pack? If @tsullivan and @w33ble are cool with it as is though, it's cool with me. Same goes for moving the logic into the |
| } | ||
|
|
||
| for (let message of warningMessages) { | ||
| server.log(['warning'], message); |
There was a problem hiding this comment.
Why not just log this in the loop above?
There was a problem hiding this comment.
for multi-plugin packs, I'm checking the version of the pack as a whole, but there will be one plugin object for each plugin in the pack. I only want to show one message for the overall pack.
src/server/plugins/check_version.js
Outdated
| if (!compatibleWithKibana(kbnServer, version)) { | ||
| const message = `Plugin "${name}" was disabled because it expected Kibana version "${version}", and found "${kbnServer.version}".`; | ||
| warningMessages.add(message); | ||
| plugins.delete(plugin); |
There was a problem hiding this comment.
Now that @Bargs has pointed it out, I took a deeper look and discovered that Plugin#readConfig() is doing a very different job that it should. Removing the config schema of the plugin from the config service is something that should also happen when a plugin is disabled.
I don't really think this is a use case we need to support. Only Elastic is responsible for generating the X-Pack builds, and the code only refers to the main package.json, and it only does that for generating the build artifact. To be honest, I'm not really sure why we even have the |
src/server/plugins/check_version.js
Outdated
| // the version of kibana down to the patch level. If these two versions need | ||
| // to diverge, they can specify a kibana.version to indicate the version of | ||
| // kibana the plugin is intended to work with. | ||
| const version = get(plugin, 'pkg.kibana.version', get(plugin, 'pkg.version')); |
There was a problem hiding this comment.
plugin objects have a version property that is already resolved correctly, we should use it here.
There was a problem hiding this comment.
get(plugin, 'pkg.kibana.version', get(plugin, 'version')) or should I initialize the kibana version in the plugin class as well?
IMO, that's how it should work. Correct me if I'm wrong, but I'm pretty sure the top-level "pack" version is the only version that's required. If there are other "plugins" bundled in the "pack", they aren't required to have a package.json file, so we shouldn't be checking them even if they exist.
Or the internals are developed differently and their versions aren't in line with the pack's. But that's really up to the pack author to keep straight then.
This I agree with, but only if you are defining "broken" as "the top level version doesn't pass the test." If that's the case, then yes, the whole pack should be disabled. |
src/server/plugins/plugin.js
Outdated
| return schema || defaultConfigSchema; | ||
| } | ||
|
|
||
| get enabled() { |
There was a problem hiding this comment.
Let's just use a function, getters for this type of stuff can be deceptive.
|
|
||
| throw new TypeError('unexpected plugin export ' + inspect(product)); | ||
| await this.add(plugin); | ||
| if (!plugin.enabled) this.delete(plugin); |
There was a problem hiding this comment.
It's really unclear why these two lines are necessary, I think it would be clearer if we added and removed the configuration from the config schema right here.
|
idk how reviews work yet |
|
LGTM! |
|
@Bargs can you take another look? |
|
LGTM |
--------- **Commit 1:** fixes plugin path in .gitignore * Original sha: f74eb9b * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:40:21Z **Commit 2:** Moves version from plugin installer to utils * Original sha: ae492ff * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:41:19Z **Commit 3:** Adds plugin version check to kibana startup * Original sha: 83d0821 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:41:40Z **Commit 4:** Changes plugin version to 'kibana' in text fixture * Original sha: 922c04a * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T19:07:09Z **Commit 5:** Merge branch 'master' into check-plugin-version-on-startup * Original sha: 5da33ad * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T14:45:01Z **Commit 6:** review changes to check_version * Original sha: 2802410 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T16:53:28Z **Commit 7:** reworked logic to remove config when deleting a plugin from plugin_collection * Original sha: 2f52be6 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T20:11:43Z **Commit 8:** Adds a kibanaVersion property to the Plugin class * Original sha: e920bca * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T21:04:41Z **Commit 9:** move enabled check into it's own mixin, and cleaned up how you disable a plugin * Original sha: 049c029 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-16T17:22:47Z
--------- **Commit 1:** fixes plugin path in .gitignore * Original sha: f74eb9b * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:40:21Z **Commit 2:** Moves version from plugin installer to utils * Original sha: ae492ff * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:41:19Z **Commit 3:** Adds plugin version check to kibana startup * Original sha: 83d0821 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:41:40Z **Commit 4:** Changes plugin version to 'kibana' in text fixture * Original sha: 922c04a * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T19:07:09Z **Commit 5:** Merge branch 'master' into check-plugin-version-on-startup * Original sha: 5da33ad * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T14:45:01Z **Commit 6:** review changes to check_version * Original sha: 2802410 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T16:53:28Z **Commit 7:** reworked logic to remove config when deleting a plugin from plugin_collection * Original sha: 2f52be6 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T20:11:43Z **Commit 8:** Adds a kibanaVersion property to the Plugin class * Original sha: e920bca * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T21:04:41Z **Commit 9:** move enabled check into it's own mixin, and cleaned up how you disable a plugin * Original sha: 049c029 * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-16T17:22:47Z
--------- **Commit 1:** fixes plugin path in .gitignore * Original sha: 8d8745a2d68838777929c5859dd20fbb640e9abd [formerly f74eb9b] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:40:21Z **Commit 2:** Moves version from plugin installer to utils * Original sha: 53906f1dadbfefc5e0f0235908611e1b6bee382e [formerly ae492ff] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:41:19Z **Commit 3:** Adds plugin version check to kibana startup * Original sha: b7cec7ca8a688d7b1eeb13aef6d49983ff2d6010 [formerly 83d0821] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T18:41:40Z **Commit 4:** Changes plugin version to 'kibana' in text fixture * Original sha: 898642602f305bf93b71b76d62dba68c200230eb [formerly 922c04a] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-14T19:07:09Z **Commit 5:** Merge branch 'master' into check-plugin-version-on-startup * Original sha: cbbfc82b5ced04c374ffbc88b06c12ba0a2ee557 [formerly 5da33ad] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T14:45:01Z **Commit 6:** review changes to check_version * Original sha: 6e57b59fae033d18c7a99ede8978f2b873e7d8f4 [formerly 2802410] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T16:53:28Z **Commit 7:** reworked logic to remove config when deleting a plugin from plugin_collection * Original sha: b1f1f6833ae58abad301cb3eb02918486d733d20 [formerly 2f52be6] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T20:11:43Z **Commit 8:** Adds a kibanaVersion property to the Plugin class * Original sha: 7da9b40fabddbf787e340f515ada2fd3d6d29408 [formerly e920bca] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-15T21:04:41Z **Commit 9:** move enabled check into it's own mixin, and cleaned up how you disable a plugin * Original sha: 2136468d85de1f1a40db1f2e18275a468f4ec4ae [formerly 049c029] * Authored by Jim Unger <bigfunger@gmail.com> on 2016-09-16T17:22:47Z Former-commit-id: 246b069
[backport] PR elastic#8283 to 5.x Former-commit-id: 97960b0
Closes #6652
Adds a version check to the Kibana startup process.
Added a disable function to the Plugin_Collection class that allows for the disabling (deletion) of plugins
Moves logic that checks configuration to see if a plugin is disabled into its own mixin
I also changed the
versionvalue of some test fixtures to 'kibana' instead of '0.0.0'. The version checker will ignore (and not disable) any plugins that have a version number of 'kibana'.