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

Diagnostic Visitors #1156

Merged
merged 5 commits into from
Jan 24, 2020
Merged

Diagnostic Visitors #1156

merged 5 commits into from
Jan 24, 2020

Conversation

bchong95
Copy link
Contributor

Diagnostic Visitors

Description

This PR adds visitor to CosmosDiagnostics. This ensures that for the abstract type CosmosDiagnostics the compute gateway can handle every derived type (or else there will be a compile time error). BackendMetricsExtractor is an example of this. This essentially turns a soft contract into a hard contract. I added CosmosDiagnosticsInternal to extend CosmosDiagnostics, but for internal use only.

@@ -123,6 +124,36 @@ sealed class BackendMetrics
/// </summary>
public TimeSpan VMExecutionTime { get; }

public override string ToString()
{
return $"totalExecutionTimeInMs={this.TotalTime.TotalMilliseconds};" +
Copy link
Contributor

@j82w j82w Jan 16, 2020

Choose a reason for hiding this comment

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

Use StringBuilder this is going to cause to much perf overhead. #Resolved

@bchong95 bchong95 self-assigned this Jan 22, 2020
}

internal void AddContextWriter(CosmosDiagnosticWriter diagnosticWriter)
internal void AddContextWriter(CosmosDiagnosticsInternal diagnosticWriter)
Copy link
Contributor

@j82w j82w Jan 23, 2020

Choose a reason for hiding this comment

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

AddDiagnosticsInternal ? #Resolved

this.jsonWriter = new JsonTextWriter(textWriter ?? throw new ArgumentNullException(nameof(textWriter)));
}

public override void Visit(PointOperationStatistics pointOperationStatistics)
Copy link
Contributor

@j82w j82w Jan 23, 2020

Choose a reason for hiding this comment

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

Did this make any changes to the output string? If so can you provide an example in the description. #Resolved

/// <summary>
/// Extracts the aggregated <see cref="BackendMetrics"/> from a <see cref="CosmosDiagnostics"/>.
/// </summary>
internal sealed class BackendMetricsExtractor : CosmosDiagnosticsInternalVisitor<(bool, BackendMetrics)>
Copy link
Contributor

@sboshra sboshra Jan 23, 2020

Choose a reason for hiding this comment

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

(bool, BackendMetrics [](start = 85, length = 21)

Nullable #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went for failure reason instead.


In reply to: 369908025 [](ancestors = 369908025)

/// <summary>
/// Extracts the aggregated <see cref="BackendMetrics"/> from a <see cref="CosmosDiagnostics"/>.
/// </summary>
internal sealed class BackendMetricsExtractor : CosmosDiagnosticsInternalVisitor<(bool, BackendMetrics)>
Copy link
Contributor

@sboshra sboshra Jan 23, 2020

Choose a reason for hiding this comment

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

bool [](start = 86, length = 4)

enum for the failure reason #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call :)


In reply to: 369908749 [](ancestors = 369908749)

if (!this.isDisposed)
{
return false;
}
Copy link
Contributor

@sboshra sboshra Jan 23, 2020

Choose a reason for hiding this comment

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

I think we should not have a TryGet method here; rather, we should return whatever value the stopwatch has #Resolved

Copy link
Contributor

@j82w j82w Jan 23, 2020

Choose a reason for hiding this comment

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

It's better to have a TryGet. It's misleading if it returns the current elapsed time if the operation was never disposed of or still hasn't completed if there is a background task then it causes it to be ambiguous. #Resolved

{
CosmosDiagnosticsSerializerVisitor cosmosDiagnosticsSerializerVisitor = new CosmosDiagnosticsSerializerVisitor(textWriter);
this.Accept(cosmosDiagnosticsSerializerVisitor);
}
Copy link
Contributor

@sboshra sboshra Jan 23, 2020

Choose a reason for hiding this comment

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

consider moving this to the base class #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The base class doesn't have the visitor methods that are needed for this


In reply to: 369911329 [](ancestors = 369911329)

sboshra
sboshra previously approved these changes Jan 23, 2020
Copy link
Contributor

@sboshra sboshra left a comment

Choose a reason for hiding this comment

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

:shipit:

@@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos.Tests
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
Copy link
Member

@kirankumarkolli kirankumarkolli Jan 23, 2020

Choose a reason for hiding this comment

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

undo?
Similar places #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The namespace was changed intentionally to match the file structure


In reply to: 369949865 [](ancestors = 369949865)

@sboshra sboshra merged commit 04e6f5b into master Jan 24, 2020
@sboshra sboshra deleted the users/brchon/DiagnosticVisitors branch January 24, 2020 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants