From 0782a53c11a9ebdf98004af17466dc7ea14a6e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Vl=C4=8Dek?= Date: Mon, 26 Jun 2023 17:20:36 +0200 Subject: [PATCH] Removing "leftovers" from the plugin template. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There were some `Rename*` files/classes, this commit is removing them. However, this step was not straightforward. TL;DR I had the keep the integration test in `test` folder and disabled the testingConvention task. I also had to change test testPluginInstalled a bit because the name of the plugin does no seem to be consistent and in some cases it equals to a class name (upstream ticket will be opened). Closes #190 Signed-off-by: Lukáš Vlček --- README.md | 8 ++-- build.gradle | 2 +- .../plugin/prometheus/RenamePlugin.java | 17 ------- .../plugin/prometheus/PrometheusPluginIT.java | 44 ++++++++++++++----- .../plugin/prometheus/RenameTests.java | 14 ------ 5 files changed, 40 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/org/opensearch/plugin/prometheus/RenamePlugin.java delete mode 100644 src/test/java/org/opensearch/plugin/prometheus/RenameTests.java diff --git a/README.md b/README.md index f1486dd..53e67fe 100644 --- a/README.md +++ b/README.md @@ -239,13 +239,15 @@ If you have doubts about the system requirements, please check the [CI.yml](.git ## Testing -Project contains [integration tests](src/yamlRestTest/resources/rest-api-spec) implemented using +Project contains: +- [integration tests](src/yamlRestTest/resources/rest-api-spec) implemented using [rest layer](https://github.com/opensearch-project/OpenSearch/blob/main/TESTING.md#testing-the-rest-layer) -framework. +framework +- [internal cluster tests](src/test) Complete test suite is run using: ``` -./gradlew clean assemble check +./gradlew clean check ``` To run individual integration rest test file use: diff --git a/build.gradle b/build.gradle index 481cca0..7c214f3 100644 --- a/build.gradle +++ b/build.gradle @@ -122,7 +122,7 @@ task integTest(type: RestIntegTestTask) { tasks.named("check").configure { dependsOn(integTest) } // Temporary disable task :testingConventions -//testingConventions.enabled = false +testingConventions.enabled = false testClusters.all { numberOfNodes = 2 diff --git a/src/main/java/org/opensearch/plugin/prometheus/RenamePlugin.java b/src/main/java/org/opensearch/plugin/prometheus/RenamePlugin.java deleted file mode 100644 index c58b00e..0000000 --- a/src/main/java/org/opensearch/plugin/prometheus/RenamePlugin.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ -package org.opensearch.plugin.prometheus; - -import org.opensearch.plugins.Plugin; - -/** - * TODO[lukas-vlcek]: Remove this class. It is not needed, it is a relict from OpenSearch Plugin template. - */ -public class RenamePlugin extends Plugin { - // Implement the relevant Plugin Interfaces here -} diff --git a/src/test/java/org/opensearch/plugin/prometheus/PrometheusPluginIT.java b/src/test/java/org/opensearch/plugin/prometheus/PrometheusPluginIT.java index c1c2279..4e6fcec 100644 --- a/src/test/java/org/opensearch/plugin/prometheus/PrometheusPluginIT.java +++ b/src/test/java/org/opensearch/plugin/prometheus/PrometheusPluginIT.java @@ -17,32 +17,56 @@ package org.opensearch.plugin.prometheus; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; +import org.apache.http.Header; import org.apache.http.util.EntityUtils; +import org.opensearch.action.admin.cluster.node.info.NodeInfo; +import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse; +import org.opensearch.action.admin.cluster.node.info.PluginsAndModules; import org.opensearch.client.Request; import org.opensearch.client.Response; +import org.opensearch.client.RestClient; import org.opensearch.plugins.Plugin; import org.opensearch.test.OpenSearchIntegTestCase; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.Collection; -import java.util.Collections; - -import static org.hamcrest.Matchers.containsString; @ThreadLeakScope(ThreadLeakScope.Scope.NONE) -@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE) +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 2, numClientNodes = 0, supportsDedicatedMasters = false) public class PrometheusPluginIT extends OpenSearchIntegTestCase { @Override protected Collection> nodePlugins() { - return Collections.singletonList(RenamePlugin.class); + return Arrays.asList(PrometheusExporterPlugin.class); } - public void testPluginInstalled() throws IOException { - Response response = createRestClient().performRequest(new Request("GET", "/_cat/plugins")); - String body = EntityUtils.toString(response.getEntity()); + /** + * Plugin must be installed on every cluster node. + */ + public void testPluginInstalled() { + NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().all().get(); + assertEquals(0, response.failures().size()); + assertFalse(response.getNodes().isEmpty()); + for (NodeInfo ni : response.getNodes()) { + assertNotNull(ni.getInfo(PluginsAndModules.class)); + assertEquals( + 1, + ni.getInfo(PluginsAndModules.class).getPluginInfos().stream().filter( + pluginInfo -> pluginInfo.getClassname().endsWith("PrometheusExporterPlugin") + ).count() + ); + } + } - logger.info("response body: {}", body); - org.hamcrest.MatcherAssert.assertThat(body, containsString("prometheus-exporter")); + public void testPrometheusClientResponse() throws IOException { + RestClient rc = getRestClient(); + logClusterState(); + Response response = rc.performRequest(new Request("GET", "_prometheus/metrics")); + assertEquals(200, response.getStatusLine().getStatusCode()); + assertEquals("text/plain; charset=UTF-8", response.getEntity().getContentType().getValue()); + String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + assertTrue(body.startsWith("# HELP")); } } diff --git a/src/test/java/org/opensearch/plugin/prometheus/RenameTests.java b/src/test/java/org/opensearch/plugin/prometheus/RenameTests.java deleted file mode 100644 index 4619cd4..0000000 --- a/src/test/java/org/opensearch/plugin/prometheus/RenameTests.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ -package org.opensearch.plugin.prometheus; - -import org.opensearch.test.OpenSearchTestCase; - -public class RenameTests extends OpenSearchTestCase { - // Add unit tests for your plugin -} \ No newline at end of file