Skip to content

Commit

Permalink
Bugfix rntbd diagnostics to include rntbd timeline on the failure (Az…
Browse files Browse the repository at this point in the history
…ure#15574)

* fixes diagnostics to include rntbd timeline on the failure

* added a test
  • Loading branch information
moderakh authored Sep 24, 2020
1 parent e1dc876 commit c2d7dfc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public static void setQueryPlanDiagnosticsContext(CosmosDiagnostics cosmosDiagno
cosmosDiagnostics.getFeedResponseDiagnostics().setDiagnosticsContext(diagnosticsContext);
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static <E extends CosmosException> E setRequestTimeline(E e, RequestTimeline requestTimeline) {
e.setRequestTimeline(requestTimeline);
return e;
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static <E extends CosmosException> RequestTimeline getRequestTimeline(E e) {
return e.getRequestTimeline();
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static <E extends CosmosException> E setResourceAddress(E e, String resourceAddress) {
e.setResourceAddress(resourceAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class CosmosException extends AzureException {
private final Map<String, String> responseHeaders;

private CosmosDiagnostics cosmosDiagnostics;
private final RequestTimeline requestTimeline;
private RequestTimeline requestTimeline;
private CosmosError cosmosError;

long lsn;
Expand All @@ -56,7 +56,6 @@ public class CosmosException extends AzureException {
protected CosmosException(int statusCode, String message, Map<String, String> responseHeaders, Throwable cause) {
super(message, cause);
this.statusCode = statusCode;
this.requestTimeline = RequestTimeline.empty();
this.responseHeaders = responseHeaders == null ? new HashMap<>() : new HashMap<>(responseHeaders);
}

Expand Down Expand Up @@ -302,4 +301,12 @@ private List<Map.Entry<String, String>> filterSensitiveData(Map<String, String>
void setResourceAddress(String resourceAddress) {
this.resourceAddress = resourceAddress;
}

RequestTimeline getRequestTimeline() {
return this.requestTimeline;
}

void setRequestTimeline(RequestTimeline requestTimeline) {
this.requestTimeline = requestTimeline;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ public Mono<StoreResponse> invokeStoreAsync(final Uri addressUri, final RxDocume
address.toString());
}

return error;
assert error instanceof CosmosException;
CosmosException cosmosException = (CosmosException) error;
BridgeInternal.setRequestTimeline(cosmosException, record.takeTimelineSnapshot());

return cosmosException;

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public void serialize(StoreResult storeResult,
jsonGenerator.writeNumberField("itemLSN", storeResult.itemLSN);
jsonGenerator.writeStringField("sessionToken", (storeResult.sessionToken != null ? storeResult.sessionToken.convertToString() : null));
jsonGenerator.writeStringField("exception", BridgeInternal.getInnerErrorMessage(storeResult.exception));
jsonGenerator.writeObjectField("transportRequestTimeline", storeResult.storeResponse != null ? storeResult.storeResponse.getRequestTimeline() : null);
jsonGenerator.writeObjectField("transportRequestTimeline", storeResult.storeResponse != null ?
storeResult.storeResponse.getRequestTimeline() :
storeResult.exception != null ? BridgeInternal.getRequestTimeline(storeResult.exception) : null);
jsonGenerator.writeEndObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ public void directDiagnostics() {
assertThat(createResponse.getDiagnostics().getDuration()).isNotNull();
validateTransportRequestTimelineDirect(diagnostics);
validateJson(diagnostics);

// validate that on failed operation request timeline is populated
try {
cosmosContainer.createItem(internalObjectNode);
fail("expected 409");
} catch (CosmosException e) {
validateTransportRequestTimelineDirect(e.getDiagnostics().toString());
}
} finally {
if (testDirectClient != null) {
testDirectClient.close();
Expand Down Expand Up @@ -489,6 +497,9 @@ public void serializationOnVariousScenarios() {
assertThat(diagnostics).contains("\"userAgent\":\"" + Utils.getUserAgent() + "\"");
}




@Test(groups = {"emulator"}, timeOut = TIMEOUT)
public void addressResolutionStatistics() {
CosmosClient client1 = null;
Expand Down

0 comments on commit c2d7dfc

Please sign in to comment.