forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "information" command and information about tracing
- Loading branch information
Showing
6 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
java/server/src/org/openqa/selenium/grid/commands/InfoCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.grid.commands; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import com.beust.jcommander.ParameterException; | ||
import com.google.auto.service.AutoService; | ||
import com.google.common.io.Resources; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.nio.charset.StandardCharsets; | ||
import org.openqa.selenium.cli.CliCommand; | ||
import org.openqa.selenium.cli.WrappedPrintWriter; | ||
import org.openqa.selenium.grid.server.HelpFlags; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.Collections; | ||
|
||
|
||
@AutoService(CliCommand.class) | ||
public class InfoCommand implements CliCommand { | ||
|
||
public String getName() { | ||
return "info"; | ||
} | ||
|
||
public String getDescription() { | ||
return "Prints information for commands and topics."; | ||
} | ||
|
||
public Executable configure(String... args) { | ||
HelpFlags help = new HelpFlags(); | ||
InfoFlags topic = new InfoFlags(); | ||
|
||
JCommander commander = JCommander.newBuilder() | ||
.programName("selenium") | ||
.addObject(help) | ||
.addObject(topic) | ||
.build(); | ||
|
||
return () -> { | ||
try { | ||
commander.parse(args); | ||
} catch (ParameterException e) { | ||
System.err.println(e.getMessage()); | ||
commander.usage(); | ||
return; | ||
} | ||
|
||
if (help.displayHelp(commander, System.out)) { | ||
return; | ||
} | ||
|
||
String toDisplay; | ||
String title; | ||
switch (topic.topic) { | ||
case "tracing": | ||
title = "About Tracing"; | ||
toDisplay = "tracing.txt"; | ||
break; | ||
|
||
case "help": | ||
default: | ||
title = "Help"; | ||
toDisplay = "help.txt"; | ||
break; | ||
} | ||
|
||
String path = getClass().getPackage().getName().replaceAll("\\.", "/") + "/" + toDisplay; | ||
String content = readContent(path); | ||
|
||
PrintWriter out = new WrappedPrintWriter(System.out, 72, 0); | ||
|
||
out.printf("\n%s\n%s\n\n", title, String.join("", Collections.nCopies(title.length(), "="))); | ||
out.print(content); | ||
out.println("\n\n"); | ||
}; | ||
} | ||
|
||
private String readContent(String path) throws IOException { | ||
String unformattedText = Resources.toString(Resources.getResource(path), StandardCharsets.UTF_8); | ||
StringBuilder formattedText = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new StringReader(unformattedText))) { | ||
boolean inCode = false; | ||
|
||
for (String line = reader.readLine(); line != null; line = reader.readLine()) { | ||
if (line.isEmpty()) { | ||
if (inCode) { | ||
formattedText.append("\n"); | ||
} else { | ||
formattedText.append("\n\n"); | ||
} | ||
} else if ("```".equals(line)) { | ||
inCode = !inCode; | ||
} else { | ||
formattedText.append(line); | ||
if (inCode || line.startsWith("* ")) { | ||
formattedText.append("\n"); | ||
} else { | ||
formattedText.append(" "); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return formattedText.toString(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
java/server/src/org/openqa/selenium/grid/commands/InfoFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.grid.commands; | ||
|
||
import com.beust.jcommander.Parameter; | ||
|
||
public class InfoFlags { | ||
|
||
@Parameter(description = "Topic to gather additional help on") | ||
String topic = "help"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
You can find out more about topics concerning Selenium Grid by running | ||
the "help" command followed by: | ||
|
||
* tracing - Help on how distributed tracing works with selenium | ||
|
||
Each topic will give you enough information to help you get started, and | ||
contains some pointers on our site to provide more complete information. |
68 changes: 68 additions & 0 deletions
68
java/server/src/org/openqa/selenium/grid/commands/tracing.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Selenium Grid ships with support for distributed tracing, backed by | ||
the OpenTracing APIs. This allows admins and devops engineers to trace | ||
the flow of control through the Grid for each and every command. | ||
|
||
To enable this support, you must first provide a "Tracer" | ||
implementation that should be used. We use OpenTracing's own | ||
TracerResolver to find the Tracer to use, so if your chosen tracing | ||
library supports this mechanism to (and most do!) you should be good | ||
to go. If you are using the standalone selenium jar, updating the | ||
classpath to contain your tracer can be done using the `--ext` flag to | ||
selenium. As a worked example, using Jaeger as the tracing library and | ||
running on macOS or Linux: | ||
|
||
``` | ||
java -jar selenium.jar \ | ||
--ext $(coursier fetch -p io.jaegertracing:jaeger-client:1.0.0) \ | ||
standalone | ||
``` | ||
|
||
This example uses a tool called "coursier" to generate a full | ||
classpath, but you can also write this manually. When started this | ||
way, the selenium server will inform you that it has found a tracer on | ||
stdout. | ||
|
||
However, just making the tracer available is seldom enough. You must | ||
also configure it to send diagnostics back. In the case of Jaeger, | ||
this can be done via system properties. Modifying our example: | ||
|
||
``` | ||
java -DJAEGER_SERVICE_NAME="selenium-standalone" \ | ||
-DJAEGER_AGENT_HOST=localhost \ | ||
-DJAEGER_AGENT_PORT=6831 \ | ||
-DJAEGER_SAMPLER_TYPE=const \ | ||
-DJAEGER_SAMPLER_PARAM=1 \ | ||
-jar selenium.jar \ | ||
--ext $(coursier fetch -p io.jaegertracing:jaeger-client:1.0.0) \ | ||
standalone | ||
``` | ||
|
||
There are other popular tracing libraries that are supported by | ||
OpenTracing, so please check their documentation for more information | ||
on how to configure them. | ||
|
||
You will also need to be running a tracing server somewhere. In the | ||
case of Jaeger, you can do this using docker to fire up something | ||
locally: | ||
|
||
``` | ||
docker run --rm -it -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \ | ||
-p 5775:5775/udp \ | ||
-p 6831:6831/udp \ | ||
-p 6832:6832/udp \ | ||
-p 5778:5778 \ | ||
-p 16686:16686 \ | ||
-p 14268:14268 \ | ||
-p 9411:9411 \ | ||
jaegertracing/all-in-one:1.14 | ||
``` | ||
|
||
Now run some tests, and then point a browser at | ||
http://localhost:16686/ to view the outputs. | ||
|
||
More information can be found at: | ||
|
||
* OpenTracing: https://opentracing.io | ||
* TracerResolver: https://github.com/opentracing-contrib/java-tracerresolver | ||
* Jaeger: https://www.jaegertracing.io | ||
* Coursier: https://get-coursier.io |