Skip to content

Commit

Permalink
Allow null uri attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jklukas committed Aug 13, 2019
1 parent dd09b4f commit f8bff29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ private static class UnexpectedPathElementsException extends InvalidUriException
}
}

private static class NullUriException extends InvalidUriException {
}

private ParseUri() {
}

Expand Down Expand Up @@ -94,7 +91,10 @@ protected PubsubMessage processElement(PubsubMessage message) throws InvalidUriE
// parse uri based on prefix
final String uri = attributes.get("uri");
if (uri == null) {
throw new NullUriException();
// We should only have a missing uri attribute if we're replaying messages from decoded
// payloads in which case they already have parsed URI attributes encoded in the payload
// and these will be recovered in ParsePayload.
return message;
} else if (uri.startsWith(TELEMETRY_URI_PREFIX)) {
// We don't yet have access to the version field, so we delay populating the document_version
// attribute until the ParsePayload step where we have map-like access to the JSON content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ParseUriTest extends TestWithDeterministicJson {
@Test
public void testOutput() {
final List<String> validInput = Arrays.asList(//
"{\"attributeMap\":{},\"payload\":\"\"}", //
"{\"attributeMap\":" //
+ "{\"uri\":\"/submit/telemetry/ce39b608-f595-4c69-b6a6-f7a436604648"
+ "/main/Firefox/61.0a1/nightly/20180328030202\"" //
Expand All @@ -50,7 +51,6 @@ public void testOutput() {
+ "},\"payload\":\"\"}");

final List<String> invalidInput = Arrays.asList(//
"{\"attributeMap\":{},\"payload\":\"\"}", //
"{\"attributeMap\":" //
+ "{\"uri\":\"/nonexistent_prefix/ce39b608-f595-4c69-b6a6-f7a436604648" //
+ "/main/Firefox/61.0a1/nightly/20180328030202\"" //
Expand All @@ -64,6 +64,7 @@ public void testOutput() {
+ "},\"payload\":\"\"}");

final List<String> expected = Arrays.asList(//
"{\"attributeMap\":{},\"payload\":\"\"}", //
"{\"attributeMap\":" //
+ "{\"app_build_id\":\"20180328030202\"" //
+ ",\"app_name\":\"Firefox\"" //
Expand Down Expand Up @@ -95,9 +96,8 @@ public void testOutput() {
PCollection<String> exceptions = parsed.errors() //
.apply(MapElements.into(TypeDescriptors.strings())
.via(message -> message.getAttribute("exception_class")));
PAssert.that(exceptions)
.containsInAnyOrder(Arrays.asList("com.mozilla.telemetry.decoder.ParseUri$NullUriException",
"com.mozilla.telemetry.decoder.ParseUri$InvalidUriException",
PAssert.that(exceptions).containsInAnyOrder(
Arrays.asList("com.mozilla.telemetry.decoder.ParseUri$InvalidUriException",
"com.mozilla.telemetry.decoder.ParseUri$UnexpectedPathElementsException",
"com.mozilla.telemetry.decoder.ParseUri$UnexpectedPathElementsException"));

Expand Down

0 comments on commit f8bff29

Please sign in to comment.