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

Check plugin version on startup #8283

Merged
merged 9 commits into from
Sep 19, 2016

Conversation

BigFunger
Copy link
Contributor

@BigFunger BigFunger commented Sep 14, 2016

Closes #6652

Adds a version check to the Kibana startup process.

  • Applies the same version checks that are applied during the plugin install process (including Adds concept of kibanaVersion to plugin installer #8222 changes)
  • If the version of the plugin (pack) fails this check, a warning message is displayed in the console and the plugin is disabled.

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 version value 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'.

@spalger spalger self-assigned this Sep 14, 2016
@BigFunger BigFunger force-pushed the check-plugin-version-on-startup branch from bd08c6c to 92f1b90 Compare September 14, 2016 19:31
@BigFunger BigFunger force-pushed the check-plugin-version-on-startup branch from 92f1b90 to 922c04a Compare September 15, 2016 14:38
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.

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/scan module? 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

@@ -21,7 +21,7 @@ target
/esvm
.htpasswd
.eslintcache
plugins
/plugins
Copy link
Contributor

@Bargs Bargs Sep 15, 2016

Choose a reason for hiding this comment

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

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

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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, I only meant this one line, sorry if it sounded like I was implying we change the whole file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love how I dragged my feet about your suggestion, and then didn't actually apply it. updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, I meant we could change this one line to /plugins/

@@ -0,0 +1,34 @@
import pluginInit from './plugin_init';
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks to be an unused import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right you are, Ken

import { cleanVersion, versionSatisfies } from '../../utils/version';
import _ from 'lodash';

module.exports = async function (kbnServer, server, config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ES6 export syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:salute:

const version = _.get(plugin, 'pkg.kibana.version', _.get(plugin, 'pkg.version'));
const name = _.get(plugin, 'pkg.name');

if (version === 'kibana') continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

cleanVersion(version),
cleanVersion(kbnServer.version))) {
warningMessages.add(`Plugin "${name}" expected Kibana version "${version}" and was disabled.`);
plugins.delete(plugin);
Copy link
Contributor

Choose a reason for hiding this comment

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

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);
    }

if (!versionSatisfies(
cleanVersion(version),
cleanVersion(kbnServer.version))) {
warningMessages.add(`Plugin "${name}" expected Kibana version "${version}" and was disabled.`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe include the actual Kibana version in the error message, just to users don't have to go digging for it?

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 thought about it, but was worried that it would be too wordy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Plugin "${name}" was disabled because it expected Kibana version "${version}", and found "${kbnServer.version}". ?

Copy link
Contributor

Choose a reason for hiding this comment

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

perfect

}

//because a plugin pack can contain more than one actual plugin, (for example x-pack)
//we make sure that the warning messages are unique
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really sure what this comment means. The code below doesn't seem to do any de-duping.

Copy link
Contributor Author

@BigFunger BigFunger Sep 15, 2016

Choose a reason for hiding this comment

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

I'm using a Set() object to collect the warning messages. I'll move the comment to the variable declaration.

@BigFunger
Copy link
Contributor Author

I tested this with xpack and ran into some possible issues (or maybe this behavior is intended?)

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?

Did you consider putting this logic in the ./plugins/scan module?

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?

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

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.

@BigFunger BigFunger force-pushed the check-plugin-version-on-startup branch from e88ecca to 2802410 Compare September 15, 2016 17:05
@Bargs
Copy link
Contributor

Bargs commented Sep 15, 2016

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 scan module, if @spalger thinks it is appropriate where it is currently, that's fine with me. I like the idea of keeping more of the plugin logic in one place, but I don't feel super strongly about it.

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

one question, but LGTM

}

for (let message of warningMessages) {
server.log(['warning'], message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just log this in the loop above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@tsullivan
Copy link
Member

when I changed the version number of an individual plugin (reporting) it didn't report any errors and did not disabled the plugin

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 x-plugins/kibana/plugins/*/package.json files

// 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'));
Copy link
Contributor

Choose a reason for hiding this comment

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

plugin objects have a version property that is already resolved correctly, we should use it 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.

get(plugin, 'pkg.kibana.version', get(plugin, 'version')) or should I initialize the kibana version in the plugin class as well?

@w33ble
Copy link
Contributor

w33ble commented Sep 15, 2016

But when I changed the version number of an individual plugin (reporting) it didn't report any errors and did not disabled the plugin.

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.

I guess at the moment the only reason a plugin would have a different version than its pack is due to a build error.

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.

If someone has a broken pack, it seems like we should warn them and disable the entire pack?

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.

return schema || defaultConfigSchema;
}

get enabled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@spalger
Copy link
Contributor

spalger commented Sep 15, 2016

idk how reviews work yet

@spalger
Copy link
Contributor

spalger commented Sep 16, 2016

LGTM!

@spalger
Copy link
Contributor

spalger commented Sep 16, 2016

@Bargs can you take another look?

@Bargs
Copy link
Contributor

Bargs commented Sep 16, 2016

LGTM

@BigFunger BigFunger merged commit 3b03ec3 into elastic:master Sep 19, 2016
elastic-jasper added a commit that referenced this pull request Sep 19, 2016
---------

**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
elastic-jasper added a commit that referenced this pull request Sep 19, 2016
---------

**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
BigFunger added a commit that referenced this pull request Sep 19, 2016
BigFunger added a commit that referenced this pull request Sep 19, 2016
@epixa epixa added the v5.0.0 label Oct 26, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
---------

**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
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
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.

Add plugin version check to Kibana startup
6 participants