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

Allow extended plugins to be optional #16909

Merged
merged 18 commits into from
Jan 3, 2025

Conversation

cwperks
Copy link
Member

@cwperks cwperks commented Dec 24, 2024

Description

When a plugin extends another extensible plugin, OpenSearch requires the other plugin to be installed ahead of time.

This PR adds a new way to specify that extended plugins are optional. This PR warns the cluster administrator that the dependent plugin is missing on installation.

See below example for configuration:

opensearchplugin {
    name 'opensearch-plugin'
    description 'OpenSearch Plugin'
    classname 'org.opensearch.example.ExamplePlugin'
    extendedPlugins = ['opensearch-security;optional=true']
}

In most use-cases, a plugin will extend another plugin because it offers core functionality. i.e. Anomaly detections needs job-scheduler to run detectors. In other cases, a plugin may extend another but only for a particular feature of the plugin that not all users will use. In such cases, does the extended plugin need to be installed if a user will never use the functionality?

While this doesn't make sense in all use-cases, the Security plugin would like to offer a SPI for plugins to share resources. In order for the security plugin to offer a SPI, other plugins would need to declare that they extend the security plugin. The problem with this is that security is optional and plugins currently support clusters where the security plugin is installed or clusters where it is not installed. By allowing extendedPlugins to be optional, this will allow security to offer a SPI but not be required for installation.

A warning is presented to a cluster administrator when trying to install a plugin that extends another plugin without the extended plugin being installed.

✗ ./bin/opensearch-plugin install file:/Users/cwperx/Projects/opensearch/index-management/build/distributions/opensearch-index-management-3.0.0.0-SNAPSHOT.zip
-> Installing file:/Users/cwperx/Projects/opensearch/index-management/build/distributions/opensearch-index-management-3.0.0.0-SNAPSHOT.zip
-> Downloading file:/Users/cwperx/Projects/opensearch/index-management/build/distributions/opensearch-index-management-3.0.0.0-SNAPSHOT.zip
[=================================================] 100%
15:34:46.216 [main] WARN  org.opensearch.plugins.PluginsService - Missing plugin [opensearch-job-scheduler], dependency of [opensearch-index-management]
15:34:46.217 [main] WARN  org.opensearch.plugins.PluginsService - Some features of this plugin may not function without the dependencies being installed.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission createClassLoader
* java.lang.RuntimePermission getClassLoader
* java.net.NetPermission getProxySelector
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed opensearch-index-management with folder name opensearch-index-management

This PR is to enable the plugin resource sharing use-case. Additional discussion can be found on #16030

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@cwperks cwperks closed this Dec 24, 2024
Copy link
Contributor

❌ Gradle check result for 29ff5b0: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

❌ Gradle check result for 29ff5b0: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@cwperks
Copy link
Member Author

cwperks commented Jan 2, 2025

Re-opening this PR based on the conversation on #16030

Copy link
Contributor

github-actions bot commented Jan 2, 2025

❌ Gradle check result for 3ebe10e: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@cwperks cwperks marked this pull request as ready for review January 3, 2025 01:14
Copy link
Contributor

github-actions bot commented Jan 3, 2025

❌ Gradle check result for 7e75335: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jan 3, 2025

✅ Gradle check result for 7e75335: SUCCESS

@cwperks
Copy link
Member Author

cwperks commented Jan 3, 2025

Hit a new problem and not sure how to move forward...

Usually its the plugin being extended that will supply the SPI jar on the classpath and that would be the single instance of the jar in the node.

When trying to make extended plugins optional, I can't rely on the extended plugin being installed and instead the extending plugin would need to provide the jar. If you have both the extended and the extending plugins providing the jar then it leads to jar hell.

