Debugging test cluster provided by OpenSearchIntegTestCase

Hello everyone,
I’m trying to develop a custom plugin for opensearch.
I want to verify if the plugin works as intended, for this purpose my idea is to create some tests based on OpenSearchIntegTestCase.

If I see the file build.gradle provided by opensearch-plugin-template-java I can read the a comment

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'
    }
}

Adding the argument -Dtest.debug=true in the gradle test launcher I’m able to debug the test runner with remote debugger provided by eclipse IDE. Unfortunately this don’t allow me to debug the plugin it self that is running in the cluster.

I think that --debug-jvm argument is supposed to do the magic (as the provided comment say), but where I must set that argument? If I set it into the JVM Arguments the test doesn’t start at all.

If I start the project with gradlew run --debug-jvm the opensearch cluster starts correctly and respond on simple CURL request. Of course it’s not enough for a complete test because I need some fake data to create a complete test.

What am I missing in the configuration to debug the cluster?
Thanks for your help

Hi @jluca
The command: gradlew run --debug-jvm run the cluster and loads plugin also if you run this command from your plugin repository.

Can you please elaborate here little bit more like what kind of exact debugging you need?

Hi @Navneet
the idea is to create a complete debuggable test case. So I need to create an opensearch envirovment with some fake data, make a request to the endpoint provided by my custom plugin and see what happens on the plugin side.

This is an example of the test:

public void test_addData() throws IOException, ParseException {

        // bulk request for fake data
	final BulkRequest bulk = new BulkRequest();
	LocalDateTime time = LocalDate.of(2023, Month.JANUARY, 1).atStartOfDay();
	for (int i = 0; i < 100; i++) {
		final Map<String, Object> item = new HashMap<>();
		item.put("@timestamp", time.toInstant(ZoneOffset.UTC).toEpochMilli());
		item.put("i", i);
		final IndexRequest index = new IndexRequest("test");
		index.source(item);
		bulk.add(index);
		time.plusHours(1);
	}
	client().bulk(bulk).actionGet();
	
	// real request to my custom plugin
	final CustomPluginRequest request = new CustomPluginRequest();
	request.setIndex("test-*");
	
	final HttpEntity entity = EntityBuilder.create()
			.setText(JSONUtils.serialize(request))
			.setContentType(ContentType.APPLICATION_JSON)
			.build();
	
	final Request req = new Request("GET", "/_plugins/custom-plugin-endpoint");
	req.setEntity(entity);
    Response response = getRestClient().performRequest(req);
    String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);

    logger.info("response body: {}", body);
    assertThat(body, containsString("test-*"));
}

If I launch the following command:
./gradlew ':integTest' --tests "org.osplugin.custom.CustomPluginIT.test_addData" -Dtest.debug=true
the test run exposing the port 5005 for debugging but only for the code that I have previously pasted. The action of the endpoint works and respond correctly but is not debuggable. Maybe is on a different port?

Nothing change if I add the argument --debug-jvm on the previous command.

As I’ve said on the first message If I simply run the cluster with gradlew run --debug-jvm and make some request with postman the plugin is debuggable, but It’s not a complete test case because there are no data.

How I can debug both side of the test (the test it self and the plugin that is on the cluster)?

Thank you for your help

Hi @jluca , I think this will get you want you want:
./gradlew :integTest -Dcluster.debug=1
then you can run the debugger that will listen on 5005 and attach