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

CosmosClient: Fixes missing Trace when converting HTTP Timeout to 503 #3866

Merged
14 commits merged into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
6 changes: 4 additions & 2 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6473,8 +6473,10 @@ await this.cosmosAuthorization.AddAuthorizationHeaderAsync(
return request;
}

AccountProperties databaseAccount = await gatewayModel.GetDatabaseAccountAsync(CreateRequestMessage,
clientSideRequestStatistics: null);
AccountProperties databaseAccount = await gatewayModel.GetDatabaseAccountAsync(
CreateRequestMessage,
clientSideRequestStatistics: null,
trace: null);
rinatmini marked this conversation as resolved.
Show resolved Hide resolved
this.UseMultipleWriteLocations = this.ConnectionPolicy.UseMultipleWriteLocations && databaseAccount.EnableMultipleWriteLocations;

if (this.queryPartitionProvider.IsValueCreated)
Expand Down
1 change: 1 addition & 0 deletions Microsoft.Azure.Cosmos/src/GatewayAccountReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ await this.cosmosAuthorization.AddAuthorizationHeaderAsync(
resourceType: ResourceType.DatabaseAccount,
timeoutPolicy: HttpTimeoutPolicyControlPlaneRead.Instance,
clientSideRequestStatistics: stats,
trace: trace,
cancellationToken: default))
using (DocumentServiceResponse documentServiceResponse = await ClientExtensions.ParseResponseAsync(responseMessage))
{
Expand Down
4 changes: 4 additions & 0 deletions Microsoft.Azure.Cosmos/src/GatewayStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Microsoft.Azure.Cosmos
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Handlers;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Cosmos.Tracing.TraceData;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
Expand Down Expand Up @@ -78,13 +79,15 @@ internal Task<HttpResponseMessage> SendHttpAsync(
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken = default)
{
return this.httpClient.SendHttpAsync(
createRequestMessageAsync: requestMessage,
resourceType: resourceType,
timeoutPolicy: timeoutPolicy,
clientSideRequestStatistics: clientSideRequestStatistics,
trace: trace,
cancellationToken: cancellationToken);
}

Expand Down Expand Up @@ -354,6 +357,7 @@ private Task<HttpResponseMessage> InvokeClientAsync(
resourceType,
HttpTimeoutPolicy.GetTimeoutPolicy(request),
request.RequestContext.ClientRequestStatistics,
trace: null,
cancellationToken);
}
}
Expand Down
9 changes: 6 additions & 3 deletions Microsoft.Azure.Cosmos/src/GatewayStoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ await GatewayStoreModel.ApplySessionTokenAsync(
return response;
}

public virtual async Task<AccountProperties> GetDatabaseAccountAsync(Func<ValueTask<HttpRequestMessage>> requestMessage,
IClientSideRequestStatistics clientSideRequestStatistics,
CancellationToken cancellationToken = default)
public virtual async Task<AccountProperties> GetDatabaseAccountAsync(
Func<ValueTask<HttpRequestMessage>> requestMessage,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken = default)
{
AccountProperties databaseAccount = null;

Expand All @@ -105,6 +107,7 @@ public virtual async Task<AccountProperties> GetDatabaseAccountAsync(Func<ValueT
ResourceType.DatabaseAccount,
HttpTimeoutPolicyControlPlaneRead.Instance,
clientSideRequestStatistics,
trace,
rinatmini marked this conversation as resolved.
Show resolved Hide resolved
cancellationToken))
{
using (DocumentServiceResponse documentServiceResponse = await ClientExtensions.ParseResponseAsync(responseMessage))
Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public abstract Task<HttpResponseMessage> GetAsync(
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken);

public abstract Task<HttpResponseMessage> SendHttpAsync(
Func<ValueTask<HttpRequestMessage>> createRequestMessageAsync,
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken);

protected abstract void Dispose(bool disposing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Cosmos
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Cosmos.Tracing.TraceData;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
Expand Down Expand Up @@ -261,6 +262,7 @@ public override Task<HttpResponseMessage> GetAsync(
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken)
{
if (uri == null)
Expand Down Expand Up @@ -292,6 +294,7 @@ ValueTask<HttpRequestMessage> CreateRequestMessage()
resourceType,
timeoutPolicy,
clientSideRequestStatistics,
trace,
cancellationToken);
}

Expand All @@ -300,6 +303,7 @@ public override Task<HttpResponseMessage> SendHttpAsync(
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken)
{
if (createRequestMessageAsync == null)
Expand All @@ -312,6 +316,7 @@ public override Task<HttpResponseMessage> SendHttpAsync(
resourceType,
timeoutPolicy,
clientSideRequestStatistics,
trace,
cancellationToken);
}

Expand All @@ -320,6 +325,7 @@ private async Task<HttpResponseMessage> SendHttpHelperAsync(
ResourceType resourceType,
HttpTimeoutPolicy timeoutPolicy,
IClientSideRequestStatistics clientSideRequestStatistics,
ITrace trace,
CancellationToken cancellationToken)
{
DateTime startDateTimeUtc = DateTime.UtcNow;
Expand Down Expand Up @@ -394,6 +400,7 @@ private async Task<HttpResponseMessage> SendHttpHelperAsync(
ActivityId = System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
SubStatusCode = SubStatusCodes.TransportGenerated503
},
trace: trace,
innerException: e);
}

Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ private async Task<DocumentServiceResponse> GetMasterAddressesViaGatewayAsync(
resourceType: resourceType,
timeoutPolicy: HttpTimeoutPolicyControlPlaneRetriableHotPath.Instance,
clientSideRequestStatistics: request.RequestContext?.ClientRequestStatistics,
trace: trace,
cancellationToken: default))
{
DocumentServiceResponse documentServiceResponse = await ClientExtensions.ParseResponseAsync(httpResponseMessage);
Expand Down Expand Up @@ -694,6 +695,7 @@ private async Task<DocumentServiceResponse> GetServerAddressesViaGatewayAsync(
resourceType: ResourceType.Document,
timeoutPolicy: HttpTimeoutPolicyControlPlaneRetriableHotPath.Instance,
clientSideRequestStatistics: request.RequestContext?.ClientRequestStatistics,
trace: trace,
cancellationToken: default))
{
DocumentServiceResponse documentServiceResponse = await ClientExtensions.ParseResponseAsync(httpResponseMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ await this.tokenProvider.AddAuthorizationHeaderAsync(
ResourceType.Telemetry,
HttpTimeoutPolicyNoRetry.Instance,
null,
null,
cancellationToken);

if (!response.IsSuccessStatusCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static ValueTask<HttpRequestMessage> CreateRequestMessage()
resourceType: ResourceType.Telemetry,
timeoutPolicy: HttpTimeoutPolicyNoRetry.Instance,
clientSideRequestStatistics: null,
trace: null,
cancellationToken: default);

azMetadata = await VmMetadataApiHandler.ProcessResponseAsync(response);
Expand Down
Loading