./bin/opensearch-plugin install file:/Users/cwperx/Projects/opensearch/job-scheduler/build/distributions/opensearch-job-scheduler-3.0.0.0-SNAPSHOT.zip
-> Installing file:/Users/cwperx/Projects/opensearch/job-scheduler/build/distributions/opensearch-job-scheduler-3.0.0.0-SNAPSHOT.zip
-> Downloading file:/Users/cwperx/Projects/opensearch/job-scheduler/build/distributions/opensearch-job-scheduler-3.0.0.0-SNAPSHOT.zip
[=================================================] 100%
-> Failed installing file:/Users/cwperx/Projects/opensearch/job-scheduler/build/distributions/opensearch-job-scheduler-3.0.0.0-SNAPSHOT.zip
-> Rolling back file:/Users/cwperx/Projects/opensearch/job-scheduler/build/distributions/opensearch-job-scheduler-3.0.0.0-SNAPSHOT.zip
-> Rolled back file:/Users/cwperx/Projects/opensearch/job-scheduler/build/distributions/opensearch-job-scheduler-3.0.0.0-SNAPSHOT.zip
Exception in thread "main" java.lang.IllegalStateException: failed to load plugin opensearch-index-management due to jar hell
	at org.opensearch.plugins.PluginsService.checkBundleJarHell(PluginsService.java:702)
	at org.opensearch.plugins.InstallPluginCommand.jarHellCheck(InstallPluginCommand.java:839)
	at org.opensearch.plugins.InstallPluginCommand.loadPluginInfo(InstallPluginCommand.java:807)
	at org.opensearch.plugins.InstallPluginCommand.installPlugin(InstallPluginCommand.java:852)
	at org.opensearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:274)
	at org.opensearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:248)
	at org.opensearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:104)
	at org.opensearch.cli.Command.mainWithoutErrorHandling(Command.java:138)
	at org.opensearch.cli.MultiCommand.execute(MultiCommand.java:104)
	at org.opensearch.cli.Command.mainWithoutErrorHandling(Command.java:138)
	at org.opensearch.cli.Command.main(Command.java:101)
	at org.opensearch.plugins.PluginCli.main(PluginCli.java:66)
Caused by: java.lang.IllegalStateException: jar hell!
class: org.opensearch.jobscheduler.spi.schedule.ScheduleParser
jar1: /Users/cwperx/Projects/opensearch/OpenSearch/build/distribution/local/opensearch-3.0.0-SNAPSHOT/plugins/opensearch-index-management/opensearch-job-scheduler-spi-3.0.0.0-SNAPSHOT.jar
jar2: /Users/cwperx/Projects/opensearch/OpenSearch/build/distribution/local/opensearch-3.0.0-SNAPSHOT/plugins/.installing-17374475940414597224/opensearch-job-scheduler-spi-3.0.0.0-SNAPSHOT.jar

@reta
Copy link
Collaborator

reta commented Jan 3, 2025

When trying to make extended plugins optional, I can't rely on the extended plugin being installed and instead the extending plugin would need to provide the jar.

The extending plugin has to have the runtimeOnly dependency on the plugin being extended, it should never bundle it. Since this becomes optional functionality now, it has to be propagated to the code level - if the classpath does not contain the extending plugin, the initialization of the related classes should not be triggered.

Signed-off-by: Craig Perkins <[email protected]>
@reta reta added v3.0.0 Issues and PRs related to version 3.0.0 backport 2.x Backport to 2.x branch v2.19.0 Issues and PRs related to version 2.19.0 labels Jan 3, 2025
@reta
Copy link
Collaborator

reta commented Jan 3, 2025

Could you please create a documentation issue to document this change (and extended plugins in general) [1], we have done that for semantic versioning fe

[1] https://opensearch.org/docs/latest/install-and-configure/plugins/

Copy link
Contributor

github-actions bot commented Jan 3, 2025

❌ Gradle check result for 754bc6f: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@cwperks
Copy link
Member Author

cwperks commented Jan 3, 2025

Could you please create a documentation issue to document this change (and extended plugins in general) [1], we have done that for semantic versioning fe

[1] https://opensearch.org/docs/latest/install-and-configure/plugins/

