diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java index aa42509556926..0713550229ab0 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/BridgeInternal.java @@ -387,14 +387,8 @@ public static CosmosException createCosmosException(int statusCode, String error } @Warning(value = INTERNAL_USE_ONLY_WARNING) - public static CosmosException createCosmosException(int statusCode, Exception innerException) { - return new CosmosException(statusCode, null, null, innerException); - } - - @Warning(value = INTERNAL_USE_ONLY_WARNING) - public static CosmosException createCosmosException(int statusCode, CosmosError cosmosErrorResource, - Map responseHeaders) { - return new CosmosException(/* resourceAddress */ null, statusCode, cosmosErrorResource, responseHeaders); + public static CosmosException createCosmosException(String resourceAddress, int statusCode, Exception innerException) { + return new CosmosException(resourceAddress, statusCode, null, null, innerException); } @Warning(value = INTERNAL_USE_ONLY_WARNING) diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosDiagnostics.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosDiagnostics.java index 58359931e97a1..8b02badf8c0dd 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosDiagnostics.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosDiagnostics.java @@ -10,7 +10,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.URI; import java.time.Duration; +import java.util.Set; /** * This class represents response diagnostic statistics associated with a request to Azure Cosmos DB @@ -77,6 +79,14 @@ public Duration getDuration() { return this.clientSideRequestStatistics.getDuration(); } + /** + * Regions contacted for this request + * @return set of regions contacted for this request + */ + public Set getRegionsContacted() { + return this.clientSideRequestStatistics.getRegionsContacted(); + } + FeedResponseDiagnostics getFeedResponseDiagnostics() { return feedResponseDiagnostics; } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosException.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosException.java index a3b5a2719495b..9cc1063d5527b 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosException.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/CosmosException.java @@ -284,7 +284,7 @@ CosmosException setDiagnostics(CosmosDiagnostics cosmosDiagnostics) { @Override public String toString() { return getClass().getSimpleName() + "{" + "userAgent=" + USER_AGENT + ", error=" + cosmosError + ", resourceAddress='" - + resourceAddress + "', requestUri='" + (requestUri != null ? requestUri.getURIAsString() : null) + "', statusCode=" + statusCode + ", message=" + getMessage() + + resourceAddress + ", statusCode=" + statusCode + ", message=" + getMessage() + ", causeInfo=" + causeInfo() + ", responseHeaders=" + responseHeaders + ", requestHeaders=" + filterSensitiveData(requestHeaders) + '}'; } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java index 40f82f908f28b..6321f3f6490cb 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DocumentServiceRequestContext.java @@ -37,6 +37,7 @@ public class DocumentServiceRequestContext implements Cloneable { public volatile StoreResult quorumSelectedStoreResponse; public volatile PartitionKeyInternal effectivePartitionKey; public volatile CosmosDiagnostics cosmosDiagnostics; + public volatile String resourcePhysicalAddress; public RetryContext retryContext; public DocumentServiceRequestContext() { @@ -145,6 +146,7 @@ public DocumentServiceRequestContext clone() { context.effectivePartitionKey = this.effectivePartitionKey; context.performedBackgroundAddressRefresh = this.performedBackgroundAddressRefresh; context.cosmosDiagnostics = this.cosmosDiagnostics; + context.resourcePhysicalAddress = this.resourcePhysicalAddress; context.retryContext = new RetryContext(this.retryContext); return context; diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java index 4b71de72f361f..58151c5593bec 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxGatewayStoreModel.java @@ -147,6 +147,7 @@ public Mono performRequest(RxDocumentServiceRequest r } URI uri = getUri(request); + request.requestContext.resourcePhysicalAddress = uri.toString(); HttpHeaders httpHeaders = this.getHttpRequestHeaders(request.getHeaders()); @@ -300,7 +301,7 @@ private Mono toDocumentServiceResponse(Mono> tryResolveServerPartitionAsync request.getResourceType(), request.getOperationType(), request.getResourceAddress()); - return Mono.error(BridgeInternal.setResourceAddress(new InternalServerErrorException(RMResources.InternalServerError), request.getResourceAddress())); + return Mono.error(BridgeInternal.setResourceAddress(new InternalServerErrorException(RMResources.InternalServerError), request.requestContext.resourcePhysicalAddress)); } PartitionKeyRange range; @@ -293,7 +293,7 @@ private PartitionKeyRange tryResolveSinglePartitionCollection( logger.debug("tryResolveSinglePartitionCollection: collectionCacheIsUptoDate = {}", collectionCacheIsUptoDate); if (collectionCacheIsUptoDate) { - throw BridgeInternal.setResourceAddress(new BadRequestException(RMResources.MissingPartitionKeyValue), request.getResourceAddress()); + throw BridgeInternal.setResourceAddress(new BadRequestException(RMResources.MissingPartitionKeyValue), request.requestContext.resourcePhysicalAddress); } else { return null; } @@ -314,7 +314,7 @@ private Mono resolveMasterResourceAddress(RxDocumentServiceReq // return Observable.getError() NotFoundException e = new NotFoundException(); - BridgeInternal.setResourceAddress(e, request.getResourceAddress()); + BridgeInternal.setResourceAddress(e, request.requestContext.resourcePhysicalAddress); return Mono.error(e); } @@ -507,7 +507,7 @@ private Mono resolveAddressesAndIdentityAsync( // The only reason we will get here is if collection doesn't exist. // Case when partition-key-range doesn't exist is handled in the corresponding method. - return Mono.error(BridgeInternal.setResourceAddress(new NotFoundException(), request.getResourceAddress())); + return Mono.error(BridgeInternal.setResourceAddress(new NotFoundException(), request.requestContext.resourcePhysicalAddress)); } return Mono.just(funcResolutionResult.v); @@ -568,7 +568,7 @@ private ResolutionResult handleRangeAddressResolutionFailure( RMResources.PartitionKeyRangeNotFound, request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId(), request.getPartitionKeyRangeIdentity().getCollectionRid()); - throw BridgeInternal.setResourceAddress(new PartitionKeyRangeGoneException(errorMessage), request.getResourceAddress()); + throw BridgeInternal.setResourceAddress(new PartitionKeyRangeGoneException(errorMessage), request.requestContext.resourcePhysicalAddress); } logger.debug("handleRangeAddressResolutionFailure returns null"); return null; @@ -649,7 +649,7 @@ private PartitionKeyRange tryResolveServerPartitionByPartitionKey( } catch (Exception ex) { throw BridgeInternal.setResourceAddress(new BadRequestException( String.format(RMResources.InvalidPartitionKey, partitionKeyString), - ex), request.getResourceAddress()); + ex), request.requestContext.resourcePhysicalAddress); } } } @@ -670,7 +670,8 @@ private PartitionKeyRange tryResolveServerPartitionByPartitionKey( } if (collectionCacheUptoDate) { - BadRequestException badRequestException = BridgeInternal.setResourceAddress(new BadRequestException(RMResources.PartitionKeyMismatch), request.getResourceAddress()); + BadRequestException badRequestException = BridgeInternal.setResourceAddress(new BadRequestException(RMResources.PartitionKeyMismatch), + request.requestContext.resourcePhysicalAddress); badRequestException.getResponseHeaders().put(WFConstants.BackendHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH)); throw badRequestException; diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/GatewayAddressCache.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/GatewayAddressCache.java index 84e7f956de914..99573d502ab6b 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/GatewayAddressCache.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/GatewayAddressCache.java @@ -354,7 +354,7 @@ public Mono> getServerAddressesViaGatewayAsync( Duration.ofSeconds(Configs.getAddressRefreshResponseTimeoutInSeconds()))); } - Mono dsrObs = HttpClientUtils.parseResponseAsync(clientContext, httpResponseMono, httpRequest); + Mono dsrObs = HttpClientUtils.parseResponseAsync(request, clientContext, httpResponseMono, httpRequest); return dsrObs.map( dsr -> { MetadataDiagnosticsContext metadataDiagnosticsContext = @@ -386,7 +386,7 @@ public Mono> getServerAddressesViaGatewayAsync( if (!(exception instanceof CosmosException)) { // wrap in CosmosException logger.error("Network failure", exception); - dce = BridgeInternal.createCosmosException(0, exception); + dce = BridgeInternal.createCosmosException(request.requestContext.resourcePhysicalAddress, 0, exception); BridgeInternal.setRequestHeaders(dce, request.getHeaders()); } else { dce = (CosmosException) exception; @@ -588,7 +588,7 @@ public Mono> getMasterAddressesViaGatewayAsync( Duration.ofSeconds(Configs.getAddressRefreshResponseTimeoutInSeconds()))); } - Mono dsrObs = HttpClientUtils.parseResponseAsync(this.clientContext, httpResponseMono, httpRequest); + Mono dsrObs = HttpClientUtils.parseResponseAsync(request, this.clientContext, httpResponseMono, httpRequest); return dsrObs.map( dsr -> { @@ -618,7 +618,7 @@ public Mono> getMasterAddressesViaGatewayAsync( if (!(exception instanceof CosmosException)) { // wrap in CosmosException logger.error("Network failure", exception); - dce = BridgeInternal.createCosmosException(0, exception); + dce = BridgeInternal.createCosmosException(request.requestContext.resourcePhysicalAddress, 0, exception); BridgeInternal.setRequestHeaders(dce, request.getHeaders()); } else { dce = (CosmosException) exception; diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpClientUtils.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpClientUtils.java index 8efbb57db5f8d..155ac97db720c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpClientUtils.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpClientUtils.java @@ -8,6 +8,7 @@ import com.azure.cosmos.implementation.CosmosError; import com.azure.cosmos.implementation.DiagnosticsClientContext; import com.azure.cosmos.implementation.HttpConstants; +import com.azure.cosmos.implementation.RxDocumentServiceRequest; import com.azure.cosmos.implementation.RxDocumentServiceResponse; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.azure.cosmos.implementation.http.HttpRequest; @@ -16,7 +17,10 @@ public class HttpClientUtils { - static Mono parseResponseAsync(DiagnosticsClientContext diagnosticsClientContext, Mono httpResponse, HttpRequest httpRequest) { + static Mono parseResponseAsync(RxDocumentServiceRequest request, + DiagnosticsClientContext diagnosticsClientContext, + Mono httpResponse, + HttpRequest httpRequest) { return httpResponse.flatMap(response -> { if (response.statusCode() < HttpConstants.StatusCodes.MINIMUM_STATUSCODE_AS_ERROR_GATEWAY) { @@ -27,20 +31,19 @@ static Mono parseResponseAsync(DiagnosticsClientConte } else { return HttpClientUtils - .createDocumentClientException(response).flatMap(Mono::error); + .createDocumentClientException(request, response).flatMap(Mono::error); } }); } - private static Mono createDocumentClientException(HttpResponse httpResponse) { + private static Mono createDocumentClientException(RxDocumentServiceRequest request, HttpResponse httpResponse) { Mono readStream = httpResponse.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY)); return readStream.map(body -> { CosmosError cosmosError = new CosmosError(body); - // TODO: we should set resource address in the Document Client Exception - return BridgeInternal.createCosmosException(httpResponse.statusCode(), cosmosError, - httpResponse.headers().toMap()); + return BridgeInternal.createCosmosException(request.requestContext.resourcePhysicalAddress, httpResponse.statusCode(), + cosmosError, httpResponse.headers().toMap()); }); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClient.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClient.java index 92d5bc7880863..8c769ee3515bd 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClient.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClient.java @@ -218,7 +218,7 @@ public Mono invokeStoreAsync( null); }); - return httpResponseMono.flatMap(rsp -> processHttpResponse(request.getResourceAddress(), + return httpResponseMono.flatMap(rsp -> processHttpResponse(request.requestContext.resourcePhysicalAddress, httpRequest, activityId, rsp, physicalAddress)); } catch (Exception e) { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestManager.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestManager.java index dca5f359690fa..1316b24af40da 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestManager.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/directconnectivity/rntbd/RntbdRequestManager.java @@ -759,6 +759,9 @@ private void messageReceived(final ChannelHandlerContext context, final RntbdRes // ..Create CosmosException based on status and sub-status codes + final String resourceAddress = requestRecord.args().physicalAddress() != null ? + requestRecord.args().physicalAddress().toString() : null; + switch (status.code()) { case StatusCodes.BADREQUEST: @@ -825,9 +828,6 @@ private void messageReceived(final ChannelHandlerContext context, final RntbdRes case StatusCodes.REQUEST_TIMEOUT: Exception inner = new RequestTimeoutException(error, lsn, partitionKeyRangeId, responseHeaders); - String resourceAddress = requestRecord.args().physicalAddress() != null ? - requestRecord.args().physicalAddress().toString() : null; - cause = new GoneException(resourceAddress, error, lsn, partitionKeyRangeId, responseHeaders, inner); break; @@ -848,9 +848,10 @@ private void messageReceived(final ChannelHandlerContext context, final RntbdRes break; default: - cause = BridgeInternal.createCosmosException(status.code(), error, responseHeaders); + cause = BridgeInternal.createCosmosException(resourceAddress, status.code(), error, responseHeaders); break; } + BridgeInternal.setResourceAddress(cause, resourceAddress); requestRecord.completeExceptionally(cause); } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java index c1157445deaff..b137b51eda910 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java @@ -146,6 +146,9 @@ public void gatewayDiagnostics() { assertThat(diagnostics).contains("\"serializationType\":\"PARTITION_KEY_FETCH_SERIALIZATION\""); assertThat(diagnostics).contains("\"userAgent\":\"" + Utils.getUserAgent() + "\""); assertThat(createResponse.getDiagnostics().getDuration()).isNotNull(); + assertThat(createResponse.getDiagnostics().getRegionsContacted()).isNotNull(); + // TODO: (nakumars) - Uncomment the following line after your client telemetry fix + // assertThat(createResponse.getDiagnostics().getRegionsContacted()).isNotEmpty(); validateTransportRequestTimelineGateway(diagnostics); validateJson(diagnostics); } finally { @@ -176,6 +179,10 @@ public void gatewayDiagnosticsOnException() { assertThat(diagnostics).contains("\"statusCode\":404"); assertThat(diagnostics).contains("\"operationType\":\"Read\""); assertThat(diagnostics).contains("\"userAgent\":\"" + Utils.getUserAgent() + "\""); + assertThat(diagnostics).doesNotContain(("\"resourceAddress\":null")); + assertThat(createResponse.getDiagnostics().getRegionsContacted()).isNotNull(); + // TODO: (nakumars) - Uncomment the following line after your client telemetry fix + // assertThat(createResponse.getDiagnostics().getRegionsContacted()).isNotEmpty(); assertThat(exception.getDiagnostics().getDuration()).isNotNull(); validateTransportRequestTimelineGateway(diagnostics); validateJson(diagnostics); @@ -219,6 +226,7 @@ public void directDiagnostics() { assertThat(diagnostics).contains("\"metaDataName\":\"SERVER_ADDRESS_LOOKUP\""); assertThat(diagnostics).contains("\"serializationType\":\"PARTITION_KEY_FETCH_SERIALIZATION\""); assertThat(diagnostics).contains("\"userAgent\":\"" + Utils.getUserAgent() + "\""); + assertThat(createResponse.getDiagnostics().getRegionsContacted()).isNotEmpty(); assertThat(createResponse.getDiagnostics().getDuration()).isNotNull(); validateTransportRequestTimelineDirect(diagnostics); validateJson(diagnostics); @@ -417,6 +425,8 @@ public void directDiagnosticsOnException() { String diagnostics = exception.getDiagnostics().toString(); assertThat(exception.getStatusCode()).isEqualTo(HttpConstants.StatusCodes.NOTFOUND); assertThat(diagnostics).contains("\"connectionMode\":\"DIRECT\""); + assertThat(diagnostics).doesNotContain(("\"resourceAddress\":null")); + assertThat(exception.getDiagnostics().getRegionsContacted()).isNotEmpty(); assertThat(exception.getDiagnostics().getDuration()).isNotNull(); validateJson(diagnostics); // TODO https://github.com/Azure/azure-sdk-for-java/issues/8035 diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosExceptionTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosExceptionTest.java index 0a7026dce0485..df92bffce61f3 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosExceptionTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/CosmosExceptionTest.java @@ -77,14 +77,14 @@ public void headerNotNull2() { @Test(groups = { "unit" }) public void headerNotNull3() { - CosmosException dce = BridgeInternal.createCosmosException(0, new RuntimeException()); + CosmosException dce = BridgeInternal.createCosmosException(null, 0, new RuntimeException()); assertThat(dce.getResponseHeaders()).isNotNull(); assertThat(dce.getResponseHeaders()).isEmpty(); } @Test(groups = { "unit" }) public void headerNotNull4() { - CosmosException dce = BridgeInternal.createCosmosException(0, (CosmosError) null, (Map) null); + CosmosException dce = BridgeInternal.createCosmosException(null, 0, (CosmosError) null, (Map) null); assertThat(dce.getResponseHeaders()).isNotNull(); assertThat(dce.getResponseHeaders()).isEmpty(); } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ClientRetryPolicyTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ClientRetryPolicyTest.java index 397dc88d8ee5c..04faf9151b2ef 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ClientRetryPolicyTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/ClientRetryPolicyTest.java @@ -31,7 +31,7 @@ public void networkFailureOnRead() throws Exception { ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(mockDiagnosticsClientContext(), endpointManager, true, throttlingRetryOptions); Exception exception = ReadTimeoutException.INSTANCE; - CosmosException cosmosException = BridgeInternal.createCosmosException(0, exception); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, 0, exception); BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_UNAVAILABLE); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), @@ -66,7 +66,7 @@ public void tcpNetworkFailureOnRead() throws Exception { Exception exception = ReadTimeoutException.INSTANCE; GoneException goneException = new GoneException(exception); CosmosException cosmosException = - BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, + BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), @@ -105,7 +105,7 @@ public void networkFailureOnWrite() throws Exception { ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(mockDiagnosticsClientContext(), endpointManager, true, throttlingRetryOptions); Exception exception = ReadTimeoutException.INSTANCE; - CosmosException cosmosException = BridgeInternal.createCosmosException(0, exception); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, 0, exception); BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_UNAVAILABLE); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), @@ -137,7 +137,7 @@ public void tcpNetworkFailureOnWrite() throws Exception { //Non retribale exception for write Exception exception = ReadTimeoutException.INSTANCE; GoneException goneException = new GoneException(exception); - CosmosException cosmosException = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); @@ -160,7 +160,7 @@ public void tcpNetworkFailureOnWrite() throws Exception { // Retriable exception scenario exception = new SSLHandshakeException("test"); goneException = new GoneException(exception); - cosmosException = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); + cosmosException = BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); Mockito.doReturn(true).when(endpointManager).canUseMultipleWriteLocations(Mockito.any(RxDocumentServiceRequest.class)); clientRetryPolicy = new ClientRetryPolicy(mockDiagnosticsClientContext(), endpointManager, true, retryOptions); @@ -196,7 +196,7 @@ public void networkFailureOnUpsert() throws Exception { ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(mockDiagnosticsClientContext(), endpointManager, true, throttlingRetryOptions); Exception exception = ReadTimeoutException.INSTANCE; - CosmosException cosmosException = BridgeInternal.createCosmosException(0, exception); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, 0, exception); BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_UNAVAILABLE); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), @@ -227,7 +227,7 @@ public void tcpNetworkFailureOnUpsert() throws Exception { Exception exception = ReadTimeoutException.INSTANCE; GoneException goneException = new GoneException(exception); - CosmosException cosmosException = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), OperationType.Upsert, "/dbs/db/colls/col/docs/docId", ResourceType.Document); @@ -257,7 +257,7 @@ public void networkFailureOnDelete() throws Exception { ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(mockDiagnosticsClientContext(), endpointManager, true, throttlingRetryOptions); Exception exception = ReadTimeoutException.INSTANCE; - CosmosException cosmosException = BridgeInternal.createCosmosException(0, exception); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, 0, exception); BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_UNAVAILABLE); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), @@ -288,7 +288,7 @@ public void tcpNetworkFailureOnDelete() throws Exception { Exception exception = ReadTimeoutException.INSTANCE; GoneException goneException = new GoneException(exception); - CosmosException cosmosException = BridgeInternal.createCosmosException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); + CosmosException cosmosException = BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, goneException); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), OperationType.Delete, "/dbs/db/colls/col/docs/docId", ResourceType.Document); @@ -320,7 +320,7 @@ public void httpNetworkFailureOnQueryPlan() throws Exception { Exception exception = ReadTimeoutException.INSTANCE; CosmosException cosmosException = - BridgeInternal.createCosmosException(0, exception); + BridgeInternal.createCosmosException(null, 0, exception); BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_READ_TIMEOUT); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), @@ -361,7 +361,7 @@ public void httpNetworkFailureOnAddressRefresh() throws Exception { Exception exception = ReadTimeoutException.INSTANCE; CosmosException cosmosException = - BridgeInternal.createCosmosException(0, exception); + BridgeInternal.createCosmosException(null, 0, exception); BridgeInternal.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_READ_TIMEOUT); RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/NetworkFailureTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/NetworkFailureTest.java index 6dc1d8dd8a71a..ffed0835b5e77 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/NetworkFailureTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/NetworkFailureTest.java @@ -45,7 +45,7 @@ public void createCollectionWithUnreachableHost() { RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); if (request.getResourceType() == ResourceType.DocumentCollection) { - CosmosException exception = BridgeInternal.createCosmosException(0, new UnknownHostException()); + CosmosException exception = BridgeInternal.createCosmosException(null, 0, new UnknownHostException()); BridgeInternal.setSubStatusCode(exception, HttpConstants.SubStatusCodes.GATEWAY_ENDPOINT_UNAVAILABLE); return Mono.error(exception); } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryCreateDocumentTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryCreateDocumentTest.java index 734a656545620..1a6536053f3d3 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryCreateDocumentTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/RetryCreateDocumentTest.java @@ -58,7 +58,7 @@ public void retryDocumentCreate() throws Exception { HttpConstants.HttpHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH)); - return Mono.error(BridgeInternal.createCosmosException(HttpConstants.StatusCodes.BADREQUEST, new CosmosError() , header)); + return Mono.error(BridgeInternal.createCosmosException(req.requestContext.resourcePhysicalAddress, HttpConstants.StatusCodes.BADREQUEST, new CosmosError() , header)); } else { return client.getOrigGatewayStoreModel().processMessage(req); } @@ -89,7 +89,7 @@ public void createDocument_noRetryOnNonRetriableFailure() throws Exception { HttpConstants.HttpHeaders.SUB_STATUS, Integer.toString(2)); - return Mono.error(BridgeInternal.createCosmosException(1, new CosmosError() , header)); + return Mono.error(BridgeInternal.createCosmosException(req.requestContext.resourcePhysicalAddress, 1, new CosmosError() , header)); } }).when(client.getSpyGatewayStoreModel()).processMessage(anyObject()); @@ -124,7 +124,7 @@ public void createDocument_failImmediatelyOnNonRetriable() throws Exception { HttpConstants.HttpHeaders.SUB_STATUS, Integer.toString(2)); - return Mono.error(BridgeInternal.createCosmosException(1, new CosmosError() , header)); + return Mono.error(BridgeInternal.createCosmosException(req.requestContext.resourcePhysicalAddress, 1, new CosmosError() , header)); } else { return client.getOrigGatewayStoreModel().processMessage(req); } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClientTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClientTest.java index f5b9434440e0d..9d794065efd14 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClientTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/directconnectivity/HttpTransportClientTest.java @@ -460,6 +460,7 @@ public void failuresWithHttpStatusCodes(HttpClientMockWrapper.HttpClientBehaviou RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName(mockDiagnosticsClientContext(), OperationType.Create, "dbs/db/colls/col", ResourceType.Document); request.setContentBytes(new byte[0]); + request.requestContext.resourcePhysicalAddress = "dbs/db/colls/col"; Mono storeResp = transportClient.invokeStoreAsync( Uri.create(physicalAddress), diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/query/DocumentProducerTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/query/DocumentProducerTest.java index 6639a8fed3ba0..4e75112ffdff7 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/query/DocumentProducerTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/query/DocumentProducerTest.java @@ -727,7 +727,7 @@ private static CosmosException partitionKeyRangeGoneException() { Map headers = new HashMap<>(); headers.put(HttpConstants.HttpHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE)); - return BridgeInternal.createCosmosException(HttpConstants.StatusCodes.GONE, new CosmosError(), headers); + return BridgeInternal.createCosmosException(null, HttpConstants.StatusCodes.GONE, new CosmosError(), headers); } protected void capture(String partitionId, CapturedInvocation captureInvocation) {