summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client-cli
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-01-03 21:46:05 +0100
committerjonmv <venstad@gmail.com>2023-01-03 21:46:05 +0100
commitb7933275fab6d14da23cac136560c17c5bc16ffb (patch)
treeaf914385cf33d897e10a8d5bfb2f1179ff2af483 /vespa-feed-client-cli
parent77fa33edd5f5d85d0283dc16a212291447c1afad (diff)
Add --gzip-requests to compress request bodies in feed client
Diffstat (limited to 'vespa-feed-client-cli')
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java7
-rw-r--r--vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java5
-rw-r--r--vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java3
-rw-r--r--vespa-feed-client-cli/src/test/resources/help.txt2
4 files changed, 12 insertions, 5 deletions
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
index fd36749b109..f827c2b64ca 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java
@@ -58,6 +58,7 @@ class CliArguments {
private static final String STDIN_OPTION = "stdin";
private static final String DOOM_OPTION = "max-failure-seconds";
private static final String PROXY_OPTION = "proxy";
+ private static final String GZIP_REQUESTS_OPTION = "gzip-requests";
private final CommandLine arguments;
@@ -181,6 +182,8 @@ class CliArguments {
boolean speedTest() { return has(SPEED_TEST_OPTION); }
+ boolean gzipRequests() { return has(GZIP_REQUESTS_OPTION); }
+
OptionalInt testPayloadSize() throws CliArgumentsException { return intValue(TEST_PAYLOAD_SIZE_OPTION); }
Optional<URI> proxy() throws CliArgumentsException {
@@ -354,6 +357,10 @@ class CliArguments {
.desc("URI to proxy endpoint")
.hasArg()
.type(URL.class)
+ .build())
+ .addOption(Option.builder()
+ .longOpt(GZIP_REQUESTS_OPTION)
+ .desc("Compress request bodies with gzip")
.build());
}
diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
index 43a16c2abf0..6b5e41a6b36 100644
--- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
+++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.feed.client.impl;
-import ai.vespa.feed.client.DocumentId;
import ai.vespa.feed.client.FeedClient;
import ai.vespa.feed.client.FeedClientBuilder;
import ai.vespa.feed.client.FeedException;
@@ -10,7 +9,6 @@ import ai.vespa.feed.client.JsonFeeder.ResultCallback;
import ai.vespa.feed.client.OperationStats;
import ai.vespa.feed.client.Result;
import ai.vespa.feed.client.ResultException;
-import ai.vespa.feed.client.impl.CliArguments.CliArgumentsException;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -29,14 +27,12 @@ import java.time.Instant;
import java.util.Enumeration;
import java.util.Map;
import java.util.Random;
-import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.joining;
@@ -163,6 +159,7 @@ public class CliClient {
cliArgs.headers().forEach(builder::addRequestHeader);
builder.setDryrun(cliArgs.dryrunEnabled());
builder.setSpeedTest(cliArgs.speedTest());
+ builder.setGzipRequests(cliArgs.gzipRequests());
cliArgs.doomSeconds().ifPresent(doom -> builder.setCircuitBreaker(new GracePeriodCircuitBreaker(Duration.ofSeconds(10),
Duration.ofSeconds(doom))));
cliArgs.proxy().ifPresent(builder::setProxy);
diff --git a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java
index 073ea4a58db..dcfa96d5531 100644
--- a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java
+++ b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java
@@ -28,7 +28,7 @@ class CliArgumentsTest {
"--max-streams-per-connection=128", "--certificate=cert.pem", "--private-key=key.pem",
"--ca-certificates=ca-certs.pem", "--disable-ssl-hostname-verification",
"--header=\"My-Header: my-value\"", "--header", "Another-Header: another-value", "--benchmark",
- "--route=myroute", "--timeout=0.125", "--trace=9", "--verbose", "--silent",
+ "--route=myroute", "--timeout=0.125", "--trace=9", "--verbose", "--silent", "--gzip-requests",
"--show-errors", "--show-all", "--max-failure-seconds=30", "--proxy", "https://myproxy:1234"});
assertEquals(URI.create("https://vespa.ai:4443/"), args.endpoint());
assertEquals(Paths.get("feed.json"), args.inputFile().get());
@@ -52,6 +52,7 @@ class CliArgumentsTest {
assertTrue(args.showErrors());
assertTrue(args.showSuccesses());
assertFalse(args.showProgress());
+ assertTrue(args.gzipRequests());
assertEquals(URI.create("https://myproxy:1234"), args.proxy().orElse(null));
}
diff --git a/vespa-feed-client-cli/src/test/resources/help.txt b/vespa-feed-client-cli/src/test/resources/help.txt
index e41a78bc932..63e4adf0d7d 100644
--- a/vespa-feed-client-cli/src/test/resources/help.txt
+++ b/vespa-feed-client-cli/src/test/resources/help.txt
@@ -15,6 +15,8 @@ Vespa feed client
across the network
--endpoint <arg> URI to feed endpoint
--file <arg> Path to feed file in JSON format
+ --gzip-requests Compress request bodies with
+ gzip
--header <arg> HTTP header on the form 'Name:
value'
--help