Skip to content

Commit

Permalink
Ensure that the tracing library does not touch the old grid code
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Nov 14, 2018
1 parent 0840fb9 commit 7312f98
Show file tree
Hide file tree
Showing 33 changed files with 97 additions and 75 deletions.
5 changes: 0 additions & 5 deletions java/client/src/org/openqa/selenium/remote/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ java_library(name = 'remote-lib',
'mobile/RemoteNetworkConnection.java',
] + glob([
'service/*.java',
'tracing/*.java',
]),
resources = [
':get-attribute',
Expand All @@ -134,14 +133,10 @@ java_library(name = 'remote-lib',
'//java/client/src/org/openqa/selenium/json:json',
'//java/client/src/org/openqa/selenium/remote/session:session',
'//third_party/java/okhttp3:okhttp',
'//third_party/java/opencensus:opencensus-api',
'//third_party/java/opentracing:opentracing-api',
],
deps = [
':http-session-id',
'//java/client/src/org/openqa/selenium:selenium',
'//third_party/java/contrib:opentracing-tracerresolver',
'//third_party/java/opentracing:opentracing-noop',
'//third_party/java/guava:guava',
],
)
Expand Down
22 changes: 22 additions & 0 deletions java/client/src/org/openqa/selenium/remote/tracing/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

java_library(
name = "tracing",
srcs = glob(["*.java"]),
exported_deps = [
# Required for the "register" API
"//third_party/java/opencensus:opencensus-api",
"//third_party/java/opentracing:opentracing-api",
],
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
'//third_party/java/contrib:opentracing-tracerresolver',
"//third_party/java/guava:guava",
"//third_party/java/opentracing:opentracing-noop",
"//third_party/java/opentracing:opentracing-util",
],
visibility = [
"//java/client/test/org/openqa/selenium/remote/tracing:",
"//java/server/src/org/openqa/selenium/grid/...",
"//java/server/test/org/openqa/selenium/grid/...",
],
)
2 changes: 2 additions & 0 deletions java/client/test/org/openqa/selenium/remote/tracing/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ java_test(
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/client/test/org/openqa/selenium/remote/tracing/simple:simple",
"//java/client/test/org/openqa/selenium/environment:environment",
"//java/client/test/org/openqa/selenium/remote/tracing/simple:simple",
"//third_party/java/assertj:assertj",
Expand Down
3 changes: 2 additions & 1 deletion java/server/src/org/openqa/selenium/grid/commands/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ java_library(
'com.google.auto.service.processor.AutoServiceProcessor',
],
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/cli:cli",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
Expand All @@ -31,4 +32,4 @@ java_library(
"//java/server/src/org/openqa/selenium/grid:",
"//java/server/src/org/openqa/selenium/grid:"
],
)
)
6 changes: 4 additions & 2 deletions java/server/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ public Executable configure(String... args) {
new EnvConfig(),
new ConcatenatingConfig("selenium", '.', System.getProperties()));

DistributedTracer tracer = DistributedTracer.getInstance();
DistributedTracer tracer = DistributedTracer.builder()
.registerDetectedTracers()
.build();
DistributedTracer.setInstance(tracer);

SessionMap sessions = new LocalSessionMap();
Distributor distributor = new LocalDistributor(tracer);
Router router = new Router(sessions, distributor);

Server<?> server = new BaseServer<>(
tracer,
new BaseServerOptions(config));
server.addRoute(Routes.matching(router).using(router).decorateWith(W3CCommandHandler.class));
server.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ public Executable configure(String... args) {
new EnvConfig(),
new ConcatenatingConfig("selenium", '.', System.getProperties()));

DistributedTracer tracer = DistributedTracer.getInstance();
DistributedTracer tracer = DistributedTracer.builder()
.registerDetectedTracers()
.build();
DistributedTracer.setInstance(tracer);

SessionMap sessions = new LocalSessionMap();
Distributor distributor = new LocalDistributor(tracer);
Expand Down Expand Up @@ -122,7 +125,7 @@ public Executable configure(String... args) {

distributor.add(node.build());

Server<?> server = new BaseServer<>(tracer, new BaseServerOptions(config));
Server<?> server = new BaseServer<>(new BaseServerOptions(config));
server.addRoute(Routes.matching(router).using(router).decorateWith(W3CCommandHandler.class));
server.start();
};
Expand Down
2 changes: 1 addition & 1 deletion java/server/src/org/openqa/selenium/grid/distributor/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/node:node",
],
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/node/remote:remote",
"//java/server/src/org/openqa/selenium/grid/server:server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ java_library(
name = "httpd",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/cli:cli",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
Expand All @@ -25,4 +26,4 @@ java_library(
visibility = [
"//java/server/src/org/openqa/selenium/grid:"
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ public Executable configure(String... args) {
DistributedTracer tracer = DistributedTracer.builder()
.registerDetectedTracers()
.build();
DistributedTracer.setInstance(tracer);

Distributor distributor = new LocalDistributor(tracer);

BaseServerOptions serverOptions = new BaseServerOptions(config);

Server<?> server = new BaseServer<>(tracer, serverOptions);
Server<?> server = new BaseServer<>(serverOptions);
server.addRoute(
Routes.matching(distributor)
.using(distributor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
],
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/web:web",
"//java/server/src/org/openqa/selenium/grid/node:node",
"//java/server/src/org/openqa/selenium/grid/node/remote:remote",
Expand All @@ -16,4 +16,4 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/...",
"//java/server/test/org/openqa/selenium/grid/...",
]
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
],
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/web:web",
],
visibility = [
"//java/server/src/org/openqa/selenium/grid/...",
"//java/server/test/org/openqa/selenium/grid/...",
]
)
)
1 change: 1 addition & 0 deletions java/server/src/org/openqa/selenium/grid/node/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/data:data",
],
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/server:server",
"//java/server/src/org/openqa/selenium/grid/sessionmap:sessionmap",
"//java/server/src/org/openqa/selenium/grid/web:web",
Expand Down
1 change: 1 addition & 0 deletions java/server/src/org/openqa/selenium/grid/node/httpd/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ java_library(
'com.google.auto.service.processor.AutoServiceProcessor',
],
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/cli:cli",
"//java/server/src/org/openqa/selenium/concurrent:concurrent",
"//java/server/src/org/openqa/selenium/grid/config:config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,18 @@ public Executable configure(String... args) {
new EnvConfig(),
new ConcatenatingConfig("node", '.', System.getProperties()));

DistributedTracer tracer = DistributedTracer.builder()
.registerDetectedTracers()
.build();
DistributedTracer.setInstance(tracer);

SessionMapOptions sessionsOptions = new SessionMapOptions(config);
URL sessionMapUrl = sessionsOptions.getSessionMapUri().toURL();
SessionMap sessions = new RemoteSessionMap(
HttpClient.Factory.createDefault().createClient(sessionMapUrl));

BaseServerOptions serverOptions = new BaseServerOptions(config);

DistributedTracer tracer = DistributedTracer.builder()
.registerDetectedTracers()
.build();