Opened a doc issue: opensearch-project/documentation-website#9016

Signed-off-by: Craig Perkins <[email protected]>
Copy link
Contributor

github-actions bot commented Jan 3, 2025

✅ Gradle check result for ef6bbfb: SUCCESS

Copy link
Collaborator

@reta reta left a comment

Choose a reason for hiding this comment

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

@andrross any concerns / comments regarding this change? thank you!

@andrross andrross merged commit 845fbfa into opensearch-project:main Jan 3, 2025
38 of 42 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-16909-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 845fbfa10407f3264e6aab8812eff4ef0ad8be24
# Push it to GitHub
git push --set-upstream origin backport/backport-16909-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-16909-to-2.x.

@cwperks
Copy link
Member Author

cwperks commented Jan 3, 2025

I'll open up a manual backport

reta pushed a commit that referenced this pull request Jan 4, 2025
* Allow extended plugins to be optional (#16909)

* Make extended plugins optional

Signed-off-by: Craig Perkins <[email protected]>

* Make extended plugins optional

Signed-off-by: Craig Perkins <[email protected]>

* Load extensions for classpath plugins

Signed-off-by: Craig Perkins <[email protected]>

* Ensure only single instance for each classpath extension

Signed-off-by: Craig Perkins <[email protected]>

* Add test for classpath plugin extended plugin loading

Signed-off-by: Craig Perkins <[email protected]>

* Modify test to allow optional extended plugin

Signed-off-by: Craig Perkins <[email protected]>

* Only optional extended plugins

Signed-off-by: Craig Perkins <[email protected]>

* Add additional warning message

Signed-off-by: Craig Perkins <[email protected]>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <[email protected]>

* Add tag to make extended plugin optional

Signed-off-by: Craig Perkins <[email protected]>

* Only send plugin names when serializing PluginInfo

Signed-off-by: Craig Perkins <[email protected]>

* Keep track of optional extended plugins in separate set

Signed-off-by: Craig Perkins <[email protected]>

* Include in ser/de of PluginInfo

Signed-off-by: Craig Perkins <[email protected]>

* Change to 3_0_0

Signed-off-by: Craig Perkins <[email protected]>

---------

Signed-off-by: Craig Perkins <[email protected]>
(cherry picked from commit 845fbfa)

* Fix cherry-pick

Signed-off-by: Craig Perkins <[email protected]>

---------

Signed-off-by: Craig Perkins <[email protected]>
bugmakerrrrrr pushed a commit to bugmakerrrrrr/OpenSearch that referenced this pull request Jan 8, 2025
* Make extended plugins optional

Signed-off-by: Craig Perkins <[email protected]>

* Make extended plugins optional

Signed-off-by: Craig Perkins <[email protected]>

* Load extensions for classpath plugins

Signed-off-by: Craig Perkins <[email protected]>

* Ensure only single instance for each classpath extension

Signed-off-by: Craig Perkins <[email protected]>

* Add test for classpath plugin extended plugin loading

Signed-off-by: Craig Perkins <[email protected]>

* Modify test to allow optional extended plugin

Signed-off-by: Craig Perkins <[email protected]>

* Only optional extended plugins

Signed-off-by: Craig Perkins <[email protected]>

* Add additional warning message

Signed-off-by: Craig Perkins <[email protected]>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <[email protected]>

* Add tag to make extended plugin optional

Signed-off-by: Craig Perkins <[email protected]>

* Only send plugin names when serializing PluginInfo

Signed-off-by: Craig Perkins <[email protected]>

* Keep track of optional extended plugins in separate set

Signed-off-by: Craig Perkins <[email protected]>

* Include in ser/de of PluginInfo

Signed-off-by: Craig Perkins <[email protected]>

* Change to 3_0_0

Signed-off-by: Craig Perkins <[email protected]>

---------

Signed-off-by: Craig Perkins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch backport-failed v2.19.0 Issues and PRs related to version 2.19.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants