Skip to content

Commit fe72e8f

Browse files
committed
Fix substatus mapping issue.
1 parent d5fcd3e commit fe72e8f

3 files changed

Lines changed: 141 additions & 124 deletions

File tree

Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryAttributeKeys.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace Microsoft.Azure.Cosmos.Telemetry
99
using System.Linq;
1010
using System.Net;
1111
using global::Azure.Core;
12-
using Microsoft.Azure.Cosmos.Tracing.TraceData;
12+
using Microsoft.Azure.Cosmos.Tracing.TraceData;
13+
using Microsoft.Azure.Cosmos.Util;
1314
using Microsoft.Azure.Documents;
1415

1516
/// <summary>
@@ -484,17 +485,19 @@ private static string GetRegion(ClientSideRequestStatisticsTraceDatum.StoreRespo
484485
/// <param name="statusCode">Status code</param>
485486
/// <param name="subStatusCode">Sub status code</param>
486487
/// <returns>error.type dimension value</returns>
487-
private static string GetErrorType(Exception exception, int? statusCode, int? subStatusCode)
488-
{
489-
if (exception == null)
490-
{
491-
return null;
492-
}
493-
494-
HttpStatusCode? code = statusCode.HasValue ? (HttpStatusCode)statusCode.Value : null;
495-
SubStatusCodes? subCode = subStatusCode.HasValue ? (SubStatusCodes)subStatusCode.Value : null;
496-
497-
return $"{exception.GetType().Name}_{code?.ToString()}_{subCode?.ToString()}";
488+
private static string GetErrorType(Exception exception, int? statusCode, int? subStatusCode)
489+
{
490+
if (exception == null)
491+
{
492+
return null;
493+
}
494+
495+
string codeString = statusCode.HasValue ? ((StatusCodes)statusCode.Value).ToString() : string.Empty;
496+
string mappedSubStatusCode = (statusCode.HasValue && subStatusCode.HasValue)
497+
? SubStatusMappingUtil.GetSubStatusCodeString((StatusCodes)statusCode.Value, (SubStatusCodes)subStatusCode.Value)
498+
: string.Empty;
499+
500+
return $"{exception.GetType().Name}_{codeString}_{mappedSubStatusCode}";
498501
}
499502

500503
private static int GetSubStatusCode(ClientSideRequestStatisticsTraceDatum.StoreResponseStatistics tcpStats, ClientSideRequestStatisticsTraceDatum.HttpResponseStatistics? httpStats)

Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Microsoft.Azure.Cosmos.Tracing
1111
using System.Net.Http;
1212
using System.Text;
1313
using Microsoft.Azure.Cosmos.Json;
14-
using Microsoft.Azure.Cosmos.Tracing.TraceData;
14+
using Microsoft.Azure.Cosmos.Tracing.TraceData;
15+
using Microsoft.Azure.Cosmos.Util;
1516
using Microsoft.Azure.Documents;
1617

1718
internal static partial class TraceWriter
@@ -394,7 +395,7 @@ public void Visit(StoreResult storeResult)
394395
this.jsonWriter.WriteStringValue(storeResult.StatusCode.ToString());
395396

396397
this.jsonWriter.WriteFieldName(nameof(storeResult.SubStatusCode));
397-
this.jsonWriter.WriteStringValue(this.GetSubStatusCodeString(storeResult.StatusCode, storeResult.SubStatusCode));
398+
this.jsonWriter.WriteStringValue(SubStatusMappingUtil.GetSubStatusCodeString(storeResult.StatusCode, storeResult.SubStatusCode));
398399

399400
this.jsonWriter.WriteFieldName(nameof(storeResult.LSN));
400401
this.jsonWriter.WriteNumberValue(storeResult.LSN);
@@ -452,116 +453,6 @@ public void Visit(StoreResult storeResult)
452453
this.jsonWriter.WriteObjectEnd();
453454
}
454455

455-
internal string GetSubStatusCodeString(StatusCodes statusCode, SubStatusCodes subStatusCode)
456-
{
457-
if ((int)subStatusCode == 1002)
458-
{
459-
return statusCode == StatusCodes.NotFound
460-
? "ReadSessionNotAvailable"
461-
: SubStatusCodes.PartitionKeyRangeGone.ToString();
462-
}
463-
464-
if ((int)subStatusCode == 2001)
465-
{
466-
return statusCode == StatusCodes.NoContent
467-
? "MissedTargetLsn"
468-
: SubStatusCodes.SplitIsDisabled.ToString();
469-
}
470-
471-
if ((int)subStatusCode == 2002)
472-
{
473-
return statusCode == StatusCodes.NoContent
474-
? "MissedTargetLsnOver100"
475-
: SubStatusCodes.CollectionsInPartitionGotUpdated.ToString();
476-
}
477-
478-
if ((int)subStatusCode == 2003)
479-
{
480-
return statusCode == StatusCodes.NoContent
481-
? "MissedTargetLsnOver1000"
482-
: SubStatusCodes.CanNotAcquirePKRangesLock.ToString();
483-
}
484-
485-
if ((int)subStatusCode == 2004)
486-
{
487-
return statusCode == StatusCodes.NoContent
488-
? "MissedTargetLsnOver10000"
489-
: SubStatusCodes.ResourceNotFound.ToString();
490-
}
491-
492-
if ((int)subStatusCode == 2011)
493-
{
494-
return statusCode == StatusCodes.NoContent
495-
? "MissedTargetGlobalCommittedLsn"
496-
: SubStatusCodes.StorageSplitConflictingWithNWayThroughputSplit.ToString();
497-
}
498-
499-
if ((int)subStatusCode == 2012)
500-
{
501-
return statusCode == StatusCodes.NoContent
502-
? "MissedTargetGlobalCommittedLsnOver100"
503-
: SubStatusCodes.MergeIsDisabled.ToString();
504-
}
505-
506-
if ((int)subStatusCode == 1004)
507-
{
508-
return statusCode == StatusCodes.BadRequest
509-
? "CrossPartitionQueryNotServable"
510-
: SubStatusCodes.ConfigurationNameNotFound.ToString();
511-
}
512-
513-
if ((int)subStatusCode == 1007)
514-
{
515-
return statusCode == StatusCodes.Gone
516-
? "CompletingSplit"
517-
: SubStatusCodes.InsufficientBindablePartitions.ToString();
518-
}
519-
520-
if ((int)subStatusCode == 1008)
521-
{
522-
return statusCode == StatusCodes.Gone
523-
? "CompletingPartitionMigration"
524-
: SubStatusCodes.DatabaseAccountNotFound.ToString();
525-
}
526-
527-
if ((int)subStatusCode == 1005)
528-
{
529-
return statusCode == StatusCodes.NotFound
530-
? "ConfigurationPropertyNotFound"
531-
: SubStatusCodes.ProvisionLimitReached.ToString();
532-
}
533-
534-
if ((int)subStatusCode == 3207)
535-
{
536-
return statusCode == StatusCodes.Conflict
537-
? "ConfigurationNameAlreadyExists"
538-
: SubStatusCodes.PrepareTimeLimitExceeded.ToString();
539-
}
540-
541-
if ((int)subStatusCode == 6001)
542-
{
543-
return statusCode == StatusCodes.ServiceUnavailable
544-
? "AggregatedHealthStateError"
545-
: SubStatusCodes.PartitionMigrationWaitForFullSyncReceivedInternalServerErrorDuringCompleteMigrationFromBackend.ToString();
546-
}
547-
548-
if ((int)subStatusCode == 6002)
549-
{
550-
return statusCode == StatusCodes.ServiceUnavailable
551-
? "ApplicationHealthStateError"
552-
: SubStatusCodes.PartitionMigrationWaitForFullSyncReceivedInternalServerErrorDuringAbortMigrationFromBackend.ToString();
553-
}
554-
555-
if ((int)subStatusCode == 6003)
556-
{
557-
return statusCode == StatusCodes.ServiceUnavailable
558-
? "HealthStateError"
559-
: SubStatusCodes.PartitionMigrationFinalizeMigrationsDidNotCompleteInTenRetries.ToString();
560-
}
561-
562-
return subStatusCode.ToString();
563-
}
564-
565456
public void Visit(PartitionKeyRangeCacheTraceDatum partitionKeyRangeCacheTraceDatum)
566457
{
567458
this.jsonWriter.WriteObjectStart();
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
//------------------------------------------------------------
4+
namespace Microsoft.Azure.Cosmos.Util
5+
{
6+
using Microsoft.Azure.Documents;
7+
8+
/// <summary>
9+
/// Utility for correctly mapping duplicate SubStatus codes.
10+
/// </summary>
11+
internal class SubStatusMappingUtil
12+
{
13+
public static string GetSubStatusCodeString(StatusCodes statusCode, SubStatusCodes subStatusCode)
14+
{
15+
if ((int)subStatusCode == 1002)
16+
{
17+
return statusCode == StatusCodes.NotFound
18+
? nameof(SubStatusCodes.ReadSessionNotAvailable)
19+
: nameof(SubStatusCodes.PartitionKeyRangeGone);
20+
}
21+
22+
if ((int)subStatusCode == 2001)
23+
{
24+
return statusCode == StatusCodes.NoContent
25+
? nameof(SubStatusCodes.MissedTargetLsn)
26+
: nameof(SubStatusCodes.SplitIsDisabled);
27+
}
28+
29+
if ((int)subStatusCode == 2002)
30+
{
31+
return statusCode == StatusCodes.NoContent
32+
? nameof(SubStatusCodes.MissedTargetLsnOver100)
33+
: nameof(SubStatusCodes.CollectionsInPartitionGotUpdated);
34+
}
35+
36+
if ((int)subStatusCode == 2003)
37+
{
38+
return statusCode == StatusCodes.NoContent
39+
? nameof(SubStatusCodes.MissedTargetLsnOver1000)
40+
: nameof(SubStatusCodes.CanNotAcquirePKRangesLock);
41+
}
42+
43+
if ((int)subStatusCode == 2004)
44+
{
45+
return statusCode == StatusCodes.NoContent
46+
? nameof(SubStatusCodes.MissedTargetLsnOver10000)
47+
: nameof(SubStatusCodes.ResourceNotFound);
48+
}
49+
50+
if ((int)subStatusCode == 2011)
51+
{
52+
return statusCode == StatusCodes.NoContent
53+
? nameof(SubStatusCodes.MissedTargetGlobalCommittedLsn)
54+
: nameof(SubStatusCodes.StorageSplitConflictingWithNWayThroughputSplit);
55+
}
56+
57+
if ((int)subStatusCode == 2012)
58+
{
59+
return statusCode == StatusCodes.NoContent
60+
? nameof(SubStatusCodes.MissedTargetGlobalCommittedLsnOver100)
61+
: nameof(SubStatusCodes.MergeIsDisabled);
62+
}
63+
64+
if ((int)subStatusCode == 1004)
65+
{
66+
return statusCode == StatusCodes.BadRequest
67+
? nameof(SubStatusCodes.CrossPartitionQueryNotServable)
68+
: nameof(SubStatusCodes.ConfigurationNameNotFound);
69+
}
70+
71+
if ((int)subStatusCode == 1007)
72+
{
73+
return statusCode == StatusCodes.Gone
74+
? nameof(SubStatusCodes.CompletingSplit)
75+
: nameof(SubStatusCodes.InsufficientBindablePartitions);
76+
}
77+
78+
if ((int)subStatusCode == 1008)
79+
{
80+
return statusCode == StatusCodes.Gone
81+
? nameof(SubStatusCodes.CompletingPartitionMigration)
82+
: nameof(SubStatusCodes.DatabaseAccountNotFound);
83+
}
84+
85+
if ((int)subStatusCode == 1005)
86+
{
87+
return statusCode == StatusCodes.NotFound
88+
? nameof(SubStatusCodes.ConfigurationPropertyNotFound)
89+
: nameof(SubStatusCodes.ProvisionLimitReached);
90+
}
91+
92+
if ((int)subStatusCode == 3207)
93+
{
94+
return statusCode == StatusCodes.Conflict
95+
? nameof(SubStatusCodes.ConfigurationNameAlreadyExists)
96+
: nameof(SubStatusCodes.PrepareTimeLimitExceeded);
97+
}
98+
99+
if ((int)subStatusCode == 6001)
100+
{
101+
return statusCode == StatusCodes.ServiceUnavailable
102+
? nameof(SubStatusCodes.AggregatedHealthStateError)
103+
: nameof(SubStatusCodes.PartitionMigrationWaitForFullSyncReceivedInternalServerErrorDuringCompleteMigrationFromBackend);
104+
}
105+
106+
if ((int)subStatusCode == 6002)
107+
{
108+
return statusCode == StatusCodes.ServiceUnavailable
109+
? nameof(SubStatusCodes.ApplicationHealthStateError)
110+
: nameof(SubStatusCodes.PartitionMigrationWaitForFullSyncReceivedInternalServerErrorDuringAbortMigrationFromBackend);
111+
}
112+
113+
if ((int)subStatusCode == 6003)
114+
{
115+
return statusCode == StatusCodes.ServiceUnavailable
116+
? nameof(SubStatusCodes.HealthStateError)
117+
: nameof(SubStatusCodes.PartitionMigrationFinalizeMigrationsDidNotCompleteInTenRetries);
118+
}
119+
120+
return subStatusCode.ToString();
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)