Skip to content
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

core: support user-agent in InProcess #3853

Merged
merged 1 commit into from
Dec 11, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public ConnectionClientTransport newClientTransport(
if (closed) {
throw new IllegalStateException("The transport factory is closed.");
}
return new InProcessTransport(name, authority);
return new InProcessTransport(name, authority, userAgent);
}

@Override
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/io/grpc/inprocess/InProcessTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.grpc.internal.ClientStream;
import io.grpc.internal.ClientStreamListener;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.ManagedClientTransport;
import io.grpc.internal.NoopClientStream;
import io.grpc.internal.ObjectPool;
Expand Down Expand Up @@ -66,6 +67,7 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
private final InternalLogId logId = InternalLogId.allocate(getClass().getName());
private final String name;
private final String authority;
private final String userAgent;
private ObjectPool<ScheduledExecutorService> serverSchedulerPool;
private ScheduledExecutorService serverScheduler;
private ServerTransportListener serverTransportListener;
Expand All @@ -82,9 +84,10 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
@GuardedBy("this")
private List<ServerStreamTracer.Factory> serverStreamTracerFactories;

public InProcessTransport(String name, String authority) {
public InProcessTransport(String name, String authority, String userAgent) {
this.name = name;
this.authority = authority;
this.userAgent = userAgent;
}

@CheckReturnValue
Expand Down Expand Up @@ -143,6 +146,9 @@ public void start(ClientStreamListener listener) {
}
};
}
headers.put(
GrpcUtil.USER_AGENT_KEY,
GrpcUtil.getGrpcUserAgent("inprocess", userAgent));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the agent should be a final var for this instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that as a follow-up.

return new InProcessStream(method, headers, callOptions, authority).clientStream;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public class InProcessTransportTest extends AbstractTransportTest {
private static final String TRANSPORT_NAME = "perfect-for-testing";
private static final String AUTHORITY = "a-testing-authority";
private static final String USER_AGENT = "a-testing-user-agent";

@Override
protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) {
Expand All @@ -49,7 +50,7 @@ protected String testAuthority(InternalServer server) {

@Override
protected ManagedClientTransport newClientTransport(InternalServer server) {
return new InProcessTransport(TRANSPORT_NAME, testAuthority(server));
return new InProcessTransport(TRANSPORT_NAME, testAuthority(server), USER_AGENT);
}

@Override
Expand Down