-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Diagnostics: Adds Api for getting all regions contacted by a request (#…
…2312) * Api for getting all regions contacted by a request * Updating public contract * Updating tuple names * Adding Emulator Test * Renaming tuple * optimizing tree search Co-authored-by: j82w <j82w@users.noreply.github.com>
- Loading branch information
1 parent
da197a5
commit 8686eaa
Showing
9 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Tracing/ContactedRegionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace Microsoft.Azure.Cosmos.Tests.Tracing | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Azure.Cosmos.Diagnostics; | ||
using Microsoft.Azure.Cosmos.Tracing; | ||
using Microsoft.Azure.Cosmos.Tracing.TraceData; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class ContactedRegionsTests | ||
{ | ||
[TestMethod] | ||
public void ContactedRegionsTest() | ||
{ | ||
CosmosDiagnostics diagnostics = new CosmosTraceDiagnostics(this.CreateTestTraceTree()); | ||
IReadOnlyList<(string, Uri)> regionsContacted = diagnostics.GetContactedRegions(); | ||
Assert.IsNotNull(regionsContacted); | ||
Assert.AreEqual(regionsContacted.Count, 4); | ||
} | ||
|
||
private ITrace CreateTestTraceTree() | ||
{ | ||
ITrace trace; | ||
using (trace = Trace.GetRootTrace("Root Trace", TraceComponent.Unknown, TraceLevel.Info)) | ||
{ | ||
using (ITrace firstLevel = trace.StartChild("First level Node", TraceComponent.Unknown, TraceLevel.Info)) | ||
{ | ||
using (ITrace secondLevel = trace.StartChild("Second level Node", TraceComponent.Unknown, TraceLevel.Info)) | ||
{ | ||
using (ITrace thirdLevel = trace.StartChild("Third level Node", TraceComponent.Unknown, TraceLevel.Info)) | ||
{ | ||
thirdLevel.AddDatum("Client Side Request Stats", this.GetDatumObject(Regions.CentralUS)); | ||
} | ||
} | ||
|
||
using (ITrace secondLevel = trace.StartChild("Second level Node", TraceComponent.Unknown, TraceLevel.Info)) | ||
{ | ||
secondLevel.AddDatum("Client Side Request Stats", this.GetDatumObject(Regions.CentralIndia, Regions.EastUS2)); | ||
} | ||
} | ||
|
||
using (ITrace firstLevel = trace.StartChild("First level Node", TraceComponent.Unknown, TraceLevel.Info)) | ||
{ | ||
firstLevel.AddDatum("Client Side Request Stats", this.GetDatumObject(Regions.FranceCentral)); | ||
} | ||
} | ||
|
||
return trace; | ||
} | ||
|
||
private TraceDatum GetDatumObject(string regionName1, string regionName2 = null) | ||
{ | ||
ClientSideRequestStatisticsTraceDatum datum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow); | ||
Uri uri1 = new Uri("http://someUri1.com"); | ||
datum.RegionsContactedWithName.Add((regionName1, uri1)); | ||
if (regionName2 != null) | ||
{ | ||
Uri uri2 = new Uri("http://someUri2.com"); | ||
datum.RegionsContactedWithName.Add((regionName2, uri2)); | ||
} | ||
|
||
return datum; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters