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

Diagnostics Logs: Fixes ContactReplicas to only include the successful replica contacted per physical partition. #4156

Closed
Show file tree
Hide file tree
Changes from all 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 @@ -194,7 +194,7 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
this.jsonWriter.WriteFieldName("Id");
this.jsonWriter.WriteStringValue("AggregatedClientSideRequestStatistics");

this.WriteJsonUriArrayWithDuplicatesCounted("ContactedReplicas", clientSideRequestStatisticsTraceDatum.ContactedReplicas);
this.WriteJsonUriArrayWithDuplicatesCounted("ContactedReplicas", TraceWriter.TraceDatumJsonWriter.GetFinalContactedReplica(clientSideRequestStatisticsTraceDatum));

this.WriteRegionsContactedArray("RegionsContacted", clientSideRequestStatisticsTraceDatum.RegionsContacted);
this.WriteJsonUriArray("FailedReplicas", clientSideRequestStatisticsTraceDatum.FailedReplicas);
Expand All @@ -206,7 +206,7 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist

foreach (KeyValuePair<string, ClientSideRequestStatisticsTraceDatum.AddressResolutionStatistics> stat in clientSideRequestStatisticsTraceDatum.EndpointToAddressResolutionStatistics)
{
this.VisitAddressResolutionStatistics(stat.Value);
this.VisitAddressResolutionStatistics(stat.Value);
}

this.jsonWriter.WriteArrayEnd();
Expand Down Expand Up @@ -237,6 +237,11 @@ public void Visit(ClientSideRequestStatisticsTraceDatum clientSideRequestStatist
this.jsonWriter.WriteObjectEnd();
}

private static List<TransportAddressUri> GetFinalContactedReplica(ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum)
{
return new List<TransportAddressUri> { clientSideRequestStatisticsTraceDatum.ContactedReplicas.LastOrDefault() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A request might have contacted multiple replicas, why are we taking only 1?

}

private void VisitHttpResponseStatistics(ClientSideRequestStatisticsTraceDatum.HttpResponseStatistics stat, IJsonWriter jsonWriter)
{
jsonWriter.WriteObjectStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@
"Client Side Request Stats": {
"Id": "AggregatedClientSideRequestStatistics",
"ContactedReplicas": [
{
"Count": 1,
"Uri": "http://someuri1.com/"
},
{
"Count": 1,
"Uri": "http://someuri2.com/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,56 @@ public async Task ConcurrentUpdateHttpResponseStatisticsListTests()
}

[TestMethod]
public void DuplicateContactedReplicasTests()
[Owner("philipthomas")]
public void NullContactedReplicasExpectsZeroCountTests()
{
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, Trace.GetRootTrace(nameof(DuplicateContactedReplicasTests)));
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, Trace.GetRootTrace(nameof(NullContactedReplicasExpectsZeroCountTests)));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(default);
ITrace trace = Trace.GetRootTrace("test");
trace.AddDatum("stats", clientSideRequestStatisticsTraceDatum);
string json = new CosmosTraceDiagnostics(trace).ToString();
JObject jobject = JObject.Parse(json);
JToken contactedReplicas = jobject["data"]["stats"]["ContactedReplicas"];
Assert.AreEqual(0, contactedReplicas.Count());
}

[TestMethod]
[Owner("philipthomas")]
public void NoContactedReplicasExpectsZeroCountTests()
{
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, Trace.GetRootTrace(nameof(NoContactedReplicasExpectsZeroCountTests)));
ITrace trace = Trace.GetRootTrace("test");
trace.AddDatum("stats", clientSideRequestStatisticsTraceDatum);
string json = new CosmosTraceDiagnostics(trace).ToString();
JObject jobject = JObject.Parse(json);
JToken contactedReplicas = jobject["data"]["stats"]["ContactedReplicas"];
Assert.AreEqual(0, contactedReplicas.Count());
}

[TestMethod]
[Owner("philipthomas")]
public void NoDuplicateContactedReplicasExpectsLastContactedReplicasTests()
{
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, Trace.GetRootTrace(nameof(NoDuplicateContactedReplicasExpectsLastContactedReplicasTests)));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(new TransportAddressUri(new Uri("http://storephysicaladdress1.com")));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(new TransportAddressUri(new Uri("http://storephysicaladdress2.com")));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(new TransportAddressUri(new Uri("http://storephysicaladdress3.com")));
ITrace trace = Trace.GetRootTrace("test");
trace.AddDatum("stats", clientSideRequestStatisticsTraceDatum);
string json = new CosmosTraceDiagnostics(trace).ToString();
JObject jobject = JObject.Parse(json);
JToken contactedReplicas = jobject["data"]["stats"]["ContactedReplicas"];
Assert.AreEqual(1, contactedReplicas.Count());
int count = contactedReplicas[0]["Count"].Value<int>();
Assert.AreEqual(1, count);
string uri = contactedReplicas[0]["Uri"].Value<string>();
Assert.AreEqual("http://storephysicaladdress3.com/", uri);
}

[TestMethod]
public void DuplicateContactedReplicasExpectsLastContactedReplicasTests()
{
ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, Trace.GetRootTrace(nameof(DuplicateContactedReplicasExpectsLastContactedReplicasTests)));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(new TransportAddressUri(new Uri("http://storephysicaladdress1.com")));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(new TransportAddressUri(new Uri("http://storephysicaladdress2.com")));
clientSideRequestStatisticsTraceDatum.ContactedReplicas.Add(new TransportAddressUri(new Uri("http://storephysicaladdress2.com")));
Expand All @@ -58,22 +105,13 @@ public void DuplicateContactedReplicasTests()
ITrace trace = Trace.GetRootTrace("test");
trace.AddDatum("stats", clientSideRequestStatisticsTraceDatum);
string json = new CosmosTraceDiagnostics(trace).ToString();
Console.WriteLine(json);
JObject jobject = JObject.Parse(json);
JToken contactedReplicas = jobject["data"]["stats"]["ContactedReplicas"];
Assert.AreEqual(3, contactedReplicas.Count());
Assert.AreEqual(1, contactedReplicas.Count());
int count = contactedReplicas[0]["Count"].Value<int>();
Assert.AreEqual(1, count);
string uri = contactedReplicas[0]["Uri"].Value<string>();
Assert.AreEqual("http://storephysicaladdress1.com/", uri);

count = contactedReplicas[1]["Count"].Value<int>();
Assert.AreEqual(4, count);
uri = contactedReplicas[1]["Uri"].Value<string>();
Assert.AreEqual("http://storephysicaladdress2.com/", uri);

count = contactedReplicas[2]["Count"].Value<int>();
Assert.AreEqual(1, count);
uri = contactedReplicas[2]["Uri"].Value<string>();
Assert.AreEqual("http://storephysicaladdress3.com/", uri);
}

Expand Down
Loading