Skip to content

Commit

Permalink
Merge branch 'main' into feature/default-lb
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Jun 10, 2024
2 parents 1969a16 + 8dd819c commit 5330c5a
Show file tree
Hide file tree
Showing 67 changed files with 1,145 additions and 2,087 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.net.URI;
import java.time.Duration;

import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.client.endpoint.AbstractDynamicEndpointGroupBuilder;
import com.linecorp.armeria.client.endpoint.EndpointSelectionStrategy;
import com.linecorp.armeria.common.Flags;
Expand All @@ -44,7 +43,7 @@
*/
@UnstableApi
public final class ConsulEndpointGroupBuilder
extends AbstractDynamicEndpointGroupBuilder implements ConsulConfigSetters {
extends AbstractDynamicEndpointGroupBuilder<ConsulEndpointGroupBuilder> implements ConsulConfigSetters {

private static final long DEFAULT_HEALTH_CHECK_INTERVAL_MILLIS = 10_000;

Expand Down Expand Up @@ -146,29 +145,4 @@ public ConsulEndpointGroup build() {
consulClientBuilder.build(), serviceName, registryFetchIntervalMillis,
useHealthyEndpoints, datacenter, filter);
}

@Override
public ConsulEndpointGroupBuilder allowEmptyEndpoints(boolean allowEmptyEndpoints) {
return (ConsulEndpointGroupBuilder) super.allowEmptyEndpoints(allowEmptyEndpoints);
}

/**
* Sets the timeout to wait until a successful {@link Endpoint} selection.
* {@link Duration#ZERO} disables the timeout.
* If unspecified, {@link Flags#defaultResponseTimeoutMillis()} is used by default.
*/
@Override
public ConsulEndpointGroupBuilder selectionTimeout(Duration selectionTimeout) {
return (ConsulEndpointGroupBuilder) super.selectionTimeout(selectionTimeout);
}

/**
* Sets the timeout to wait until a successful {@link Endpoint} selection.
* {@code 0} disables the timeout.
* If unspecified, {@link Flags#defaultResponseTimeoutMillis()} is used by default.
*/
@Override
public ConsulEndpointGroupBuilder selectionTimeoutMillis(long selectionTimeoutMillis) {
return (ConsulEndpointGroupBuilder) super.selectionTimeoutMillis(selectionTimeoutMillis);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* A skeletal builder implementation for DNS resolvers.
*/
@UnstableApi
public abstract class AbstractDnsResolverBuilder {
public abstract class AbstractDnsResolverBuilder<SELF extends AbstractDnsResolverBuilder<SELF>> {

private DnsCache dnsCache = DnsCache.ofDefault();
private String cacheSpec = Flags.dnsCacheSpec();
Expand Down Expand Up @@ -92,6 +92,14 @@ public abstract class AbstractDnsResolverBuilder {
*/
protected AbstractDnsResolverBuilder() {}

/**
* Return {@code this}.
*/
@SuppressWarnings("unchecked")
protected final SELF self() {
return (SELF) this;
}

/**
* Sets if this resolver should generate detailed trace information in exception messages so that
* it is easier to understand the cause of resolution failure. This flag is enabled by default.
Expand All @@ -100,17 +108,17 @@ protected AbstractDnsResolverBuilder() {}
* {@link LoggingDnsQueryLifeCycleObserverFactory}.
*/
@Deprecated
public AbstractDnsResolverBuilder traceEnabled(boolean traceEnabled) {
public SELF traceEnabled(boolean traceEnabled) {
this.traceEnabled = traceEnabled;
return this;
return self();
}

/**
* Sets the timeout of the DNS query performed by this resolver.
* {@code 0} disables the timeout.
* If unspecified, {@value DnsUtil#DEFAULT_DNS_QUERY_TIMEOUT_MILLIS} ms will be used.
*/
public AbstractDnsResolverBuilder queryTimeout(Duration queryTimeout) {
public SELF queryTimeout(Duration queryTimeout) {
requireNonNull(queryTimeout, "queryTimeout");
checkArgument(!queryTimeout.isNegative(), "queryTimeout: %s (expected: >= 0)", queryTimeout);
return queryTimeoutMillis(queryTimeout.toMillis());
Expand All @@ -128,10 +136,10 @@ protected final long queryTimeoutMillis() {
* {@code 0} disables the timeout.
* If unspecified, {@value DnsUtil#DEFAULT_DNS_QUERY_TIMEOUT_MILLIS} ms will be used.
*/
public AbstractDnsResolverBuilder queryTimeoutMillis(long queryTimeoutMillis) {
public SELF queryTimeoutMillis(long queryTimeoutMillis) {
checkArgument(queryTimeoutMillis >= 0, "queryTimeoutMillis: %s (expected: >= 0)", queryTimeoutMillis);
this.queryTimeoutMillis = queryTimeoutMillis;
return this;
return self();
}

/**
Expand All @@ -140,7 +148,7 @@ public AbstractDnsResolverBuilder queryTimeoutMillis(long queryTimeoutMillis) {
* <a href="https://en.wikipedia.org/wiki/Search_domain">search domain</a> resolution.
* If unspecified, the value of {@link #queryTimeout(Duration)} is used.
*/
public AbstractDnsResolverBuilder queryTimeoutForEachAttempt(Duration queryTimeoutForEachAttempt) {
public SELF queryTimeoutForEachAttempt(Duration queryTimeoutForEachAttempt) {
requireNonNull(queryTimeoutForEachAttempt, "queryTimeoutForEachAttempt");
final long queryTimeoutMillisForEachAttempt = queryTimeoutForEachAttempt.toMillis();
checkArgument(queryTimeoutMillisForEachAttempt > 0, "queryTimeoutForEachAttempt: %s (expected: > 0)",
Expand All @@ -154,20 +162,20 @@ public AbstractDnsResolverBuilder queryTimeoutForEachAttempt(Duration queryTimeo
* <a href="https://en.wikipedia.org/wiki/Search_domain">search domain</a> resolution.
* If unspecified, the value of {@link #queryTimeoutMillis(long)} is used.
*/
public AbstractDnsResolverBuilder queryTimeoutMillisForEachAttempt(long queryTimeoutMillisForEachAttempt) {
public SELF queryTimeoutMillisForEachAttempt(long queryTimeoutMillisForEachAttempt) {
checkArgument(queryTimeoutMillisForEachAttempt > 0,
"queryTimeoutMillisForEachAttempt: %s (expected: > 0)", queryTimeoutMillisForEachAttempt);
this.queryTimeoutMillisForEachAttempt = queryTimeoutMillisForEachAttempt;
return this;
return self();
}

/**
* Sets if this resolver has to send a DNS query with the RD (recursion desired) flag set.
* This flag is enabled by default.
*/
public AbstractDnsResolverBuilder recursionDesired(boolean recursionDesired) {
public SELF recursionDesired(boolean recursionDesired) {
this.recursionDesired = recursionDesired;
return this;
return self();
}

/**
Expand All @@ -179,24 +187,24 @@ public AbstractDnsResolverBuilder recursionDesired(boolean recursionDesired) {
*
* @see #serverAddressStreamProvider(DnsServerAddressStreamProvider)
*/
public AbstractDnsResolverBuilder maxQueriesPerResolve(int maxQueriesPerResolve) {
public SELF maxQueriesPerResolve(int maxQueriesPerResolve) {
checkArgument(maxQueriesPerResolve > 0, "maxQueriesPerResolve: %s (expected: > 0)",
maxQueriesPerResolve);
this.maxQueriesPerResolve = maxQueriesPerResolve;
return this;
return self();
}

/**
* Sets the DNS server addresses to send queries to. Operating system default is used by default.
*/
public AbstractDnsResolverBuilder serverAddresses(InetSocketAddress... serverAddresses) {
public SELF serverAddresses(InetSocketAddress... serverAddresses) {
return serverAddresses(ImmutableList.copyOf(requireNonNull(serverAddresses, "serverAddresses")));
}

/**
* Sets the DNS server addresses to send queries to. Operating system default is used by default.
*/
public AbstractDnsResolverBuilder serverAddresses(Iterable<InetSocketAddress> serverAddresses) {
public SELF serverAddresses(Iterable<InetSocketAddress> serverAddresses) {
final DnsServerAddresses addrs = DnsServerAddresses.sequential(serverAddresses);
return serverAddressStreamProvider(hostname -> addrs.stream());
}
Expand All @@ -212,11 +220,11 @@ protected final DnsServerAddressStreamProvider serverAddressStreamProvider() {
* Sets the {@link DnsServerAddressStreamProvider} which is used to determine which DNS server is used to
* resolve each hostname.
*/
public AbstractDnsResolverBuilder serverAddressStreamProvider(
public SELF serverAddressStreamProvider(
DnsServerAddressStreamProvider serverAddressStreamProvider) {
requireNonNull(serverAddressStreamProvider, "serverAddressStreamProvider");
this.serverAddressStreamProvider = serverAddressStreamProvider;
return this;
return self();
}

/**
Expand All @@ -226,28 +234,28 @@ public AbstractDnsResolverBuilder serverAddressStreamProvider(
* @deprecated Use {@link #serverAddressStreamProvider(DnsServerAddressStreamProvider)} instead.
*/
@Deprecated
public AbstractDnsResolverBuilder dnsServerAddressStreamProvider(
public SELF dnsServerAddressStreamProvider(
DnsServerAddressStreamProvider dnsServerAddressStreamProvider) {
return serverAddressStreamProvider(dnsServerAddressStreamProvider);
}

/**
* Sets the capacity of the datagram packet buffer in bytes.
*/
public AbstractDnsResolverBuilder maxPayloadSize(int maxPayloadSize) {
public SELF maxPayloadSize(int maxPayloadSize) {
checkArgument(maxPayloadSize > 0, "maxPayloadSize: %s (expected: > 0)", maxPayloadSize);
this.maxPayloadSize = maxPayloadSize;
return this;
return self();
}

/**
* Enables the automatic inclusion of an optional records that tries to give the remote DNS server a hint
* about how much data the resolver can read per response. Some DNS Server may not support this and so
* fail to answer queries.
*/
public AbstractDnsResolverBuilder optResourceEnabled(boolean optResourceEnabled) {
public SELF optResourceEnabled(boolean optResourceEnabled) {
this.optResourceEnabled = optResourceEnabled;
return this;
return self();
}

/**
Expand All @@ -261,21 +269,21 @@ protected final HostsFileEntriesResolver hostsFileEntriesResolver() {
* Sets the {@link HostsFileEntriesResolver} which is used to first check if the hostname is locally
* aliased.
*/
public AbstractDnsResolverBuilder hostsFileEntriesResolver(
public SELF hostsFileEntriesResolver(
HostsFileEntriesResolver hostsFileEntriesResolver) {
this.hostsFileEntriesResolver = hostsFileEntriesResolver;
return this;
return self();
}

/**
* Sets the {@link DnsQueryLifecycleObserverFactory} that is used to generate objects which can observe
* individual DNS queries.
*/
public AbstractDnsResolverBuilder dnsQueryLifecycleObserverFactory(
public SELF dnsQueryLifecycleObserverFactory(
DnsQueryLifecycleObserverFactory observerFactory) {
requireNonNull(observerFactory, "observerFactory");
dnsQueryLifecycleObserverFactory = observerFactory;
return this;
return self();
}

/**
Expand All @@ -285,17 +293,17 @@ public AbstractDnsResolverBuilder dnsQueryLifecycleObserverFactory(
* @deprecated Use {@link #enableDnsQueryMetrics(boolean)} instead.
*/
@Deprecated
public AbstractDnsResolverBuilder disableDnsQueryMetrics() {
public SELF disableDnsQueryMetrics() {
return enableDnsQueryMetrics(false);
}

/**
* Enables the default {@link DnsQueryLifecycleObserverFactory} that collects DNS query
* metrics through {@link MeterRegistry}. This option is enabled by default.
*/
public AbstractDnsResolverBuilder enableDnsQueryMetrics(boolean enable) {
public SELF enableDnsQueryMetrics(boolean enable) {
dnsQueryMetricsEnabled = enable;
return this;
return self();
}

/**
Expand All @@ -308,18 +316,18 @@ protected final List<String> searchDomains() {
/**
* Sets the search domains of the resolver.
*/
public AbstractDnsResolverBuilder searchDomains(String... searchDomains) {
public SELF searchDomains(String... searchDomains) {
requireNonNull(searchDomains, "searchDomains");
return searchDomains(ImmutableList.copyOf(searchDomains));
}

/**
* Sets the list of search domains of the resolver.
*/
public AbstractDnsResolverBuilder searchDomains(Iterable<String> searchDomains) {
public SELF searchDomains(Iterable<String> searchDomains) {
requireNonNull(searchDomains, "searchDomains");
this.searchDomains = ImmutableList.copyOf(searchDomains);
return this;
return self();
}

/**
Expand All @@ -332,19 +340,19 @@ protected final int ndots() {
/**
* Sets the number of dots which must appear in a name before an initial absolute query is made.
*/
public AbstractDnsResolverBuilder ndots(int ndots) {
public SELF ndots(int ndots) {
checkArgument(ndots >= 0, "ndots: %s (expected: >= 0)", ndots);
this.ndots = ndots;
return this;
return self();
}

/**
* Sets if the domain and host names should be decoded to unicode when received.
* See <a href="https://datatracker.ietf.org/doc/rfc3492/">rfc3492</a>. This flag is enabled by default.
*/
public AbstractDnsResolverBuilder decodeIdn(boolean decodeIdn) {
public SELF decodeIdn(boolean decodeIdn) {
this.decodeIdn = decodeIdn;
return this;
return self();
}

/**
Expand All @@ -358,9 +366,9 @@ protected final MeterRegistry meterRegistry() {
/**
* Sets {@link MeterRegistry} to collect the DNS query metrics.
*/
public AbstractDnsResolverBuilder meterRegistry(MeterRegistry meterRegistry) {
public SELF meterRegistry(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
return this;
return self();
}

/**
Expand All @@ -376,11 +384,11 @@ protected final String cacheSpec() {
*
* <p>Note that {@link #cacheSpec(String)} and {@link #dnsCache(DnsCache)} are mutually exclusive.
*/
public AbstractDnsResolverBuilder cacheSpec(String cacheSpec) {
public SELF cacheSpec(String cacheSpec) {
requireNonNull(cacheSpec, "cacheSpec");
this.cacheSpec = cacheSpec;
needsToCreateDnsCache = true;
return this;
return self();
}

/**
Expand All @@ -407,13 +415,13 @@ protected final int maxTtl() {
*
* <p>Note that {@link #ttl(int, int)} and {@link #dnsCache(DnsCache)} are mutually exclusive.
*/
public AbstractDnsResolverBuilder ttl(int minTtl, int maxTtl) {
public SELF ttl(int minTtl, int maxTtl) {
checkArgument(minTtl > 0 && minTtl <= maxTtl,
"minTtl: %s, maxTtl: %s (expected: 1 <= minTtl <= maxTtl)", minTtl, maxTtl);
this.minTtl = minTtl;
this.maxTtl = maxTtl;
needsToCreateDnsCache = true;
return this;
return self();
}

/**
Expand All @@ -429,11 +437,11 @@ protected final int negativeTtl() {
*
* <p>Note that {@link #negativeTtl(int)} and {@link #dnsCache(DnsCache)} are mutually exclusive.
*/
public AbstractDnsResolverBuilder negativeTtl(int negativeTtl) {
public SELF negativeTtl(int negativeTtl) {
checkArgument(negativeTtl >= 0, "negativeTtl: %s (expected: >= 0)", negativeTtl);
needsToCreateDnsCache = true;
this.negativeTtl = negativeTtl;
return this;
return self();
}

/**
Expand All @@ -447,10 +455,10 @@ public AbstractDnsResolverBuilder negativeTtl(int negativeTtl) {
* mutually exclusive with {@link #dnsCache(DnsCache)}.
*/
@UnstableApi
public AbstractDnsResolverBuilder dnsCache(DnsCache dnsCache) {
public SELF dnsCache(DnsCache dnsCache) {
requireNonNull(dnsCache, "dnsCache");
this.dnsCache = dnsCache;
return this;
return self();
}

/**
Expand Down
Loading

0 comments on commit 5330c5a

Please sign in to comment.