You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by rd...@apache.org on 2022/10/04 01:09:54 UTC
[pulsar] branch master updated: [improve][pulsar-testclient] Add proxyServiceUrl and proxyProtocol as options for PerfTool CLI (#17862)
This is an automated email from the ASF dual-hosted git repository.
rdhabalia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new d1b7c6af37f [improve][pulsar-testclient] Add proxyServiceUrl and proxyProtocol as options for PerfTool CLI (#17862)
d1b7c6af37f is described below
commit d1b7c6af37fab50ac916e9e5b61c4345ad3643ad
Author: vineeth1995 <vi...@gmail.com>
AuthorDate: Mon Oct 3 18:09:46 2022 -0700
[improve][pulsar-testclient] Add proxyServiceUrl and proxyProtocol as options for PerfTool CLI (#17862)
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
* Add proxyServiceUrl and proxyProtocol as oprtions for PerfTool CLI
Co-authored-by: Vineeth <vi...@verizonmedia.com>
---
conf/client.conf | 4 +
.../apache/pulsar/testclient/PerfClientUtils.java | 3 +-
.../testclient/PerformanceBaseArguments.java | 27 +++++
.../pulsar/testclient/PerfClientUtilsTest.java | 5 +
.../testclient/PerformanceBaseArgumentsTest.java | 113 +++++++++++++++++++++
.../src/test/resources/perf_client1.conf | 2 +
6 files changed, 153 insertions(+), 1 deletion(-)
diff --git a/conf/client.conf b/conf/client.conf
index ea1d339a09c..8a485e5676c 100644
--- a/conf/client.conf
+++ b/conf/client.conf
@@ -88,7 +88,11 @@ tlsKeyStorePassword=
# When TLS authentication with KeyStore is used, available options can be SunJSSE, Conscrypt and so on.
webserviceTlsProvider=
+#Proxy-server URL to which to connect
+proxyServiceUrl=
+#Proxy protocol to select type of routing at proxy
+proxyProtocol=
# Pulsar Admin Custom Commands
#customCommandFactoriesDirectory=commandFactories
diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java
index 1ce5777fd32..a3552d31430 100644
--- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java
+++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java
@@ -75,7 +75,8 @@ public class PerfClientUtils {
.enableBusyWait(arguments.enableBusyWait)
.listenerThreads(arguments.listenerThreads)
.tlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath)
- .maxLookupRequests(arguments.maxLookupRequest);
+ .maxLookupRequests(arguments.maxLookupRequest)
+ .proxyServiceUrl(arguments.proxyServiceURL, arguments.proxyProtocol);
if (isNotBlank(arguments.authPluginClassName)) {
clientBuilder.authentication(arguments.authPluginClassName, arguments.authParams);
diff --git a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java
index cff7e16e9ca..307af7cbb15 100644
--- a/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java
+++ b/pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java
@@ -19,10 +19,12 @@
package org.apache.pulsar.testclient;
import static org.apache.commons.lang3.StringUtils.isBlank;
+import static org.apache.pulsar.testclient.PerfClientUtils.exit;
import com.beust.jcommander.Parameter;
import java.io.FileInputStream;
import java.util.Properties;
import lombok.SneakyThrows;
+import org.apache.pulsar.client.api.ProxyProtocol;
public abstract class PerformanceBaseArguments {
@@ -85,6 +87,12 @@ public abstract class PerformanceBaseArguments {
+ "on each broker connection to prevent overloading a broker")
public int maxLookupRequest = 50000;
+ @Parameter(names = { "--proxy-url" }, description = "Proxy-server URL to which to connect.")
+ String proxyServiceURL = null;
+
+ @Parameter(names = { "--proxy-protocol" }, description = "Proxy protocol to select type of routing at proxy.")
+ ProxyProtocol proxyProtocol = null;
+
public abstract void fillArgumentsFromProperties(Properties prop);
@SneakyThrows
@@ -133,6 +141,25 @@ public abstract class PerformanceBaseArguments {
.getProperty("tlsEnableHostnameVerification", ""));
}
+
+ if (proxyServiceURL == null) {
+ proxyServiceURL = prop.getProperty("proxyServiceURL");
+ }
+
+ if (proxyProtocol == null) {
+ try {
+ String proxyProtocolString = prop.getProperty("proxyProtocol");
+ if (proxyProtocolString != null) {
+ proxyProtocol = ProxyProtocol.valueOf(prop.getProperty("proxyProtocol"));
+ }
+ } catch (IllegalArgumentException e) {
+ System.out.println("Incorrect proxyProtocol name");
+ e.printStackTrace();
+ exit(-1);
+ }
+
+ }
+
fillArgumentsFromProperties(prop);
}
diff --git a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java
index ea21112635a..e1f1e7d3581 100644
--- a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java
+++ b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerfClientUtilsTest.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import org.apache.pulsar.client.api.Authentication;
+import org.apache.pulsar.client.api.ProxyProtocol;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.impl.ClientBuilderImpl;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
@@ -71,6 +72,8 @@ public class PerfClientUtilsTest {
args.tlsTrustCertsFilePath = "path";
args.tlsAllowInsecureConnection = true;
args.maxLookupRequest = 100000;
+ args.proxyServiceURL = "pulsar+ssl://my-proxy-pulsar:4443";
+ args.proxyProtocol = ProxyProtocol.SNI;
final ClientBuilderImpl builder = (ClientBuilderImpl)PerfClientUtils.createClientBuilderFromArguments(args);
final ClientConfigurationData conf = builder.getClientConfigurationData();
@@ -88,6 +91,8 @@ public class PerfClientUtilsTest {
Assert.assertEquals(conf.getTlsTrustCertsFilePath(), "path");
Assert.assertTrue(conf.isTlsAllowInsecureConnection());
Assert.assertEquals(conf.getMaxLookupRequest(), 100000);
+ Assert.assertEquals(conf.getProxyServiceUrl(), "pulsar+ssl://my-proxy-pulsar:4443");
+ Assert.assertEquals(conf.getProxyProtocol(), ProxyProtocol.SNI);
}
}
\ No newline at end of file
diff --git a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java
index 0b244a5a4e1..3071f92f9cc 100644
--- a/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java
+++ b/pulsar-testclient/src/test/java/org/apache/pulsar/testclient/PerformanceBaseArgumentsTest.java
@@ -18,11 +18,19 @@
*/
package org.apache.pulsar.testclient;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
+
import org.testng.Assert;
import org.testng.annotations.Test;
+import static org.apache.pulsar.client.api.ProxyProtocol.SNI;
+import static org.testng.Assert.fail;
+
public class PerformanceBaseArgumentsTest {
@@ -47,6 +55,111 @@ public class PerformanceBaseArgumentsTest {
Assert.assertEquals(args.tlsTrustCertsFilePath, "./path");
Assert.assertTrue(args.tlsAllowInsecureConnection);
Assert.assertTrue(args.tlsHostnameVerificationEnable);
+ Assert.assertEquals(args.proxyServiceURL, "https://my-proxy-pulsar:4443/");
+ Assert.assertEquals(args.proxyProtocol, SNI);
+ }
+
+ @Test
+ public void testReadFromConfigFileWithoutProxyUrl() {
+
+ AtomicBoolean called = new AtomicBoolean();
+
+ final PerformanceBaseArguments args = new PerformanceBaseArguments() {
+ @Override
+ public void fillArgumentsFromProperties(Properties prop) {
+ called.set(true);
+ }
+ };
+
+ File tempConfigFile = new File("./src/test/resources/performance_client2.conf");
+ if (tempConfigFile.exists()) {
+ tempConfigFile.delete();
+ }
+ try {
+ Properties props = new Properties();
+
+ Map<String, String> configs = Map.of("brokerServiceUrl","https://my-pulsar:8443/",
+ "authPlugin","org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth",
+ "authParams", "myparams",
+ "tlsTrustCertsFilePath", "./path",
+ "tlsAllowInsecureConnection","true",
+ "tlsEnableHostnameVerification", "true"
+ );
+ props.putAll(configs);
+ FileOutputStream out = new FileOutputStream(tempConfigFile);
+ props.store(out, "properties file");
+ out.close();
+ args.confFile = "./src/test/resources/performance_client2.conf";
+
+ args.fillArgumentsFromProperties();
+ Assert.assertTrue(called.get());
+ Assert.assertEquals(args.serviceURL, "https://my-pulsar:8443/");
+ Assert.assertEquals(args.authPluginClassName,
+ "org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth");
+ Assert.assertEquals(args.authParams, "myparams");
+ Assert.assertEquals(args.tlsTrustCertsFilePath, "./path");
+ Assert.assertTrue(args.tlsAllowInsecureConnection);
+ Assert.assertTrue(args.tlsHostnameVerificationEnable);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Error while updating/reading config file");
+ } finally {
+ tempConfigFile.delete();
+ }
+ }
+
+ @Test
+ public void testReadFromConfigFileProxyProtocolException() {
+
+ AtomicBoolean calledVar1 = new AtomicBoolean();
+ AtomicBoolean calledVar2 = new AtomicBoolean();
+
+ final PerformanceBaseArguments args = new PerformanceBaseArguments() {
+ @Override
+ public void fillArgumentsFromProperties(Properties prop) {
+ calledVar1.set(true);
+ }
+ };
+ File tempConfigFile = new File("./src/test/resources/performance_client3.conf");
+ if (tempConfigFile.exists()) {
+ tempConfigFile.delete();
+ }
+ try {
+ Properties props = new Properties();
+
+ Map<String, String> configs = Map.of("brokerServiceUrl","https://my-pulsar:8443/",
+ "authPlugin","org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth",
+ "authParams", "myparams",
+ "tlsTrustCertsFilePath", "./path",
+ "tlsAllowInsecureConnection","true",
+ "tlsEnableHostnameVerification", "true",
+ "proxyServiceURL", "https://my-proxy-pulsar:4443/",
+ "proxyProtocol", "TEST"
+ );
+ props.putAll(configs);
+ FileOutputStream out = new FileOutputStream(tempConfigFile);
+ props.store(out, "properties file");
+ out.close();
+ args.confFile = "./src/test/resources/performance_client3.conf";
+ PerfClientUtils.setExitProcedure(code -> {
+ calledVar2.set(true);
+ Assert.assertNotNull(code);
+ if (code != -1) {
+ fail("Incorrect exit code");
+ }
+ });
+
+ args.confFile = "./src/test/resources/performance_client3.conf";
+ args.fillArgumentsFromProperties();
+ Assert.assertTrue(calledVar1.get());
+ Assert.assertTrue(calledVar2.get());
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("Error while updating/reading config file");
+ } finally {
+ tempConfigFile.delete();
+ }
}
}
\ No newline at end of file
diff --git a/pulsar-testclient/src/test/resources/perf_client1.conf b/pulsar-testclient/src/test/resources/perf_client1.conf
index 127960618bf..1e96c7b35c7 100644
--- a/pulsar-testclient/src/test/resources/perf_client1.conf
+++ b/pulsar-testclient/src/test/resources/perf_client1.conf
@@ -23,3 +23,5 @@ authParams=myparams
tlsTrustCertsFilePath=./path
tlsAllowInsecureConnection=true
tlsEnableHostnameVerification=true
+proxyServiceURL=https://my-proxy-pulsar:4443/
+proxyProtocol=SNI
\ No newline at end of file