You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bu...@apache.org on 2020/04/30 20:20:34 UTC
[geode-benchmarks] 01/01: generate haproxy.cfg
This is an automated email from the ASF dual-hosted git repository.
burcham pushed a commit to branch sni
in repository https://gitbox.apache.org/repos/asf/geode-benchmarks.git
commit 0dd3a29b68f2630ee1f424ddd9b9c9a3339a623e
Author: Bill Burcham <bb...@pivotal.io>
AuthorDate: Thu Apr 30 13:19:29 2020 -0700
generate haproxy.cfg
---
.../geode/benchmark/tasks/StartSniProxy.java | 94 +++++++++++++++++++
.../topology/ClientServerTopologyWithSNIProxy.java | 100 +++++++++++++++++++++
.../geode/benchmark/tasks/StartSniProxyTest.java | 35 ++++++++
.../scripts/aws/image/files/docker-compose.yml | 26 ++++++
infrastructure/scripts/aws/image/files/haproxy.cfg | 53 +++++++++++
5 files changed, 308 insertions(+)
diff --git a/geode-benchmarks/src/main/java/org/apache/geode/benchmark/tasks/StartSniProxy.java b/geode-benchmarks/src/main/java/org/apache/geode/benchmark/tasks/StartSniProxy.java
new file mode 100644
index 0000000..3d5f2f9
--- /dev/null
+++ b/geode-benchmarks/src/main/java/org/apache/geode/benchmark/tasks/StartSniProxy.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geode.benchmark.tasks;
+
+import java.net.InetAddress;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.geode.perftest.Task;
+import org.apache.geode.perftest.TestContext;
+
+/**
+ * Task to create the client cache
+ */
+public class StartSniProxy implements Task {
+ private int locatorPort;
+
+ public StartSniProxy(int locatorPort) {
+ this.locatorPort = locatorPort;
+ }
+
+ @Override
+ public void run(TestContext context) throws Exception {
+
+ final String stuff = generateHaProxyConfig(
+ hostNamesFor(context, "locator"),
+ hostNamesFor(context, "server"));
+
+ System.out.println(stuff);
+ }
+
+ private List<String> hostNamesFor(final TestContext context, final String role) {
+ return context.getHostsForRole(role).stream().map(InetAddress::getHostName)
+ .collect(Collectors.toList());
+ }
+
+ String generateHaProxyConfig(final Iterable<String> locators,
+ final Iterable<String> servers) {
+
+ final StringBuilder stuff = new StringBuilder("defaults\n"
+ + " timeout client 1000\n"
+ + " timeout connect 1000\n"
+ + " timeout server 1000\n"
+ + "frontend sniproxy\n"
+ + " bind *:15443\n"
+ + " mode tcp\n"
+ + " tcp-request inspect-delay 5s\n"
+ + " tcp-request content accept if { req_ssl_hello_type 1 }\n"
+ + " log stdout format raw local0 debug\n");
+
+ for (final String addy : locators) {
+ stuff.append(" use_backend locators-").append(addy)
+ .append(" if { req.ssl_sni -i ").append(addy
+ ).append(" }\n");
+ }
+
+ for (final String addy : servers) {
+ stuff.append(" use_backend servers-").append(addy)
+ .append(" if { req.ssl_sni -i ").append(addy
+ ).append(" }\n");
+ }
+
+ final String firstLocator = locators.iterator().next();
+ stuff.append(" default_backend locators-").append(firstLocator).append("\n");
+
+ for (final String addy : locators) {
+ stuff.append("backend locators-").append(addy).append("\n")
+ .append(" mode tcp\n").append(" server locator1 ").append(addy)
+ .append(":" + locatorPort + "\n");
+ }
+
+ for (final String addy : servers) {
+ stuff.append("backend servers-").append(addy).append("\n")
+ .append(" mode tcp\n").append(" server server1 ").append(addy)
+ .append(":40404\n");
+ }
+ return stuff.toString();
+ }
+}
diff --git a/geode-benchmarks/src/main/java/org/apache/geode/benchmark/topology/ClientServerTopologyWithSNIProxy.java b/geode-benchmarks/src/main/java/org/apache/geode/benchmark/topology/ClientServerTopologyWithSNIProxy.java
new file mode 100644
index 0000000..35bdc67
--- /dev/null
+++ b/geode-benchmarks/src/main/java/org/apache/geode/benchmark/topology/ClientServerTopologyWithSNIProxy.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.benchmark.topology;
+
+import static org.apache.geode.benchmark.topology.ClientServerTopologyWithSNIProxy.Roles.CLIENT;
+import static org.apache.geode.benchmark.topology.ClientServerTopologyWithSNIProxy.Roles.LOCATOR;
+import static org.apache.geode.benchmark.topology.ClientServerTopologyWithSNIProxy.Roles.SERVER;
+import static org.apache.geode.benchmark.topology.ClientServerTopologyWithSNIProxy.Roles.PROXY;
+
+import org.bouncycastle.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.geode.benchmark.parameters.GcLoggingParameters;
+import org.apache.geode.benchmark.parameters.GcParameters;
+import org.apache.geode.benchmark.parameters.HeapParameters;
+import org.apache.geode.benchmark.parameters.JvmParameters;
+import org.apache.geode.benchmark.parameters.ProfilerParameters;
+import org.apache.geode.benchmark.tasks.StartClient;
+import org.apache.geode.benchmark.tasks.StartLocator;
+import org.apache.geode.benchmark.tasks.StartServer;
+import org.apache.geode.benchmark.tasks.StartSniProxy;
+import org.apache.geode.perftest.TestConfig;
+
+public class ClientServerTopologyWithSNIProxy {
+ private static final Logger logger = LoggerFactory.getLogger(ClientServerTopologyWithSNIProxy.class);
+
+ /**
+ * All roles defined for the JVMs created for the benchmark
+ */
+ public static class Roles {
+ public static final String SERVER = "server";
+ public static final String CLIENT = "client";
+ public static final String LOCATOR = "locator";
+ public static final String PROXY = "proxy";
+ }
+
+ /**
+ * The port used to create the locator for the tests
+ */
+ public static final int LOCATOR_PORT = 10334;
+
+ static final int NUM_LOCATORS = 1;
+ static final int NUM_SERVERS = 2;
+ static final int NUM_CLIENTS = 1;
+ static final int NUM_PROXIES = 1;
+ private static final String WITH_SSL_ARGUMENT = "-DwithSsl=true";
+ private static final String WITH_SECURITY_MANAGER_ARGUMENT = "-DwithSecurityManager=true";
+
+ public static void configure(TestConfig testConfig) {
+ testConfig.role(LOCATOR, NUM_LOCATORS);
+ testConfig.role(SERVER, NUM_SERVERS);
+ testConfig.role(CLIENT, NUM_CLIENTS);
+ testConfig.role(PROXY, NUM_PROXIES);
+
+ JvmParameters.configure(testConfig);
+ HeapParameters.configure(testConfig);
+ GcLoggingParameters.configure(testConfig);
+ GcParameters.configure(testConfig);
+ ProfilerParameters.configure(testConfig);
+
+ addToTestConfig(testConfig, "withSsl", WITH_SSL_ARGUMENT);
+ addToTestConfig(testConfig, "withSecurityManager", WITH_SECURITY_MANAGER_ARGUMENT);
+
+ testConfig.before(new StartLocator(LOCATOR_PORT), LOCATOR);
+ testConfig.before(new StartServer(LOCATOR_PORT), SERVER);
+ testConfig.before(new StartClient(LOCATOR_PORT), CLIENT);
+ testConfig.before(new StartSniProxy(LOCATOR_PORT), PROXY);
+ }
+
+ private static void addToTestConfig(TestConfig testConfig, String systemPropertyKey,
+ String jvmArgument) {
+ if (Boolean.getBoolean(systemPropertyKey)) {
+ logger.info("Configuring JVMs to run with " + jvmArgument);
+ testConfig.jvmArgs(CLIENT, jvmArgument);
+ testConfig.jvmArgs(LOCATOR, jvmArgument);
+ testConfig.jvmArgs(SERVER, jvmArgument);
+ }
+ }
+
+ private static String[] appendIfNotEmpty(String[] a, String b) {
+ if (null == b || b.length() == 0) {
+ return a;
+ }
+
+ return Arrays.append(a, b);
+ }
+}
diff --git a/geode-benchmarks/src/test/java/org/apache/geode/benchmark/tasks/StartSniProxyTest.java b/geode-benchmarks/src/test/java/org/apache/geode/benchmark/tasks/StartSniProxyTest.java
new file mode 100644
index 0000000..189172b
--- /dev/null
+++ b/geode-benchmarks/src/test/java/org/apache/geode/benchmark/tasks/StartSniProxyTest.java
@@ -0,0 +1,35 @@
+package org.apache.geode.benchmark.tasks;
+
+import java.util.Collections;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class StartSniProxyTest {
+
+ @Test
+ public void generateConfigTest() {
+ final StartSniProxy starter = new StartSniProxy(42);
+ final String config =
+ starter.generateHaProxyConfig(Collections.singleton("one"), Collections.singleton("two"));
+ assertThat(config).isEqualTo("defaults\n"
+ + " timeout client 1000\n"
+ + " timeout connect 1000\n"
+ + " timeout server 1000\n"
+ + "frontend sniproxy\n"
+ + " bind *:15443\n"
+ + " mode tcp\n"
+ + " tcp-request inspect-delay 5s\n"
+ + " tcp-request content accept if { req_ssl_hello_type 1 }\n"
+ + " log stdout format raw local0 debug\n"
+ + " use_backend locators-one if { req.ssl_sni -i one }\n"
+ + " use_backend servers-two if { req.ssl_sni -i two }\n"
+ + " default_backend locators-one\n"
+ + "backend locators-one\n"
+ + " mode tcp\n"
+ + " server locator1 one:42\n"
+ + "backend servers-two\n"
+ + " mode tcp\n"
+ + " server server1 two:40404\n");
+ }
+}
\ No newline at end of file
diff --git a/infrastructure/scripts/aws/image/files/docker-compose.yml b/infrastructure/scripts/aws/image/files/docker-compose.yml
new file mode 100644
index 0000000..73c133a
--- /dev/null
+++ b/infrastructure/scripts/aws/image/files/docker-compose.yml
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+version: '3'
+services:
+ haproxy:
+ container_name: 'haproxy'
+ image: 'haproxy:2.1'
+ ports:
+ - "15443"
+ volumes:
+ - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
+
diff --git a/infrastructure/scripts/aws/image/files/haproxy.cfg b/infrastructure/scripts/aws/image/files/haproxy.cfg
new file mode 100644
index 0000000..11a25d5
--- /dev/null
+++ b/infrastructure/scripts/aws/image/files/haproxy.cfg
@@ -0,0 +1,53 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+defaults
+ timeout client 1000
+ timeout connect 1000
+ timeout server 1000
+
+frontend sniproxy
+ bind *:15443
+ mode tcp
+ tcp-request inspect-delay 5s
+ tcp-request content accept if { req_ssl_hello_type 1 }
+ use_backend locators-maeve if { req.ssl_sni -i locator-maeve }
+ use_backend servers-dolores if { req.ssl_sni -i server-dolores }
+ use_backend servers-clementine if { req.ssl_sni -i server-clementine }
+ default_backend locators-maeve
+ log stdout format raw local0 debug
+
+# ip-172-31-39-152 locator
+# ip-172-31-45-107 server
+# ip-172-31-39-104 server
+# ip-172-31-44-235 client
+# ip-172-31-32-137 proxy
+
+backend locators-maeve
+ mode tcp
+ # TODO: make the host name dynamic
+ server locator1 ip-172-31-39-152:10334
+
+backend servers-dolores
+ mode tcp
+ # TODO: make the host name dynamic
+ server server1 ip-172-31-45-107:40404
+
+backend servers-clementine
+ mode tcp
+ # TODO: make the host name dynamic
+ server server1 ip-172-31-39-104:40404