Skip to content

Commit

Permalink
Gatling performance tests - round-robin host property and documentati…
Browse files Browse the repository at this point in the history
…on for recent changes. (#3320)

Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable authored Sep 15, 2023
1 parent d55fb73 commit 8497acc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
22 changes: 22 additions & 0 deletions performance-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ To run TargetRpsSimulation. Source code available at `./performance-test/src/gat
./gradlew :performance-test:gatlingRun-org.opensearch.dataprepper.test.performance.TargetRpsSimulation
```

### Configurations

You can configure the test in order to target different endpoints with different configurations.
Supply the configurations as Java system variables on the command line.

For example, you can configure the port and use HTTPS with a custom certificate with the following:

```
./gradlew -Dport=7099 -Dprotocol=https -Dpath=/simple-sample-pipeline/logs -Djavax.net.ssl.keyStore=examples/demo/test_keystore.p12 :performance-test:gatlingRun-org.opensearch.dataprepper.test.performance.SingleRequestSimulation
```

**Available configuration options:**

* `host` - The host name or a comma-delimited list of host names. Defaults to `localhost`.
* `port` - The destination port. The default value is `2021`.
* `protocol` - The scheme to use in the URL. Can be `http` or `https`. Defaults to `http`.
* `path` - The path of the HTTP endpoint. This uses the default `http` path of `/log/ingest`.
* `authentication` - The authentication to use with the target. Currently supports `aws_sigv4`.
* `aws_region` - The AWS region to use in signing. Required with `aws_sigv4` authentication.
* `aws_service` - The AWS service name to use in signing. Required with `aws_sigv4` authentication.


### Verify Gatling scenarios compile
```shell
./gradlew :performance-test:compileGatlingJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import io.gatling.javaapi.http.HttpDsl;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public final class Protocol {
private Protocol() {
}
Expand All @@ -17,27 +21,37 @@ private Protocol() {

private static final String HTTP_PROTOCOL = System.getProperty("protocol", HTTP);

public static final String LOCALHOST = "localhost";
private static final String HOST = System.getProperty("host", LOCALHOST);
private static final String LOCALHOST = "localhost";

private static final Integer DEFAULT_PORT = 2021;
private static final Integer PORT = Integer.getInteger("port", DEFAULT_PORT);

private static final Integer defaultPort = 2021;
private static final Integer port = Integer.getInteger("port", defaultPort);
private static List<String> loadHosts() {
String host = System.getProperty("host", LOCALHOST);

return Arrays.asList(host.split(","));
}

private static String asUrl(final String protocol, final String host, final Integer port) {
return protocol + "://" + host + ":" + port;
}
private static List<String> asUrls(final String protocol, final List<String> host, final Integer port) {
return host.stream()
.map(h -> asUrl(protocol, h, port))
.collect(Collectors.toList());
}

public static HttpProtocolBuilder httpProtocol() {
return httpProtocol(HTTP_PROTOCOL, HOST, port);
return httpProtocol(HTTP_PROTOCOL, loadHosts(), PORT);
}

public static HttpProtocolBuilder httpsProtocol(final Integer port) {
return httpProtocol(HTTPS, HOST, port);
return httpProtocol(HTTPS, loadHosts(), port);
}

private static HttpProtocolBuilder httpProtocol(final String protocol, final String host, final Integer port) {
private static HttpProtocolBuilder httpProtocol(final String protocol, final List<String> hosts, final Integer port) {
return HttpDsl.http
.baseUrl(asUrl(protocol, host, port))
.baseUrls(asUrls(protocol, hosts, port))
.sign(SignerProvider.getSigner())
.acceptHeader("application/json")
.header("Content-Type", "application/json");
Expand Down

0 comments on commit 8497acc

Please sign in to comment.