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

Changed TraceConfigz zPage form to use POST request #1521

Merged
merged 36 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ec31e3e
Removed URLEncoder
williamhu99 Jul 17, 2020
e0fe0ed
Fixed typo
williamhu99 Jul 18, 2020
cf7f5c8
Added URLDecoding
williamhu99 Jul 20, 2020
9db8e7e
Included comment for string replacement
williamhu99 Jul 20, 2020
4127978
Added unit tests for special characters in span names
williamhu99 Jul 20, 2020
e17c337
Resolved URL decoding issues
williamhu99 Jul 21, 2020
bb58b26
Moved url decoding to parseQueryMap and updated the corresponding uni…
williamhu99 Jul 21, 2020
80a5ccf
Added a README file for zPage quickstart
williamhu99 Jul 22, 2020
dcbd9aa
Add images for README
williamhu99 Jul 22, 2020
24ffce2
Updated README
williamhu99 Jul 22, 2020
5047849
Add frontend images
williamhu99 Jul 22, 2020
85a539e
Add backend images
williamhu99 Jul 22, 2020
4156123
Added our design doc
williamhu99 Jul 22, 2020
265cf27
Added details on package
wty27 Jul 23, 2020
c102e45
Reworded a few lines
williamhu99 Jul 23, 2020
e977dcf
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
williamhu99 Jul 23, 2020
ed8ef33
Moved DESIGN.md to a docs folder and changed gradle config to impleme…
williamhu99 Jul 24, 2020
f595909
Changed wording regarding HttpServer requirement
wty27 Jul 27, 2020
806b632
Added zpages folder under docs, resolved broken image links
wty27 Jul 27, 2020
9e4dde8
Resolved comments for the design md file
williamhu99 Jul 27, 2020
86c2a51
Made a few wording changes
williamhu99 Jul 27, 2020
a3c9a5a
Wrote a benchmark test for TracezSpanBuckets (#23)
williamhu99 Jul 29, 2020
07b2fcf
Updated README file (#25)
wty27 Aug 4, 2020
542f756
Wrote benchmark tests for TracezDataAggregator (#24)
williamhu99 Aug 4, 2020
fe056e3
Merged with original repo
williamhu99 Aug 4, 2020
f714b43
Added Javadocs to the TracezDataAggregator benchmark tests
williamhu99 Aug 5, 2020
922e950
Removed benchmark results from README and added a param to the Tracez…
williamhu99 Aug 5, 2020
13d82c4
Update sdk_extensions/zpages/src/jmh/java/io/opentelemetry/sdk/extens…
williamhu99 Aug 6, 2020
5ab6f6a
Added multiple param values for TracezDataAggregatorBenchmark
williamhu99 Aug 6, 2020
18a4141
Merge branch 'master' of github.com:williamhu99/opentelemetry-java in…
williamhu99 Aug 6, 2020
0ad0ebe
Merged with OpenTelemetry repo for latest updates
wty27 Aug 7, 2020
48138f7
Changed TraceConfigz zPage form submit to use POST request
wty27 Aug 7, 2020
1eb5332
Added requestMethod parameter to emitHtml, limited TraceConfig change…
wty27 Aug 7, 2020
0f09288
Removed duplicate parse function, added test for update on POST reque…
wty27 Aug 10, 2020
8044ba1
Added separate method for processing request
wty27 Aug 11, 2020
95ff5b7
Removed unnecessary error check in tests, used try resources for inpu…
wty27 Aug 11, 2020
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
4 changes: 0 additions & 4 deletions sdk_extensions/zpages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ dependencies {

compileOnly 'com.sun.net.httpserver:http:20070405'

annotationProcessor libraries.auto_value

testAnnotationProcessor libraries.auto_value

signature "org.codehaus.mojo.signature:java17:1.0@signature"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ private void emitHtmlBody(PrintStream out) {
+ ZPageLogo.getLogoBase64()
+ "\" /></a>");
out.print("<h1>Trace Configuration</h1>");
out.print("<form class=\"form-flex\" action=\"" + TRACE_CONFIGZ_URL + "\" method=\"get\">");
out.print("<form class=\"form-flex\" action=\"" + TRACE_CONFIGZ_URL + "\" method=\"post\">");
out.print(
"<input type=\"hidden\" name=\"action\" value=\"" + QUERY_STRING_ACTION_CHANGE + "\" />");
emitChangeTable(out);
// Button for submit
out.print("<button class=\"button\" type=\"submit\" value=\"Submit\">Submit</button>");
out.print("</form>");
// Button for restore default
out.print("<form class=\"form-flex\" action=\"" + TRACE_CONFIGZ_URL + "\" method=\"get\">");
out.print("<form class=\"form-flex\" action=\"" + TRACE_CONFIGZ_URL + "\" method=\"post\">");
out.print(
"<input type=\"hidden\" name=\"action\" value=\"" + QUERY_STRING_ACTION_DEFAULT + "\" />");
out.print("<button class=\"button\" type=\"submit\" value=\"Submit\">Restore Default</button>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.google.common.collect.ImmutableMap;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
Expand Down Expand Up @@ -54,12 +56,38 @@ final class ZPageHttpHandler implements HttpHandler {
*/
@VisibleForTesting
static ImmutableMap<String, String> parseQueryMap(URI uri) throws UnsupportedEncodingException {
String queryStrings = uri.getRawQuery();
if (queryStrings == null) {
String queryString = uri.getRawQuery();
wangty27 marked this conversation as resolved.
Show resolved Hide resolved
if (queryString == null) {
return ImmutableMap.of();
}
Map<String, String> queryMap = new HashMap<String, String>();
for (String param : QUERY_SPLITTER.split(queryStrings)) {
for (String param : QUERY_SPLITTER.split(queryString)) {
List<String> keyValuePair = QUERY_KEYVAL_SPLITTER.splitToList(param);
if (keyValuePair.size() > 1) {
if (keyValuePair.get(0).equals(PARAM_SPAN_NAME)) {
queryMap.put(keyValuePair.get(0), URLDecoder.decode(keyValuePair.get(1), "UTF-8"));
} else {
queryMap.put(keyValuePair.get(0), keyValuePair.get(1));
}
}
}
return ImmutableMap.copyOf(queryMap);
}

/**
* Build a query map from the query string.
*
* @param queryString the query string for buiding the query map
* @return the query map built based on the query string
*/
@VisibleForTesting
static ImmutableMap<String, String> parseQueryMap(String queryString)
wangty27 marked this conversation as resolved.
Show resolved Hide resolved
throws UnsupportedEncodingException {
if (queryString == null) {
return ImmutableMap.of();
}
Map<String, String> queryMap = new HashMap<String, String>();
for (String param : QUERY_SPLITTER.split(queryString)) {
List<String> keyValuePair = QUERY_KEYVAL_SPLITTER.splitToList(param);
if (keyValuePair.size() > 1) {
if (keyValuePair.get(0).equals(PARAM_SPAN_NAME)) {
Expand All @@ -75,9 +103,17 @@ static ImmutableMap<String, String> parseQueryMap(URI uri) throws UnsupportedEnc
@Override
public final void handle(HttpExchange httpExchange) throws IOException {
try {
String requestMethod = httpExchange.getRequestMethod();
httpExchange.sendResponseHeaders(200, 0);
zpageHandler.emitHtml(
parseQueryMap(httpExchange.getRequestURI()), httpExchange.getResponseBody());
if (requestMethod.equalsIgnoreCase("get")) {
zpageHandler.emitHtml(
wangty27 marked this conversation as resolved.
Show resolved Hide resolved
parseQueryMap(httpExchange.getRequestURI()), httpExchange.getResponseBody());
} else if (requestMethod.equalsIgnoreCase("post")) {
BufferedReader requestBodyReader =
new BufferedReader(new InputStreamReader(httpExchange.getRequestBody(), "utf-8"));
String queryString = requestBodyReader.readLine();
wangty27 marked this conversation as resolved.
Show resolved Hide resolved
zpageHandler.emitHtml(parseQueryMap(queryString), httpExchange.getResponseBody());
}
} finally {
httpExchange.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ public final class ZPageHttpHandlerTest {
@Test
void parseEmptyQuery() throws URISyntaxException, UnsupportedEncodingException {
URI uri = new URI("http://localhost:8000/tracez");
String queryString = "";
assertThat(ZPageHttpHandler.parseQueryMap(uri)).isEmpty();
assertThat(ZPageHttpHandler.parseQueryMap(queryString)).isEmpty();
}

@Test
void parseNormalQuery() throws URISyntaxException, UnsupportedEncodingException {
URI uri =
new URI("http://localhost:8000/tracez/tracez?zspanname=Test&ztype=1&zsubtype=5&noval");
String queryString = "zspanname=Test&ztype=1&zsubtype=5&noval";
assertThat(ZPageHttpHandler.parseQueryMap(uri))
wangty27 marked this conversation as resolved.
Show resolved Hide resolved
.containsOnly(entry("zspanname", "Test"), entry("ztype", "1"), entry("zsubtype", "5"));
assertThat(ZPageHttpHandler.parseQueryMap(queryString))
.containsOnly(entry("zspanname", "Test"), entry("ztype", "1"), entry("zsubtype", "5"));
}
}