Skip to content

[DE-757] content encoding #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/resilience.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ on:

jobs:
test:
if: '! github.event.pull_request.draft'
timeout-minutes: 20
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- docker-img: docker.io/arangodb/enterprise:3.11.7
compression: false
- docker-img: docker.io/arangodb/arangodb-preview:devel-nightly
compression: true

env:
TOXIPROXY_VERSION: v2.7.0

Expand All @@ -37,6 +47,8 @@ jobs:
run: ./docker/start_db.sh
env:
STARTER_MODE: cluster
DOCKER_IMAGE: ${{matrix.docker-img}}
COMPRESSION: ${{matrix.compression}}
- name: Info
run: mvn -version
- name: Start Toxiproxy
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ jobs:
- single
- cluster
- activefailover
db-ext-names:
- false
java-version:
- 21
user-language:
Expand Down Expand Up @@ -135,8 +133,6 @@ jobs:
- single
- cluster
- activefailover
db-ext-names:
- false
java-version:
- 21
user-language:
Expand Down Expand Up @@ -188,8 +184,6 @@ jobs:
- docker.io/arangodb/arangodb:3.11.7
topology:
- single
db-ext-names:
- false
java-version:
- 21
user-language:
Expand Down Expand Up @@ -272,8 +266,6 @@ jobs:
- docker.io/arangodb/enterprise:3.11.7
topology:
- cluster
db-ext-names:
- false
java-version:
- 17

Expand Down
38 changes: 38 additions & 0 deletions core/src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,44 @@ public Builder asyncExecutor(final Executor executor) {
return this;
}

/**
* Sets the {@code content-encoding} and {@code accept-encoding} to use for HTTP requests and the related
* algorithm to encode and decode the transferred data. (default: {@link Compression#NONE})
*
* @param compression format
* @return {@link ArangoDB.Builder}
* @since ArangoDB 3.12
*/
public Builder compression(final Compression compression) {
config.setCompression(compression);
return this;
}

/**
* Sets the minimum HTTP request body size (in bytes) to trigger compression.
* (default: {@code 1024})
*
* @param threshold body size (in bytes)
* @return {@link ArangoDB.Builder}
* @since ArangoDB 3.12
*/
public Builder compressionThreshold(Integer threshold) {
config.setCompressionThreshold(threshold);
return this;
}

/**
* Sets the compression level. (default: {@code 6})
*
* @param level compression level between 0 and 9
* @return {@link ArangoDB.Builder}
* @since ArangoDB 3.12
*/
public Builder compressionLevel(Integer level) {
config.setCompressionLevel(level);
return this;
}

@UnstableApi
protected ProtocolProvider protocolProvider(Protocol protocol) {
ServiceLoader<ProtocolProvider> loader = ServiceLoader.load(ProtocolProvider.class);
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/com/arangodb/Compression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.arangodb;

public enum Compression {
NONE,
DEFLATE,
GZIP
}
13 changes: 13 additions & 0 deletions core/src/main/java/com/arangodb/config/ArangoConfigProperties.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arangodb.config;

import com.arangodb.Compression;
import com.arangodb.Protocol;
import com.arangodb.entity.LoadBalancingStrategy;
import com.arangodb.internal.config.ArangoConfigPropertiesImpl;
Expand Down Expand Up @@ -97,4 +98,16 @@ default Optional<Integer> getResponseQueueTimeSamples() {
return Optional.empty();
}

default Optional<Compression> getCompression() {
return Optional.empty();
}

default Optional<Integer> getCompressionThreshold() {
return Optional.empty();
}

default Optional<Integer> getCompressionLevel() {
return Optional.empty();
}

}
7 changes: 7 additions & 0 deletions core/src/main/java/com/arangodb/internal/ArangoDefaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.arangodb.internal;

