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

Trace: Fixes Tracing/diagnostics hour-times to 24Hours #3577

Merged
merged 5 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void WriteTrace(
if (isRootTrace)
{
writer.WriteFieldName("start time");
writer.WriteStringValue(trace.StartTime.ToString("hh:mm:ss:fff"));
writer.WriteStringValue(trace.StartTime.ToString(TraceWriter.HourTimeFormatString));
}
writer.WriteFieldName("duration in milliseconds");
writer.WriteNumber64Value(trace.Duration.TotalMilliseconds);
Expand Down
22 changes: 12 additions & 10 deletions Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Microsoft.Azure.Cosmos.Tracing

internal static partial class TraceWriter
{
internal static readonly string HourTimeFormatString = "HH:mm:ss:fff";

private static class TraceTextWriter
{
private const string space = " ";
Expand Down Expand Up @@ -97,8 +99,8 @@ private static class Headers

private static class HeaderLengths
{
public static readonly int StartTime = Math.Max(Headers.StartTime.Length, DateTime.MaxValue.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture).Length);
public static readonly int EndTime = Math.Max(Headers.EndTime.Length, DateTime.MaxValue.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture).Length);
public static readonly int StartTime = Math.Max(Headers.StartTime.Length, DateTime.MaxValue.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture).Length);
public static readonly int EndTime = Math.Max(Headers.EndTime.Length, DateTime.MaxValue.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture).Length);
public static readonly int Endpoint = 80 - (StartTime + EndTime);
}

Expand Down Expand Up @@ -177,7 +179,7 @@ private static void WriteTraceRecursive(
writer.Write("Component");
writer.Write(space);

writer.Write(trace.StartTime.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture));
writer.Write(trace.StartTime.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture));
writer.Write(space);

writer.Write(trace.Duration.TotalMilliseconds.ToString("0.00"));
Expand Down Expand Up @@ -316,7 +318,7 @@ public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTra
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Activity ID: {pointOperationStatisticsTraceDatum.ActivityId ?? "<null>"}");
stringBuilder.AppendLine($"Status Code: {pointOperationStatisticsTraceDatum.StatusCode}/{pointOperationStatisticsTraceDatum.SubStatusCode}");
stringBuilder.AppendLine($"Response Time: {pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"Response Time: {pointOperationStatisticsTraceDatum.ResponseTimeUtc.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"Request Charge: {pointOperationStatisticsTraceDatum.RequestCharge}");
stringBuilder.AppendLine($"Request URI: {pointOperationStatisticsTraceDatum.RequestUri ?? "<null>"}");
stringBuilder.AppendLine($"Session Tokens: {pointOperationStatisticsTraceDatum.RequestSessionToken ?? "<null>"} / {pointOperationStatisticsTraceDatum.ResponseSessionToken ?? "<null>"}");
Expand All @@ -331,10 +333,10 @@ public void Visit(PointOperationStatisticsTraceDatum pointOperationStatisticsTra
public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Start Time: {clientSideRequestStatisticsTraceDatum.RequestStartTimeUtc.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"Start Time: {clientSideRequestStatisticsTraceDatum.RequestStartTimeUtc.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture)}");
if (clientSideRequestStatisticsTraceDatum.RequestEndTimeUtc.HasValue)
{
stringBuilder.AppendLine($"End Time: {clientSideRequestStatisticsTraceDatum.RequestEndTimeUtc.Value.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"End Time: {clientSideRequestStatisticsTraceDatum.RequestEndTimeUtc.Value.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture)}");
}

stringBuilder.AppendLine("Contacted Replicas");
Expand Down Expand Up @@ -378,8 +380,8 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
foreach (KeyValuePair<string, AddressResolutionStatistics> stat in clientSideRequestStatisticsTraceDatum.EndpointToAddressResolutionStatistics)
{
string row = AddressResolutionStatisticsTextTable.Singleton.GetRow(
stat.Value.StartTime.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture),
stat.Value.EndTime.HasValue ? stat.Value.EndTime.Value.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture) : "NO END TIME",
stat.Value.StartTime.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture),
stat.Value.EndTime.HasValue ? stat.Value.EndTime.Value.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture) : "NO END TIME",
stat.Value.TargetEndpoint);
stringBuilder.AppendLine(row);
}
Expand All @@ -391,14 +393,14 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
{
if (stat.RequestStartTime.HasValue)
{
stringBuilder.AppendLine($"{space}Start Time: {stat.RequestStartTime.Value.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"{space}Start Time: {stat.RequestStartTime.Value.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture)}");
}
else
{
stringBuilder.AppendLine("{space}Start Time Not Found");
}

stringBuilder.AppendLine($"{space}End Time: {stat.RequestResponseTime.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)}");
stringBuilder.AppendLine($"{space}End Time: {stat.RequestResponseTime.ToString(TraceWriter.HourTimeFormatString, CultureInfo.InvariantCulture)}");

stringBuilder.AppendLine($"{space}Resource Type: {stat.RequestResourceType}");
stringBuilder.AppendLine($"{space}Operation Type: {stat.RequestOperationType}");
Expand Down
Loading