LocalNode.Builder builder = LocalNode.builder(
tracer,
serverOptions.getExternalUri(),
Expand All @@ -125,7 +126,7 @@ public Executable configure(String... args) {
tracer,
HttpClient.Factory.createDefault().createClient(distributorUrl));

Server<?> server = new BaseServer<>(tracer, serverOptions);
Server<?> server = new BaseServer<>(serverOptions);
server.addRoute(Routes.matching(node).using(node).decorateWith(W3CCommandHandler.class));
server.start();

Expand Down
3 changes: 2 additions & 1 deletion java/server/src/org/openqa/selenium/grid/node/local/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ java_library(
name = "local",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/node:node",
"//java/server/src/org/openqa/selenium/grid/sessionmap:sessionmap",
Expand All @@ -14,4 +15,4 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/...",
"//java/server/test/org/openqa/selenium/grid/...",
],
)
)
3 changes: 2 additions & 1 deletion java/server/src/org/openqa/selenium/grid/node/remote/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ java_library(
name = "remote",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/data:data",
"//java/server/src/org/openqa/selenium/grid/node:node",
"//java/server/src/org/openqa/selenium/grid/web:web",
Expand All @@ -12,4 +13,4 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/...",
"//java/server/test/org/openqa/selenium/grid/...",
],
)
)
3 changes: 2 additions & 1 deletion java/server/src/org/openqa/selenium/grid/router/httpd/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ java_library(
'com.google.auto.service.processor.AutoServiceProcessor',
],
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/cli:cli",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/distributor:distributor",
Expand All @@ -29,4 +30,4 @@ java_library(
visibility = [
"//java/server/src/org/openqa/selenium/grid:"
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public Executable configure(String... args) {
DistributedTracer tracer = DistributedTracer.builder()
.registerDetectedTracers()
.build();
DistributedTracer.setInstance(tracer);

SessionMapOptions sessionsOptions = new SessionMapOptions(config);
URL sessionMapUrl = sessionsOptions.getSessionMapUri().toURL();
Expand All @@ -114,7 +115,7 @@ public Executable configure(String... args) {

Router router = new Router(sessions, distributor);

Server<?> server = new BaseServer<>(tracer, serverOptions);
Server<?> server = new BaseServer<>(serverOptions);
server.addRoute(Routes.matching(router).using(router).decorateWith(W3CCommandHandler.class));
server.start();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.tracing.DistributedTracer;
import org.seleniumhq.jetty9.security.ConstraintMapping;
import org.seleniumhq.jetty9.security.ConstraintSecurityHandler;
import org.seleniumhq.jetty9.server.Connector;
Expand Down Expand Up @@ -71,10 +70,8 @@ public class BaseServer<T extends BaseServer> implements Server<T> {
private final ServletContextHandler servletContextHandler;
private final Injector injector;
private final URL url;
private final DistributedTracer tracer;

public BaseServer(DistributedTracer tracer, BaseServerOptions options) {
this.tracer = Objects.requireNonNull(tracer);
public BaseServer(BaseServerOptions options) {
int port = options.getPort() == 0 ? PortProber.findFreePort() : options.getPort();

String host = options.getHostname().orElseGet(() -> {
Expand Down Expand Up @@ -200,7 +197,7 @@ public T start() {
.decorateWith(W3CCommandHandler.class)
.build();

addServlet(new CommandHandlerServlet(tracer, routes), "/*");
addServlet(new CommandHandlerServlet(routes), "/*");

server.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.tracing.DistributedTracer;
import org.openqa.selenium.remote.tracing.HttpTracing;
import org.openqa.selenium.remote.tracing.Span;

import java.io.IOException;
import java.util.Objects;
Expand All @@ -42,10 +39,8 @@ class CommandHandlerServlet extends HttpServlet {

private final Routes routes;
private final Injector injector;
private final DistributedTracer tracer;

public CommandHandlerServlet(DistributedTracer tracer, Routes routes) {
this.tracer = Objects.requireNonNull(tracer);
public CommandHandlerServlet(Routes routes) {
Objects.requireNonNull(routes);
this.routes = combine(routes)
.fallbackTo(
Expand All @@ -62,15 +57,11 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
HttpRequest request = new ServletRequestWrappingHttpRequest(req);
HttpResponse response = new ServletResponseWrappingHttpResponse(resp);

// log(String.format("(%s) %s", request.getMethod(), request.getUri()));

try (Span span = HttpTracing.extract(tracer, "selenium.httpservlet", request)) {
Optional<CommandHandler> possibleMatch = routes.match(injector, request);
if (possibleMatch.isPresent()) {
possibleMatch.get().execute(request, response);
} else {
throw new IllegalStateException("It should not be possible to get here");
}
Optional<CommandHandler> possibleMatch = routes.match(injector, request);
if (possibleMatch.isPresent()) {
possibleMatch.get().execute(request, response);
} else {
throw new IllegalStateException("It should not be possible to get here");
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions java/server/src/org/openqa/selenium/grid/sessionmap/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ java_library(
name = "sessionmap",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
# "//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/data:data",
"//java/server/src/org/openqa/selenium/grid/web:web",
Expand All @@ -14,4 +15,4 @@ java_library(
"//java/server/src/org/openqa/selenium/grid/...",
"//java/server/test/org/openqa/selenium/grid/...",
]
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ java_library(
name = "httpd",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote/tracing:tracing",
"//java/server/src/org/openqa/selenium/cli:cli",
"//java/server/src/org/openqa/selenium/grid/config:config",
"//java/server/src/org/openqa/selenium/grid/server:server",
Expand All @@ -25,4 +26,4 @@ java_library(
visibility = [
"//java/server/src/org/openqa/selenium/grid:"
],
)
)

0 comments on commit 7312f98

Please sign in to comment.