Skip to content

Commit

Permalink
Removing "leftovers" from the plugin template.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
lukas-vlcek committed Jun 26, 2023
1 parent 398eac2 commit 0782a53
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 45 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/org/opensearch/plugin/prometheus/RenamePlugin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<? extends Plugin>> 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"));
}
}
14 changes: 0 additions & 14 deletions src/test/java/org/opensearch/plugin/prometheus/RenameTests.java

This file was deleted.

0 comments on commit 0782a53

Please sign in to comment.