import com.arangodb.Compression;
import com.arangodb.Protocol;
import com.arangodb.config.HostDescription;
import com.arangodb.entity.LoadBalancingStrategy;
Expand Down Expand Up @@ -53,6 +54,12 @@ public final class ArangoDefaults {
public static final LoadBalancingStrategy DEFAULT_LOAD_BALANCING_STRATEGY = LoadBalancingStrategy.NONE;
public static final Integer DEFAULT_RESPONSE_QUEUE_TIME_SAMPLES = 10;

// region compression
public static final Compression DEFAULT_COMPRESSION = Compression.NONE;
public static final Integer DEFAULT_COMPRESSION_THRESHOLD = 1024;
public static final Integer DEFAULT_COMPRESSION_LEVEL = 6;
// endregion

private ArangoDefaults() {
super();
}
Expand Down
31 changes: 31 additions & 0 deletions core/src/main/java/com/arangodb/internal/config/ArangoConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.arangodb.internal.config;

import com.arangodb.ArangoDBException;
import com.arangodb.Compression;
import com.arangodb.ContentType;
import com.arangodb.Protocol;
import com.arangodb.arch.UsedInApi;
Expand Down Expand Up @@ -45,6 +46,9 @@ public class ArangoConfig {
private Integer responseQueueTimeSamples;
private Module protocolModule;
private Executor asyncExecutor;
private Compression compression;
private Integer compressionThreshold;
private Integer compressionLevel;

private static final Logger LOG = LoggerFactory.getLogger(ArangoConfig.class);

Expand Down Expand Up @@ -97,6 +101,9 @@ public void loadProperties(final ArangoConfigProperties properties) {
acquireHostListInterval = properties.getAcquireHostListInterval().orElse(ArangoDefaults.DEFAULT_ACQUIRE_HOST_LIST_INTERVAL);
loadBalancingStrategy = properties.getLoadBalancingStrategy().orElse(ArangoDefaults.DEFAULT_LOAD_BALANCING_STRATEGY);
responseQueueTimeSamples = properties.getResponseQueueTimeSamples().orElse(ArangoDefaults.DEFAULT_RESPONSE_QUEUE_TIME_SAMPLES);
compression = properties.getCompression().orElse(ArangoDefaults.DEFAULT_COMPRESSION);
compressionThreshold = properties.getCompressionThreshold().orElse(ArangoDefaults.DEFAULT_COMPRESSION_THRESHOLD);
compressionLevel = properties.getCompressionLevel().orElse(ArangoDefaults.DEFAULT_COMPRESSION_LEVEL);
}

public List<HostDescription> getHosts() {
Expand Down Expand Up @@ -287,4 +294,28 @@ public Executor getAsyncExecutor() {
public void setAsyncExecutor(Executor asyncExecutor) {
this.asyncExecutor = asyncExecutor;
}

public Compression getCompression() {
return compression;
}

public void setCompression(Compression compression) {
this.compression = compression;
}

public Integer getCompressionThreshold() {
return compressionThreshold;
}

public void setCompressionThreshold(Integer compressionThreshold) {
this.compressionThreshold = compressionThreshold;
}

public Integer getCompressionLevel() {
return compressionLevel;
}

public void setCompressionLevel(Integer compressionLevel) {
this.compressionLevel = compressionLevel;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.arangodb.internal.config;

import com.arangodb.ArangoDBException;
import com.arangodb.Compression;
import com.arangodb.Protocol;
import com.arangodb.config.ArangoConfigProperties;
import com.arangodb.config.HostDescription;
Expand Down Expand Up @@ -145,4 +146,19 @@ public Optional<Integer> getResponseQueueTimeSamples() {
return Optional.ofNullable(getProperty("responseQueueTimeSamples")).map(Integer::valueOf);
}

@Override
public Optional<Compression> getCompression() {
return Optional.ofNullable(getProperty("compression")).map(Compression::valueOf);
}

@Override
public Optional<Integer> getCompressionThreshold() {
return Optional.ofNullable(getProperty("compressionThreshold")).map(Integer::valueOf);
}

@Override
public Optional<Integer> getCompressionLevel() {
return Optional.ofNullable(getProperty("compressionLevel")).map(Integer::valueOf);
}

}
5 changes: 5 additions & 0 deletions docker/start_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
STARTER_MODE=${STARTER_MODE:=single}
DOCKER_IMAGE=${DOCKER_IMAGE:=docker.io/arangodb/arangodb:latest}
SSL=${SSL:=false}
COMPRESSION=${COMPRESSION:=false}

STARTER_DOCKER_IMAGE=docker.io/arangodb/arangodb-starter:latest
GW=172.28.0.1
Expand Down Expand Up @@ -44,6 +45,10 @@ if [ "$SSL" == "true" ]; then
ARANGOSH_SCHEME=http+ssl
fi

if [ "$COMPRESSION" == "true" ]; then
STARTER_ARGS="${STARTER_ARGS} --all.http.compress-response-threshold=1"
fi

if [ "$USE_MOUNTED_DATA" == "true" ]; then
STARTER_ARGS="${STARTER_ARGS} --starter.data-dir=/data"
MOUNT_DATA="-v $LOCATION/data:/data"
Expand Down
35 changes: 35 additions & 0 deletions driver/src/test/java/com/arangodb/ArangoConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.arangodb;

import com.arangodb.internal.ArangoDefaults;
import com.arangodb.internal.config.ArangoConfig;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ArangoConfigTest {
@Test
void defaultValues() {
ArangoConfig cfg = new ArangoConfig();
assertThat(cfg.getHosts()).isEqualTo(ArangoDefaults.DEFAULT_HOSTS);
assertThat(cfg.getProtocol()).isEqualTo(Protocol.HTTP2_JSON);
assertThat(cfg.getTimeout()).isEqualTo(ArangoDefaults.DEFAULT_TIMEOUT);
assertThat(cfg.getUser()).isEqualTo(ArangoDefaults.DEFAULT_USER);
assertThat(cfg.getPassword()).isNull();
assertThat(cfg.getJwt()).isNull();
assertThat(cfg.getUseSsl()).isEqualTo(ArangoDefaults.DEFAULT_USE_SSL);
assertThat(cfg.getSslContext()).isNull();
assertThat(cfg.getVerifyHost()).isEqualTo(ArangoDefaults.DEFAULT_VERIFY_HOST);
assertThat(cfg.getChunkSize()).isEqualTo(ArangoDefaults.DEFAULT_CHUNK_SIZE);
assertThat(cfg.getMaxConnections()).isEqualTo(ArangoDefaults.MAX_CONNECTIONS_HTTP2_DEFAULT);
assertThat(cfg.getConnectionTtl()).isNull();
assertThat(cfg.getKeepAliveInterval()).isNull();
assertThat(cfg.getAcquireHostList()).isEqualTo(ArangoDefaults.DEFAULT_ACQUIRE_HOST_LIST);
assertThat(cfg.getAcquireHostListInterval()).isEqualTo(ArangoDefaults.DEFAULT_ACQUIRE_HOST_LIST_INTERVAL);
assertThat(cfg.getLoadBalancingStrategy()).isEqualTo(ArangoDefaults.DEFAULT_LOAD_BALANCING_STRATEGY);
assertThat(cfg.getResponseQueueTimeSamples()).isEqualTo(ArangoDefaults.DEFAULT_RESPONSE_QUEUE_TIME_SAMPLES);
assertThat(cfg.getAsyncExecutor()).isNull();
assertThat(cfg.getCompression()).isEqualTo(ArangoDefaults.DEFAULT_COMPRESSION);
assertThat(cfg.getCompressionThreshold()).isEqualTo(ArangoDefaults.DEFAULT_COMPRESSION_THRESHOLD);
assertThat(cfg.getCompressionLevel()).isEqualTo(ArangoDefaults.DEFAULT_COMPRESSION_LEVEL);
}
}
26 changes: 24 additions & 2 deletions driver/src/test/java/mp/ArangoConfigPropertiesMPImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mp;

import com.arangodb.Compression;
import com.arangodb.Protocol;
import com.arangodb.config.ArangoConfigProperties;
import com.arangodb.config.HostDescription;
Expand Down Expand Up @@ -29,6 +30,9 @@ public final class ArangoConfigPropertiesMPImpl implements ArangoConfigPropertie
private Optional<Integer> acquireHostListInterval;
private Optional<LoadBalancingStrategy> loadBalancingStrategy;
private Optional<Integer> responseQueueTimeSamples;
private Optional<Compression> compression;
private Optional<Integer> compressionThreshold;
private Optional<Integer> compressionLevel;

@Override
public Optional<List<HostDescription>> getHosts() {
Expand Down Expand Up @@ -110,17 +114,32 @@ public Optional<Integer> getResponseQueueTimeSamples() {
return responseQueueTimeSamples;
}

@Override
public Optional<Compression> getCompression() {
return compression;
}

@Override
public Optional<Integer> getCompressionThreshold() {
return compressionThreshold;
}

@Override
public Optional<Integer> getCompressionLevel() {
return compressionLevel;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ArangoConfigPropertiesMPImpl that = (ArangoConfigPropertiesMPImpl) o;
return Objects.equals(hosts, that.hosts) && Objects.equals(protocol, that.protocol) && Objects.equals(user, that.user) && Objects.equals(password, that.password) && Objects.equals(jwt, that.jwt) && Objects.equals(timeout, that.timeout) && Objects.equals(useSsl, that.useSsl) && Objects.equals(verifyHost, that.verifyHost) && Objects.equals(chunkSize, that.chunkSize) && Objects.equals(maxConnections, that.maxConnections) && Objects.equals(connectionTtl, that.connectionTtl) && Objects.equals(keepAliveInterval, that.keepAliveInterval) && Objects.equals(acquireHostList, that.acquireHostList) && Objects.equals(acquireHostListInterval, that.acquireHostListInterval) && Objects.equals(loadBalancingStrategy, that.loadBalancingStrategy) && Objects.equals(responseQueueTimeSamples, that.responseQueueTimeSamples);
return Objects.equals(hosts, that.hosts) && Objects.equals(protocol, that.protocol) && Objects.equals(user, that.user) && Objects.equals(password, that.password) && Objects.equals(jwt, that.jwt) && Objects.equals(timeout, that.timeout) && Objects.equals(useSsl, that.useSsl) && Objects.equals(verifyHost, that.verifyHost) && Objects.equals(chunkSize, that.chunkSize) && Objects.equals(maxConnections, that.maxConnections) && Objects.equals(connectionTtl, that.connectionTtl) && Objects.equals(keepAliveInterval, that.keepAliveInterval) && Objects.equals(acquireHostList, that.acquireHostList) && Objects.equals(acquireHostListInterval, that.acquireHostListInterval) && Objects.equals(loadBalancingStrategy, that.loadBalancingStrategy) && Objects.equals(responseQueueTimeSamples, that.responseQueueTimeSamples) && Objects.equals(compression, that.compression) && Objects.equals(compressionThreshold, that.compressionThreshold) && Objects.equals(compressionLevel, that.compressionLevel);
}

@Override
public int hashCode() {
return Objects.hash(hosts, protocol, user, password, jwt, timeout, useSsl, verifyHost, chunkSize, maxConnections, connectionTtl, keepAliveInterval, acquireHostList, acquireHostListInterval, loadBalancingStrategy, responseQueueTimeSamples);
return Objects.hash(hosts, protocol, user, password, jwt, timeout, useSsl, verifyHost, chunkSize, maxConnections, connectionTtl, keepAliveInterval, acquireHostList, acquireHostListInterval, loadBalancingStrategy, responseQueueTimeSamples, compression, compressionThreshold, compressionLevel);
}

@Override
Expand All @@ -142,6 +161,9 @@ public String toString() {
", acquireHostListInterval=" + acquireHostListInterval +
", loadBalancingStrategy=" + loadBalancingStrategy +
", responseQueueTimeSamples=" + responseQueueTimeSamples +
", compression=" + compression +
", compressionThreshold=" + compressionThreshold +
", compressionLevel=" + compressionLevel +
'}';
}
}
3 changes: 3 additions & 0 deletions driver/src/test/java/mp/ConfigMPDefaultsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private void checkResult(ArangoConfigProperties config) {
assertThat(config.getAcquireHostListInterval()).isEmpty();
assertThat(config.getLoadBalancingStrategy()).isEmpty();
assertThat(config.getResponseQueueTimeSamples()).isEmpty();
assertThat(config.getCompression()).isEmpty();
assertThat(config.getCompressionThreshold()).isNotPresent();
assertThat(config.getCompressionLevel()).isNotPresent();
}

}
Loading