-
Notifications
You must be signed in to change notification settings - Fork 497
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
[Internal] Diagnostics: Adds Merge API that combines several CosmosTraceDiagnostics Instances #4175
Closed
Closed
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
263da8c
adds constructor for diagnostics that takes in multiple diagnostics
NaluTripician 1d7e291
added total request charge field
NaluTripician 3fb4e88
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician 3aaef3d
made diagnostics smaller by removing client config info from child re…
NaluTripician bacce6c
test fix
NaluTripician 556ed9c
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician a26f7b7
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician 0676412
suggestions
NaluTripician 198c540
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician 6cf6638
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician 27f2b42
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician 8de8df4
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician bff0d2a
added additional request context to logs
NaluTripician c9ad4fd
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician 67afea0
Merge branch 'master' into users/nalutripician/mergeDiagnostics
NaluTripician c872c2a
fix bug from new changes to master
NaluTripician File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// ------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos.Tracing | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Azure.Cosmos.Tracing.TraceData; | ||
using static Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum; | ||
|
||
internal sealed class MergedTrace : ITrace | ||
{ | ||
private static readonly IReadOnlyDictionary<string, object> EmptyDictionary = new Dictionary<string, object>(); | ||
private readonly List<ITrace> children; | ||
private readonly Lazy<Dictionary<string, object>> data; | ||
|
||
public MergedTrace( | ||
List<ITrace> traces, | ||
DateTime startTime, | ||
TimeSpan elapsedTime, | ||
TraceSummary summary) | ||
{ | ||
this.children = traces; | ||
this.Id = Guid.NewGuid(); | ||
this.StartTime = startTime; | ||
this.Duration = elapsedTime; | ||
this.Summary = summary ?? throw new ArgumentNullException(nameof(summary)); | ||
this.data = new Lazy<Dictionary<string, object>>(); | ||
|
||
foreach (ITrace trace in traces) | ||
{ | ||
if (trace.Data.Count > 0 | ||
&& !this.data.Value.ContainsKey("Client Configuration") | ||
&& trace.Data.TryGetValue("Client Configuration", out object clientConfiguration)) | ||
{ | ||
this.data.Value.Add("Client Configuration", clientConfiguration); | ||
} | ||
trace.TryRemoveClientConfig(); | ||
|
||
if (this.data.Value.TryGetValue("totalRequestCharge", out object totalRequestCharge)) | ||
{ | ||
this.data.Value["totalRequestCharge"] = (double)totalRequestCharge + this.GetTraceRequestCharge(trace); | ||
} | ||
else | ||
{ | ||
this.data.Value.Add("totalRequestCharge", this.GetTraceRequestCharge(trace)); | ||
} | ||
} | ||
} | ||
|
||
private double GetTraceRequestCharge(ITrace trace) | ||
{ | ||
double requestCharge = 0; | ||
foreach (ITrace child in trace.Children) | ||
{ | ||
if (child.Data.TryGetValue("Client Side Request Stats", out object clientSideRequestStats)) | ||
{ | ||
foreach (StoreResponseStatistics storeResponseStatistics in ((ClientSideRequestStatisticsTraceDatum)clientSideRequestStats).StoreResponseStatisticsList) | ||
{ | ||
requestCharge += storeResponseStatistics.StoreResult.RequestCharge; | ||
} | ||
} | ||
else | ||
{ | ||
requestCharge += this.GetTraceRequestCharge(child); | ||
} | ||
} | ||
|
||
return requestCharge; | ||
} | ||
public string Name => "Multi-request Trace Instance: " + this.Id.ToString(); | ||
|
||
public Guid Id { get; } | ||
|
||
public DateTime StartTime { get; } | ||
|
||
public TimeSpan Duration { get; } | ||
|
||
public TraceLevel Level => default; | ||
|
||
public TraceComponent Component => default; | ||
|
||
public TraceSummary Summary { get; } | ||
|
||
public ITrace Parent => null; | ||
|
||
public IReadOnlyList<ITrace> Children => this.children; | ||
|
||
public IReadOnlyDictionary<string, object> Data => this.data.IsValueCreated ? this.data.Value : MergedTrace.EmptyDictionary; | ||
|
||
public void AddChild(ITrace child) | ||
{ | ||
lock (this.children) | ||
{ | ||
this.children.Add(child); | ||
} | ||
} | ||
|
||
public void AddDatum(string key, TraceDatum traceDatum) | ||
{ | ||
this.data.Value.Add(key, traceDatum); | ||
this.Summary.UpdateRegionContacted(traceDatum); | ||
} | ||
|
||
public void AddDatum(string key, object value) | ||
{ | ||
this.data.Value.Add(key, value); | ||
} | ||
|
||
public void AddOrUpdateDatum(string key, object value) | ||
{ | ||
this.data.Value[key] = value; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// No Op | ||
} | ||
|
||
public ITrace StartChild( | ||
string name) | ||
{ | ||
return this.StartChild( | ||
name, | ||
component: this.Component, | ||
level: TraceLevel.Info); | ||
} | ||
|
||
public ITrace StartChild( | ||
string name, | ||
TraceComponent component, | ||
TraceLevel level) | ||
{ | ||
return this; | ||
} | ||
|
||
public bool TryRemoveClientConfig() | ||
{ | ||
return this.data.Value.Remove("Client Configuration"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the summary for every merge?
ex:
ReadItem -> Inside RequestInvoker, will it include a summary?
Queries -> Which might go multiple NW interactions, will every interaction have its own summary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summar of offline sync-up: For initial version having the simple version with hint/context to dis-ambiguate if it's a hedging or not is good enough.