From 7cab2da80a7b6d91f2bf7c74a5ee6b2bd361a47b Mon Sep 17 00:00:00 2001 From: Ajay Kumar Movva Date: Wed, 31 Jan 2024 14:36:47 +0530 Subject: [PATCH] Updated networkmodule and added logs to debug failures Signed-off-by: Ajay Kumar Movva --- .../common/network/NetworkModule.java | 7 ++++--- .../AdmissionControlTransportHandler.java | 2 ++ .../common/network/NetworkModuleTests.java | 19 +++++++++++++++++-- .../transport/RemoteClusterClientTests.java | 7 +++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/opensearch/common/network/NetworkModule.java b/server/src/main/java/org/opensearch/common/network/NetworkModule.java index 821d48fccf48c..290dd0157d506 100644 --- a/server/src/main/java/org/opensearch/common/network/NetworkModule.java +++ b/server/src/main/java/org/opensearch/common/network/NetworkModule.java @@ -153,9 +153,6 @@ public NetworkModule( List transportInterceptors ) { this.settings = settings; - if (transportInterceptors != null) { - transportInterceptors.forEach(this::registerTransportInterceptor); - } for (NetworkPlugin plugin : plugins) { Map> httpTransportFactory = plugin.getHttpTransports( settings, @@ -192,6 +189,10 @@ public NetworkModule( registerTransportInterceptor(interceptor); } } + // // Adding last because interceptors are triggered from last to first order from the list + // if (transportInterceptors != null) { + // transportInterceptors.forEach(this::registerTransportInterceptor); + // } } /** Adds a transport implementation that can be selected by setting {@link #TRANSPORT_TYPE_KEY}. */ diff --git a/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/transport/AdmissionControlTransportHandler.java b/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/transport/AdmissionControlTransportHandler.java index 79f88d4ad3478..690a90959ced2 100644 --- a/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/transport/AdmissionControlTransportHandler.java +++ b/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/transport/AdmissionControlTransportHandler.java @@ -54,8 +54,10 @@ public void messageReceived(T request, TransportChannel channel, Task task) thro if (!forceExecution) { try { this.admissionControlService.applyTransportAdmissionControl(this.action); + log.info("OpenSearch AC applied for action"); } catch (final OpenSearchRejectedExecutionException openSearchRejectedExecutionException) { log.warn(openSearchRejectedExecutionException.getMessage()); + log.info("OpenSearch Rejected exception"); channel.sendResponse(openSearchRejectedExecutionException); return; } diff --git a/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java b/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java index ab51cafb039c2..b9c1e422a7be0 100644 --- a/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java +++ b/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java @@ -474,13 +474,28 @@ public List getTransportInterceptors( try { transportInterceptor.interceptHandler("foo/bar/boom", null, true, null); } catch (Exception e) { - assertEquals(0, called.get()); + assertEquals(1, called.get()); assertEquals(1, called1.get()); } + + coreTransportInterceptors = new ArrayList<>(); + coreTransportInterceptors.add(interceptor); + module = newNetworkModule(settings, coreTransportInterceptors, new NetworkPlugin() { + @Override + public List getTransportInterceptors( + NamedWriteableRegistry namedWriteableRegistry, + ThreadContext threadContext + ) { + assertNotNull(threadContext); + return Collections.singletonList(interceptor1); + } + }); + + transportInterceptor = module.getTransportInterceptor(); try { transportInterceptor.interceptHandler("foo/baz/boom", null, false, null); } catch (Exception e) { - assertEquals(0, called.get()); + assertEquals(1, called.get()); assertEquals(2, called1.get()); } } diff --git a/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java b/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java index f3b7f9916d460..e7fe9ac5fe3d0 100644 --- a/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java +++ b/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java @@ -94,17 +94,24 @@ public void testConnectAndExecuteRequest() throws Exception { service.acceptIncomingRequests(); logger.info("now accepting incoming requests on local transport"); RemoteClusterService remoteClusterService = service.getRemoteClusterService(); + logger.info("remote cluster service is able to get"); assertBusy(() -> { assertTrue(remoteClusterService.isRemoteNodeConnected("test", remoteNode)); }, 10, TimeUnit.SECONDS); + logger.info("remote cluster service is remote node connected"); Client client = remoteClusterService.getRemoteClusterClient(threadPool, "test"); + logger.info("remote cluster client is able to create"); ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().execute().get(); + logger.info("able to get cluster state response"); assertNotNull(clusterStateResponse); assertEquals("foo_bar_cluster", clusterStateResponse.getState().getClusterName().value()); + logger.info("before triggering scroll"); // also test a failure, there is no handler for scroll registered ActionNotFoundTransportException ex = expectThrows( ActionNotFoundTransportException.class, () -> client.prepareSearchScroll("").get() ); + logger.info("after triggering scroll"); assertEquals("No handler for action [indices:data/read/scroll]", ex.getMessage()); + logger.info("Test execution successful"); } } }