Skip to content

Add Support For Multiplexing System.Diagnostics.Metrics for Dotnet Monitor and Dotnet Counters#3889

Merged
davmason merged 18 commits intodotnet:mainfrom
kkeirstead:kkeirstead/Multiplexing_2
Aug 3, 2023
Merged

Add Support For Multiplexing System.Diagnostics.Metrics for Dotnet Monitor and Dotnet Counters#3889
davmason merged 18 commits intodotnet:mainfrom
kkeirstead:kkeirstead/Multiplexing_2

Conversation

@kkeirstead
Copy link
Member

@kkeirstead kkeirstead commented May 19, 2023

This PR corresponds to dotnet/runtime#86504 from the runtime repo to support multiplexing for System.Diagnostics.Metrics. This change converts dotnet monitor and dotnet counters to use a shared session, assuming the MaxHistograms, MaxTimeSeries, and IntervalSeconds are all the same. The code is in a functional state for anyone who wants to interact with it locally; however, there may still be some bugs (I haven't done extensive testing yet).

I'll call attention to specific areas where I'm looking for feedback via comments.

@wiktork @davmason @noahfalk

…testing. Added quick filter to diagnostics so that it doesn't include irrelevant meters/instruments
@kkeirstead kkeirstead marked this pull request as ready for review June 16, 2023 20:24
@kkeirstead kkeirstead requested a review from a team as a code owner June 16, 2023 20:24
@tommcdon tommcdon requested review from davmason and noahfalk July 7, 2023 16:03
@kkeirstead
Copy link
Member Author

@davmason Any changes you'd like to see for this one?

@davmason
Copy link
Contributor

davmason commented Jul 9, 2023

With this update we will only ever use the SHARED session ID, is that a valid ID on previous runtimes that don't have shared session support? We can still run against 6 and 7

@kkeirstead
Copy link
Member Author

With this update we will only ever use the SHARED session ID, is that a valid ID on previous runtimes that don't have shared session support? We can still run against 6 and 7

Good point - while it will work, it does create an issue where the MultipleSessionNotSupportedError is disregarded (assuming both sessions use "SHARED" as the session ID). Is there a pattern I should follow for having this behavior for 8+, but still create a GUID as the session ID for 6/7?

@davmason
Copy link
Contributor

I don't think we have any existing code that checks the runtime version, generally either the command is available or it isn't. But the DiagnosticsClient has a GetRuntimeInfo that will return the runtime version that you could use to determine if it supports multiplexing or not

Copy link
Member

@wiktork wiktork left a comment

Choose a reason for hiding this comment

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

Approved with a few comments.

ClientId = Guid.NewGuid().ToString();

// Shared Session Id was added in 8.0 - older runtimes will not properly support it.
SessionId = (version != null && version.Major >= 8) ? SharedSessionId : Guid.NewGuid().ToString();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is assuming the runtime is coreclr; is there an affordance for mono? Not sure if there is a way to detect that from the perspective of an out-of-proc diagnostic tool.

Copy link
Member Author

Choose a reason for hiding this comment

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

@noahfalk Would you be able to weigh in on this or point me in the right direction to investigate this further?

Copy link
Contributor

Choose a reason for hiding this comment

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

Mono uses the same System.Private.CoreLib as coreclr, unless we specifically did something to exclude mono from using the metrics stuff I would expect it to be on mono too

Copy link
Member

Choose a reason for hiding this comment

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

Is version refering to the assembly version of System.Diagnostics.DiagnosticSource.dll? Assuming it is that then there should be no difference between Mono, CLR, or any other runtime because they are all sharing the same S.D.DiagnosticSource assembly that has the same version.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is version refering to the assembly version of System.Diagnostics.DiagnosticSource.dll? Assuming it is that then there should be no difference between Mono, CLR, or any other runtime because they are all sharing the same S.D.DiagnosticSource assembly that has the same version.

From an out-or-proc perspective, we can't get the assembly version, especially not in multi-container environments. This version seems to be the runtime version, which would be 8.0.0 for CoreCLR but that may not be true for Mono.

Copy link
Contributor

Choose a reason for hiding this comment

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

For dotnet-monitor does that mean the same version check is just happening in a different place in the code, or it actually changes how we'd do the check? I was more looking at would the check produce a useful result rather than where the check occurs. If dotnet-monitor doesn't get the new behavior for .NET 6.0 apps running 8.0 DiagnosticSource I'm not going to lose sleep over it.

I'm not sure we have much of an option here for .NET Monitor. We would need some way of interrogating the app folder in the file system in order to find that particular assembly and get its version. And consider that against the runtime version of in is less than 8. This would require a new diagnostic command that would get us the assembly information from the app folder.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm not aware you have a good alternative. Long term we could of course add one, but also long term it won't matter because all the builds that had an assembly specific version check would also have DiagnosticSource 8.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jander-msft I made the change to remove the version logic from MetricSourceConfiguration - let me know if that's what you wanted.

It sounds like on the dotnet-monitor side of things we've settled on checking that the runtime version >= 8, but the dotnet counters logic is still up in the air. If there's concerns about the granularity/correctness of the current logic that will require more investigation, Justin and I were chatting yesterday about temporarily disabling the SHARED session in dotnet-counters as part of this PR. If we go that route, I could either pull all the new logic out of CounterMonitor to revert it to its existing state, or I could leave it in and we never toggle the SHARED switch (this would be leaving unused code behind, but if the expectation is that this would be enabled in the near future, everything would already be rigged up correctly). I've left it as-is for now, but just let me know if there's any action you want me to take and I'll push another update.

Copy link
Member

Choose a reason for hiding this comment

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

I'm happy to have @davmason make the call.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the mono question, from my research it looks like the mono version will be 8.0 (match the coreclr version).

For the dotnet-counters logic, I think matching dotnet-monitor is fine and we don't need special logic.

@kkeirstead
Copy link
Member Author

@noahfalk @davmason Let me know if you want any more changes - otherwise would one of you be able to merge this in?

@davmason davmason merged commit ca5a030 into dotnet:main Aug 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants