Skip to content

Commit

Permalink
Merge branch 'main' into feature/xds-zone-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon authored Aug 2, 2024
2 parents 1a386a4 + 6a1d9bf commit 5c198f6
Show file tree
Hide file tree
Showing 344 changed files with 3,523 additions and 1,066 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI
on:
push:
branches:
- main
- "**"
tags-ignore:
# The release versions will be verified by 'publish-release.yml'
- armeria-*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.QualifiedNameable;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.tools.Diagnostic.Kind;
Expand Down Expand Up @@ -148,7 +149,9 @@ private void processAnnotation(TypeElement annotationElement, RoundEnvironment r
}

private void processMethod(ExecutableElement method) throws IOException {
final String className = ((TypeElement) method.getEnclosingElement()).getQualifiedName().toString();
final QualifiedNameable enclosingElement = (QualifiedNameable) method.getEnclosingElement();
assert enclosingElement != null;
final String className = enclosingElement.getQualifiedName().toString();
final Properties properties = readProperties(className);
final String docComment = processingEnv.getElementUtils().getDocComment(method);
if (docComment == null || !docComment.contains("@param")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static ServiceConfig newServiceConfig(Route route) {
final Path multipartUploadsLocation = Flags.defaultMultipartUploadsLocation();
final ServiceErrorHandler serviceErrorHandler = ServerErrorHandler.ofDefault().asServiceErrorHandler();
return new ServiceConfig(route, route,
SERVICE, defaultLogName, defaultServiceName, defaultServiceNaming, 0, 0,
SERVICE, defaultServiceName, defaultServiceNaming, defaultLogName, 0, 0,
false, AccessLogWriter.disabled(), CommonPools.blockingTaskExecutor(),
SuccessFunction.always(), 0, multipartUploadsLocation,
MultipartRemovalStrategy.ON_RESPONSE_COMPLETION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Scope newScope(@Nullable TraceContext currentSpan) {

@UnstableApi
@Override
public Scope decorateScope(TraceContext context, Scope scope) {
public Scope decorateScope(@Nullable TraceContext context, Scope scope) {
// If a `Scope` is decorated, `ScopeDecorator`s populate some contexts as such as MDC, which are stored
// to a thread-local. The activated contexts will be removed when `decoratedScope.close()` is called.
// If `Scope.NOOP` is specified, CurrentTraceContext.decorateScope() performs nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static TraceContext traceContext(RequestContext ctx) {
return ctx.attr(TRACE_CONTEXT_KEY);
}

public static void setTraceContext(RequestContext ctx, TraceContext traceContext) {
public static void setTraceContext(RequestContext ctx, @Nullable TraceContext traceContext) {
ctx.setAttr(TRACE_CONTEXT_KEY, traceContext);
}

Expand Down
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ plugins {
alias libs.plugins.kotlin apply false
alias libs.plugins.ktlint apply false
alias libs.plugins.errorprone apply false
alias libs.plugins.nullaway apply false
}

allprojects {
Expand Down Expand Up @@ -171,13 +172,31 @@ configure(projectsWithFlags('java')) {
// Error Prone compiler
if (!rootProject.hasProperty('noLint')) {
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'net.ltgt.nullaway'

dependencies {
errorprone libs.errorprone.core
errorprone libs.nullaway
}

nullaway {
annotatedPackages.add("com.linecorp.armeria")
}

tasks.withType(JavaCompile) {
options.errorprone.excludedPaths = '.*/gen-src/.*'
options.errorprone.nullaway {
if (name.contains("Test") || name.contains("Jmh")) {
// Disable NullAway for tests and benchmarks for now.
disable()
} else if (name.matches(/compileJava[0-9]+.*/)) {
// Disable MR-JAR classes which seem to confuse NullAway and break the build.
disable()
} else {
error()
assertsEnabled = true
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ CompletableFuture<List<Endpoint>> healthyEndpoints(String serviceName, @Nullable

@Nullable
private static Endpoint toEndpoint(HealthService healthService) {
if (healthService.service == null) {
return null;
}
if (healthService.node == null) {
return null;
}

assert healthService.service != null;
assert healthService.node != null;

if (!Strings.isNullOrEmpty(healthService.service.address)) {
return Endpoint.of(healthService.service.address, healthService.service.port);
} else if (!Strings.isNullOrEmpty(healthService.node.address)) {
Expand All @@ -122,59 +132,74 @@ private static Endpoint toEndpoint(HealthService healthService) {
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
private static final class HealthService {
@Nullable
@JsonProperty("Node")
Node node;

@Nullable
@JsonProperty("Service")
Service service;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
private static final class Node {
@Nullable
@JsonProperty("ID")
String id;

@Nullable
@JsonProperty("Node")
String node;

@Nullable
@JsonProperty("Address")
String address;

@Nullable
@JsonProperty("Datacenter")
String datacenter;

@Nullable
@JsonProperty("TaggedAddresses")
Object taggedAddresses;

@Nullable
@JsonProperty("Meta")
Map<String, Object> meta;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public static final class Service {
@Nullable
@JsonProperty("ID")
String id;

@Nullable
@JsonProperty("Service")
String service;

@Nullable
@JsonProperty("Tags")
String[] tags;

@Nullable
@JsonProperty("Address")
String address;

@Nullable
@JsonProperty("TaggedAddresses")
Object taggedAddresses;

@Nullable
@JsonProperty("Meta")
Map<String, Object> meta;

@JsonProperty("Port")
int port;

@Nullable
@JsonProperty("Weights")
Map<String, Object> weights;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http2.Http2Error;
import io.netty.handler.proxy.ProxyConnectException;

abstract class AbstractHttpRequestHandler implements ChannelFutureListener {

Expand Down Expand Up @@ -216,6 +215,7 @@ RequestHeaders mergedRequestHeaders(RequestHeaders headers) {
* {@link Channel#flush()} when each write unit is done.
*/
final void writeHeaders(RequestHeaders headers, boolean needs100Continue) {
assert session != null;
final SessionProtocol protocol = session.protocol();
assert protocol != null;
if (needs100Continue) {
Expand Down Expand Up @@ -377,8 +377,7 @@ final void failAndReset(Throwable cause) {
session.markUnacquirable();
}

if (cause instanceof ProxyConnectException || cause instanceof ResponseCompleteException) {
// - ProxyConnectException is handled by HttpSessionHandler.exceptionCaught().
if (cause instanceof ResponseCompleteException) {
// - ResponseCompleteException means the response is successfully received.
state = State.DONE;
cancel();
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/linecorp/armeria/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.linecorp.armeria.common.Response;
import com.linecorp.armeria.common.RpcRequest;
import com.linecorp.armeria.common.RpcResponse;
import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.common.util.Unwrappable;

/**
Expand Down Expand Up @@ -71,6 +72,7 @@ public interface Client<I extends Request, O extends Response> extends Unwrappab
* @see ClientFactory#unwrap(Object, Class)
* @see Unwrappable
*/
@Nullable
@Override
default <T> T as(Class<T> type) {
requireNonNull(type, "type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.linecorp.armeria.common.RequestId;
import com.linecorp.armeria.common.Response;
import com.linecorp.armeria.common.RpcRequest;
import com.linecorp.armeria.common.TimeoutException;
import com.linecorp.armeria.common.annotation.Nullable;
import com.linecorp.armeria.common.annotation.UnstableApi;
import com.linecorp.armeria.common.logging.RequestLog;
Expand Down Expand Up @@ -514,6 +515,21 @@ default void timeoutNow() {
cancel(ResponseTimeoutException.get());
}

/**
* Returns whether this {@link ClientRequestContext} has been timed-out, that is the cancellation cause
* is an instance of {@link TimeoutException} or
* {@link UnprocessedRequestException} and wrapped cause is {@link TimeoutException}.
*/
@Override
default boolean isTimedOut() {
if (RequestContext.super.isTimedOut()) {
return true;
}
final Throwable cause = cancellationCause();
return cause instanceof TimeoutException ||
cause instanceof UnprocessedRequestException && cause.getCause() instanceof TimeoutException;
}

/**
* Returns the maximum length of the received {@link Response}.
* This value is initially set from {@link ClientOptions#MAX_RESPONSE_LENGTH}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,31 @@ public ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpReques
return unwrap().newDerivedContext(id, req, rpcReq, endpoint);
}

@Nullable
@Override
public EndpointGroup endpointGroup() {
return unwrap().endpointGroup();
}

@Nullable
@Override
public Endpoint endpoint() {
return unwrap().endpoint();
}

@Nullable
@Override
public String fragment() {
return unwrap().fragment();
}

@Nullable
@Override
public String authority() {
return unwrap().authority();
}

@Nullable
@Override
public String host() {
return unwrap().host();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ public Object newClient(ClientBuilderParams params) {
return unwrap().newClient(params);
}

@Nullable
@Override
public <T> ClientBuilderParams clientBuilderParams(T client) {
return unwrap().clientBuilderParams(client);
}

@Nullable
@Override
public <T> T unwrap(Object client, Class<T> type) {
return unwrap().unwrap(client, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public Object newClient(ClientBuilderParams params) {
"No ClientFactory for scheme: " + scheme + " matched clientType: " + clientType);
}

@Nullable
@Override
public <T> T unwrap(Object client, Class<T> type) {
final T params = ClientFactory.super.unwrap(client, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void cache(DnsQuestion question, UnknownHostException cause) {
}
}

@Nullable
@Override
public List<DnsRecord> get(DnsQuestion question) throws UnknownHostException {
requireNonNull(question, "question");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public long maxResponseLength() {
return maxResponseLength;
}

@Nullable
@Override
public Long requestAutoAbortDelayMillis() {
return requestAutoAbortDelayMillis;
Expand All @@ -78,6 +79,7 @@ public Map<AttributeKey<?>, Object> attrs() {
return attributeMap;
}

@Nullable
@Override
public ExchangeType exchangeType() {
return exchangeType;
Expand Down
Loading

0 comments on commit 5c198f6

Please sign in to comment.