Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created February 10, 2023 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukas-vlcek/26fd54fb7ba25debb5b5c5c8c390ad79 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/26fd54fb7ba25debb5b5c5c8c390ad79 to your computer and use it in GitHub Desktop.
Run testing OpenSearch cluster with a core plugin

The run task

OpenSearch has a built in gradle task run to spin up a testcluster.

This is a very useful feature for plugin authors expecially if they use the plugin template (which defines its own modification of run task). It gives author easy way how to spin up a new testcluster with their plugin deployed.

However, when it comes to "core" plugins (that is plugins in plugins folder) then the run task does not seem to be setup correctly to spin up a cluster with given core plugin in it. The cluster does not seem to spin up and it hangs.

There is relatively simple workaround how to make the run task to work correctly for "core" plugin but it requires manual modification of particular plugin's build.gradle file (please read below to see how to do it).

It might be useful to implement a proper support for core plugins (shall we open a request feature?).

Workaround for "core" plugin

Assume there is a flat-object plugin under the plugins folder.

cd plugins/flat-object
vi build.gradle

Add the following line at the beginning to the file (can be below the license):

import org.opensearch.gradle.test.RestIntegTestTask

Add the following part at the end of the file:

task integTest(type: RestIntegTestTask) {
  description = "Run tests against a cluster"
  testClassesDirs = sourceSets.test.output.classesDirs
  classpath = sourceSets.test.runtimeClasspath
}
tasks.named("check").configure { dependsOn(integTest) }

integTest {
  // The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable
  if (System.getProperty("test.debug") != null) {
    jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
  }
}

testClusters.integTest {
  testDistribution = "INTEG_TEST"

  // This installs our plugin into the testClusters
  plugin(project.tasks.bundlePlugin.archiveFile)
}

// Uncommend the following if you want to spin up testcluster with more than one node.
//testClusters.all {
//  numberOfNodes = 2
//}

run {
  useCluster testClusters.integTest
}

Make sure you stay in the plugin/flat-object folder.

Start the test cluster

The following command spins up a testing cluter and deploys the flat-object plugin into it:

../../gradlw clean run

You should see output like this:

> Configure project :qa:os
Cannot add task 'destructiveDistroTest.docker' as a task with that name already exists.
=======================================
OpenSearch Build Hamster says Hello!
  Gradle Version        : 7.6
  OS Info               : Mac OS X 13.1 (aarch64)
  JDK Version           : 17 (Eclipse Temurin JDK)
  JAVA_HOME             : /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
  Random Testing Seed   : 3FBB548EEA77DE04
  In FIPS 140 mode      : false
=======================================

> Task :plugins:flat-object:run
[2023-02-10T16:09:29.387825Z] [BUILD] Configuring custom cluster specific distro directory: /Users/lukas.vlcek/projects/OpenSearch-Mingshl-temp/plugins/flat-object/build/testclusters/integTest-0/distro/3.0.0-INTEG_TEST
[2023-02-10T16:09:29.412775Z] [BUILD] Copying additional config files from distro [/Users/lukas.vlcek/projects/OpenSearch-Mingshl-temp/plugins/flat-object/build/testclusters/integTest-0/distro/3.0.0-INTEG_TEST/config/jvm.options.d, /Users/lukas.vlcek/projects/OpenSearch-Mingshl-temp/plugins/flat-object/build/testclusters/integTest-0/distro/3.0.0-INTEG_TEST/config/opensearch.yml, /Users/lukas.vlcek/projects/OpenSearch-Mingshl-temp/plugins/flat-object/build/testclusters/integTest-0/distro/3.0.0-INTEG_TEST/config/log4j2.properties, /Users/lukas.vlcek/projects/OpenSearch-Mingshl-temp/plugins/flat-object/build/testclusters/integTest-0/distro/3.0.0-INTEG_TEST/config/jvm.options]
[2023-02-10T16:09:29.413631Z] [BUILD] installing 1 plugins in a single transaction
[2023-02-10T16:09:30.221885Z] [BUILD] installed plugins

...

[2023-02-10T17:09:31,929][WARN ][o.o.n.Node               ] [integTest-0] version [3.0.0-SNAPSHOT] is a pre-release version of OpenSearch and is not suitable for production
[2023-02-10T17:09:32,019][INFO ][o.o.p.PluginsService     ] [integTest-0] loaded module [transport-netty4]
[2023-02-10T17:09:32,020][INFO ][o.o.p.PluginsService     ] [integTest-0] loaded plugin [flat-object]

...

[2023-02-10T17:16:23,026][DEBUG][o.o.c.c.PublicationTransportHandler] [integTest-0] received full cluster state version [2] with size [285]
[2023-02-10T17:16:23,042][DEBUG][o.o.c.c.C.CoordinatorPublication] [integTest-0] publication ended successfully: Publication{term=1, version=2}
[2023-02-10T17:16:23,042][INFO ][o.o.g.GatewayService     ] [integTest-0] recovered [0] indices into cluster_state
[2023-02-10T17:16:23,544][DEBUG][o.o.c.c.ElectionSchedulerFactory] [integTest-0] scheduleNextElection{gracePeriod=500ms, thisAttempt=1, maxDelayMillis=200, delayMillis=607, ElectionScheduler{attempt=2, ElectionSchedulerFactory{initialTimeout=100ms, backoffTime=100ms, maxTimeout=10s}}} not starting election
<============-> 99% EXECUTING [12s]
> IDLE
> IDLE
> IDLE
> IDLE
> :plugins:flat-object:run
> IDLE
> IDLE
> IDLE
> IDLE
> IDLE

And it stays like that until you hit Command-C which terminates the cluster.

Before you terminate the cluster you can use different terminal window to verify deployed plugins:

curl localhost:9200/_cat/plugins\?v

name        component   version
integTest-0 flat-object 3.0.0-SNAPSHOT

Or you can point your local browser to http://localhost:9200/_cat/plugins?v.

Cleanup Tip

When depevoping OpenSearch plugins and running testclusters it can sometimes happen that there is some "forgotten" background process that slashes with your new cluster. It is better to make sure there are no such processing running.

I use jps command to identify such processes:

jps -l

jps -l
4657 jdk.jcmd/sun.tools.jps.Jps
3060 org.gradle.launcher.daemon.bootstrap.GradleDaemon
1797 
2168 org.jetbrains.idea.maven.server.RemoteMavenServer36
2169 org.jetbrains.idea.maven.server.RemoteMavenServer36
2170 org.jetbrains.idea.maven.server.RemoteMavenServer36
2350 org.gradle.launcher.daemon.bootstrap.GradleDaemon

Especially the GradleDaemon processes can be problematic. You can kill them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment