Skip to content

Commit

Permalink
Merge branch 'master' into add-custom-note-locator
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocesarj authored Feb 28, 2024
2 parents 10b8af2 + 74630c8 commit ff416d6
Show file tree
Hide file tree
Showing 26 changed files with 361 additions and 68 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.spotify</groupId>
<artifactId>folsom-bom</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Folsom BOM</name>
Expand Down
2 changes: 1 addition & 1 deletion folsom-elasticache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom-elasticache</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.Socket;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ssl.SSLSocketFactory;

/**
* Implement support for AWS ElastiCache node auto-discovery <a
Expand All @@ -52,6 +53,7 @@ public static class Builder {
private int configPort = 11211;
private long ttl = MINUTES.toMillis(1);
private int timeout = 5000; // ms
private boolean useTls = false;

private Builder(final String configHost) {
this.configHost = configHost;
Expand Down Expand Up @@ -95,13 +97,24 @@ public Builder withResolveTimeoutMillis(final int timeout) {
return this;
}

/**
* Configure TLS usage for connection. Default: false
*
* @param useTls whether resolver should use TLS connection
* @return The builder
*/
public Builder withTls(final boolean useTls) {
this.useTls = useTls;
return this;
}

/**
* Build the resolver
*
* @return The resolver
*/
public ElastiCacheResolver build() {
final Resolver resolver = new SocketResolver(configHost, configPort, timeout);
final Resolver resolver = new SocketResolver(configHost, configPort, timeout, useTls);

return new ElastiCacheResolver(resolver, ttl);
}
Expand Down Expand Up @@ -157,20 +170,22 @@ public interface Resolver {
}

public static class SocketResolver implements Resolver {

private final String configHost;
private final int configPort;
private final int timeout;
private final boolean useTls;
private final ResponseParser parser = new ResponseParser();

public SocketResolver(final String configHost, final int configPort, final int timeout) {
public SocketResolver(
final String configHost, final int configPort, final int timeout, final boolean useTls) {
this.configHost = configHost;
this.configPort = configPort;
this.timeout = timeout;
this.useTls = useTls;
}

public Response resolve() {
try (final Socket socket = new Socket()) {
try (final Socket socket = createSocket()) {
socket.setSoTimeout(timeout);
socket.connect(new InetSocketAddress(configHost, configPort), timeout);

Expand All @@ -181,5 +196,13 @@ public Response resolve() {
throw new RuntimeException("ElastiCache auto-discovery failed", e);
}
}

private Socket createSocket() throws IOException {
if (useTls) {
return SSLSocketFactory.getDefault().createSocket();
} else {
return new Socket();
}
}
}
}
4 changes: 2 additions & 2 deletions folsom-micrometer-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom-micrometer-metrics</artifactId>
Expand All @@ -19,7 +19,7 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.10.3</version>
<version>1.12.0</version>
</dependency>


Expand Down
4 changes: 2 additions & 2 deletions folsom-opencensus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom-opencensus</artifactId>
Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static io.opencensus.trace.AttributeValue.stringAttributeValue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoInteractions;

import com.google.common.io.BaseEncoding;
import com.spotify.folsom.Span;
Expand All @@ -29,7 +29,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class OpenCensusSpanTest {
Expand Down Expand Up @@ -82,6 +82,6 @@ public void nullValue() {
final Span span = new OpenCensusSpan(wrapped, true);
span.value(null);

verifyZeroInteractions(wrapped);
verifyNoInteractions(wrapped);
}
}
6 changes: 3 additions & 3 deletions folsom-opentelemetry-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom-opentelemetry-metrics</artifactId>
Expand All @@ -19,12 +19,12 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>1.29.0</version>
<version>1.33.0</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-testing</artifactId>
<version>1.29.0</version>
<version>1.33.0</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion folsom-semantic-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom-semantic-metrics</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion folsom-yammer-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom-yammer-metrics</artifactId>
Expand Down
31 changes: 18 additions & 13 deletions folsom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,43 @@
<parent>
<groupId>com.spotify</groupId>
<artifactId>folsom-parent</artifactId>
<version>1.17.1-SNAPSHOT</version>
<version>1.20.1-SNAPSHOT</version>
</parent>

<artifactId>folsom</artifactId>
<packaging>jar</packaging>
<name>folsom</name>

<properties>
<netty.version>4.1.87.Final</netty.version>
<netty.version>4.1.101.Final</netty.version>
</properties>

<dependencies>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>completable-futures</artifactId>
<version>0.3.2</version>
<version>0.3.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-android</version>
<version>32.1.3-android</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
Expand All @@ -53,9 +58,9 @@
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>

<!-- Tests -->
Expand All @@ -67,7 +72,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>1.3.14</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -95,20 +100,20 @@
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>hamcrest-future</artifactId>
<version>1.0.1</version>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.6.0</version>
<version>2.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.spotify.folsom.client.NoopTracer;
import com.spotify.folsom.client.ascii.DefaultAsciiMemcacheClient;
import com.spotify.folsom.client.binary.DefaultBinaryMemcacheClient;
import com.spotify.folsom.client.tls.SSLEngineFactory;
import com.spotify.folsom.guava.HostAndPort;
import com.spotify.folsom.ketama.AddressAndClient;
import com.spotify.folsom.ketama.Continuum;
Expand Down Expand Up @@ -130,6 +131,7 @@ public class MemcacheClientBuilder<V> {
private boolean skipAuth = false;

private Function<Collection<AddressAndClient>, NodeLocator> nodeLocator = Continuum::new;
private SSLEngineFactory sslEngineFactory = null;

/**
* Create a client builder for byte array values.
Expand Down Expand Up @@ -601,6 +603,11 @@ MemcacheClientBuilder<V> withoutAuthenticationValidation() {
return this;
}

public MemcacheClientBuilder<V> withSSLEngineFactory(final SSLEngineFactory sslEngineFactory) {
this.sslEngineFactory = sslEngineFactory;
return this;
}

/**
* Create a client that uses the binary memcache protocol.
*
Expand Down Expand Up @@ -755,6 +762,7 @@ private RawMemcacheClient createReconnectingClient(
metrics,
maxSetLength,
eventLoopGroup,
channelClass);
channelClass,
sslEngineFactory);
}
}
Loading

0 comments on commit ff416d6

Please sign in to comment.