Skip to content

Commit

Permalink
Trace: Fixes Tracing/diagnostics hour-times to 24Hours (#3577)
Browse files Browse the repository at this point in the history
* Trace: Fixes Tracing/diagnostics hour-times to 24Hours

* fixing baseline tests

Co-authored-by: Matias Quaranta <[email protected]>
  • Loading branch information
kirankumarkolli and ealsur authored Nov 24, 2022
1 parent 9734ec5 commit 6632168
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 306 deletions.
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

0 comments on commit 6632168

Please sign in to comment.