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

CosmosDiagnostics: Adds optimizations and BELatency #2397

Merged
merged 9 commits into from
Apr 19, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,8 @@ private async ValueTask RefreshCachedTokenWithRetryHelperAsync(ITrace trace)
{
lastException = requestFailedException;
getTokenTrace.AddDatum(
"Request Failed Exception",
new PointOperationStatisticsTraceDatum(
activityId: System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
statusCode: (HttpStatusCode)requestFailedException.Status,
subStatusCode: SubStatusCodes.Unknown,
responseTimeUtc: DateTime.UtcNow,
requestCharge: default,
errorMessage: requestFailedException.ToString(),
method: default,
requestUri: null,
requestSessionToken: default,
responseSessionToken: default));
$"RequestFailedException at {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}",
requestFailedException);
j82w marked this conversation as resolved.
Show resolved Hide resolved

DefaultTrace.TraceError($"TokenCredential.GetToken() failed with RequestFailedException. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException}");

Expand All @@ -203,18 +193,8 @@ private async ValueTask RefreshCachedTokenWithRetryHelperAsync(ITrace trace)
{
lastException = operationCancelled;
getTokenTrace.AddDatum(
"Request Timeout Exception",
new PointOperationStatisticsTraceDatum(
activityId: System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
statusCode: HttpStatusCode.RequestTimeout,
subStatusCode: SubStatusCodes.Unknown,
responseTimeUtc: DateTime.UtcNow,
requestCharge: default,
errorMessage: operationCancelled.ToString(),
method: default,
requestUri: null,
requestSessionToken: default,
responseSessionToken: default));
$"OperationCanceledException at {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}",
operationCancelled);

DefaultTrace.TraceError(
$"TokenCredential.GetTokenAsync() failed. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException}");
Expand All @@ -232,18 +212,8 @@ private async ValueTask RefreshCachedTokenWithRetryHelperAsync(ITrace trace)
{
lastException = exception;
getTokenTrace.AddDatum(
"Internal Server Error Exception",
new PointOperationStatisticsTraceDatum(
activityId: System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
statusCode: HttpStatusCode.InternalServerError,
subStatusCode: SubStatusCodes.Unknown,
responseTimeUtc: DateTime.UtcNow,
requestCharge: default,
errorMessage: exception.ToString(),
method: default,
requestUri: null,
requestSessionToken: default,
responseSessionToken: default));
$"Exception at {DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)}",
exception);

DefaultTrace.TraceError(
$"TokenCredential.GetTokenAsync() failed. scope = {string.Join(";", this.tokenRequestContext.Scopes)}, retry = {retry}, Exception = {lastException}");
Expand Down
94 changes: 0 additions & 94 deletions Microsoft.Azure.Cosmos/src/Diagnostics/StoreResultStatistics.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public virtual string QueryMetrics
set => this.SetProperty(HttpConstants.HttpHeaders.QueryMetrics, value);
}

public virtual string BackendRequestDurationMilliseconds
{
get => this.GetValueOrDefault(HttpConstants.HttpHeaders.BackendRequestDurationMilliseconds);
set => this.SetProperty(HttpConstants.HttpHeaders.BackendRequestDurationMilliseconds, value);
}

public virtual string Location
{
get => this.GetValueOrDefault(HttpConstants.HttpHeaders.Location);
Expand Down
6 changes: 6 additions & 0 deletions Microsoft.Azure.Cosmos/src/Headers/Headers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ internal virtual string QueryMetricsText
set => this.CosmosMessageHeaders.QueryMetrics = value;
}

internal virtual string BackendRequestDurationMilliseconds
{
get => this.CosmosMessageHeaders.BackendRequestDurationMilliseconds;
set => this.CosmosMessageHeaders.BackendRequestDurationMilliseconds = value;
}

/// <summary>
/// Creates a new instance of <see cref="Headers"/>.
/// </summary>
Expand Down
9 changes: 6 additions & 3 deletions Microsoft.Azure.Cosmos/src/Headers/StoreResponseHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;

/// <summary>
Expand Down Expand Up @@ -49,6 +46,12 @@ public override string QueryMetrics
set => this.storeResponseNameValueCollection.QueryMetrics = value;
}

public override string BackendRequestDurationMilliseconds
{
get => this.storeResponseNameValueCollection.BackendRequestDurationMilliseconds;
set => this.storeResponseNameValueCollection.BackendRequestDurationMilliseconds = value;
}

public override string Continuation
{
get => this.storeResponseNameValueCollection.Continuation;
Expand Down
14 changes: 2 additions & 12 deletions Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,8 @@ private async Task<HttpResponseMessage> SendHttpHelperAsync(
{
// Log the error message
trace.AddDatum(
"Error",
new PointOperationStatisticsTraceDatum(
activityId: System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
statusCode: HttpStatusCode.ServiceUnavailable,
subStatusCode: SubStatusCodes.Unknown,
responseTimeUtc: DateTime.UtcNow,
requestCharge: 0,
errorMessage: e.ToString(),
method: requestMessage.Method,
requestUri: requestMessage.RequestUri.OriginalString,
requestSessionToken: null,
responseSessionToken: null));
$"Error at {DateTime.UtcNow}",
e);

bool isOutOfRetries = (DateTime.UtcNow - startDateTimeUtc) > timeoutPolicy.MaximumRetryTimeLimit || // Maximum of time for all retries
!timeoutEnumerator.MoveNext(); // No more retries are configured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public PointOperationStatisticsTraceDatum(
HttpMethod method,
string requestUri,
string requestSessionToken,
string responseSessionToken)
string responseSessionToken,
string beLatencyInMs)
{
this.ActivityId = activityId;
this.StatusCode = statusCode;
Expand All @@ -33,6 +34,7 @@ public PointOperationStatisticsTraceDatum(
this.RequestSessionToken = requestSessionToken;
this.ResponseSessionToken = responseSessionToken;
this.ResponseTimeUtc = responseTimeUtc;
this.BELatencyInMs = beLatencyInMs;
}

public string ActivityId { get; }
Expand All @@ -45,6 +47,7 @@ public PointOperationStatisticsTraceDatum(
public string RequestUri { get; }
public string RequestSessionToken { get; }
public string ResponseSessionToken { get; }
public string BELatencyInMs { get; }

internal override void Accept(ITraceDatumVisitor traceDatumVisitor)
{
Expand Down
Loading