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

feat: New Garbage Collection Metrics Sampler for .NET 6+ #2838

Merged
merged 15 commits into from
Oct 24, 2024

Conversation

tippmar-nr
Copy link
Member

@tippmar-nr tippmar-nr commented Oct 17, 2024

Description

Adds a new garbage collection metrics sampler that leverages the .NET APIs available in .NET 6 and later, instead of the existing (and somewhat error prone) Event Listener sampler. Available only for applications that target .NET 6 and later.

The new sampler is disabled by default but can be enabled either via newrelic.config:

<appSettings>
    <add key="GCSamplerV2Enabled" value="true" />
</appSettings>

or environment variable:

NEW_RELIC_GC_SAMPLER_V2_ENABLED=1

When the new sampler is enabled, the Event Listener sampler is disabled. Additionally, a supportability metric, Supportability/Dotnet/GCSamplerV2/Enabled is sent when the new sampler is enabled.

The set of garbage collection metrics reported by the new sampler are different from those reported by the Event Listener sampler, as detailed below:

Metric Event Listener Sampler Modern Sampler
GC/Handles ✔️
GC/Induced ✔️
GC/Gen0/Size ✔️ ✔️
GC/Gen0/Promoted ✔️
GC/Gen0/Collections ✔️ ✔️
GC/Gen0/Fragmentation ✔️
GC/Gen1/Size ✔️ ✔️
GC/Gen1/Promoted ✔️
GC/Gen1/Collections ✔️ ✔️
GC/Gen1/Fragmentation ✔️
GC/Gen2/Size ✔️ ✔️
GC/Gen2/Promoted ✔️
GC/Gen2/Survived ✔️
GC/Gen2/Collections ✔️ ✔️
GC/Gen2/Fragmentation ✔️
GC/LOH/Size ✔️ ✔️
GC/LOH/Survived ✔️
GC/LOH/Collections ✔️ ✔️
GC/LOH/Fragmentation ✔️
GC/POH/Size ✔️
GC/POH/Collections ✔️ ✔️
GC/POH/Fragmentation ✔️
GC/Heap/Total ✔️
GC/Heap/Committed ✔️
GC/Heap/Allocated ✔️

Author Checklist

  • Unit tests, Integration tests, and Unbounded tests completed
  • Performance testing completed with satisfactory results (if required)

Reviewer Checklist

  • Perform code review
  • Pull request was adequately tested (new/existing tests, performance tests)

@tippmar-nr tippmar-nr changed the title **DRAFT** feature: Modern Garbage Collection Metrics Sampler feature: Modern Garbage Collection Metrics Sampler Oct 21, 2024
@tippmar-nr tippmar-nr changed the title feature: Modern Garbage Collection Metrics Sampler feature: Modern Garbage Collection Metrics Sampler for .NET 6+ Oct 21, 2024
@tippmar-nr tippmar-nr marked this pull request as ready for review October 21, 2024 19:47
@tippmar-nr tippmar-nr requested a review from a team as a code owner October 21, 2024 19:47
@tippmar-nr tippmar-nr changed the title feature: Modern Garbage Collection Metrics Sampler for .NET 6+ feature: New Garbage Collection Metrics Sampler for .NET 6+ Oct 22, 2024
@chynesNR
Copy link
Member

If I'm following the code correctly, the first time through the PreviousSample will be empty, so the first delta report will always be a big spike. Would it be better to skip the first one to get a baseline?

@tippmar-nr
Copy link
Member Author

If I'm following the code correctly, the first time through the PreviousSample will be empty, so the first delta report will always be a big spike. Would it be better to skip the first one to get a baseline?

@chynesNR Originally, I had code in place to wait until at least once GC had completed before sending up any data - which pretty much matches what OTel is doing. I took that out a couple days ago because it didn't seem like our other GC samplers behaved that way. I can go either way with it. @nrcventura

chynesNR
chynesNR previously approved these changes Oct 24, 2024
@nrcventura
Copy link
Member

If I'm following the code correctly, the first time through the PreviousSample will be empty, so the first delta report will always be a big spike. Would it be better to skip the first one to get a baseline?

@chynesNR Originally, I had code in place to wait until at least once GC had completed before sending up any data - which pretty much matches what OTel is doing. I took that out a couple days ago because it didn't seem like our other GC samplers behaved that way. I can go either way with it. @nrcventura

I think either approach will ultimately be fine. However, if we do wait to report the first value, the charts might be able to scale themselves better.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 92.36641% with 20 lines in your changes missing coverage. Please review.

Project coverage is 81.43%. Comparing base (3afa15f) to head (bc74b10).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...Agent/Core/Samplers/GCSamplerV2ReflectionHelper.cs 68.88% 12 Missing and 2 partials ⚠️
....Agent.Extensions/Reflection/VisibilityBypasser.cs 82.60% 4 Missing ⚠️
...wRelic/Agent/Core/Config/BootstrapConfiguration.cs 89.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2838      +/-   ##
==========================================
+ Coverage   81.33%   81.43%   +0.09%     
==========================================
  Files         460      464       +4     
  Lines       29239    29496     +257     
  Branches     3231     3261      +30     
==========================================
+ Hits        23781    24019     +238     
- Misses       4666     4682      +16     
- Partials      792      795       +3     
Flag Coverage Δ
Agent 82.33% <92.36%> (+0.10%) ⬆️
Profiler 73.33% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...elic/Agent/Core/AgentHealth/AgentHealthReporter.cs 87.20% <100.00%> (+0.17%) ⬆️
...c/Agent/Core/Configuration/DefaultConfiguration.cs 89.58% <100.00%> (+0.01%) ⬆️
.../Agent/Core/Configuration/ReportedConfiguration.cs 95.74% <100.00%> (+0.01%) ⬆️
...ic/Agent/Core/DependencyInjection/AgentServices.cs 98.22% <100.00%> (+0.13%) ⬆️
...c/Agent/NewRelic/Agent/Core/Metrics/MetricNames.cs 92.15% <100.00%> (+0.28%) ⬆️
.../Agent/NewRelic/Agent/Core/Samplers/GCSamplerV2.cs 100.00% <100.00%> (ø)
...rc/Agent/NewRelic/Agent/Core/Samplers/GcSampler.cs 80.30% <ø> (-2.03%) ⬇️
.../NewRelic/Agent/Core/Samplers/ImmutableGCSample.cs 100.00% <100.00%> (ø)
...c/Agent/Core/Transformers/GCSampleTransformerV2.cs 100.00% <100.00%> (ø)
...wRelic/Agent/Core/Config/BootstrapConfiguration.cs 98.82% <89.47%> (-1.18%) ⬇️
... and 2 more

... and 2 files with indirect coverage changes

@tippmar-nr tippmar-nr changed the title feature: New Garbage Collection Metrics Sampler for .NET 6+ feat: New Garbage Collection Metrics Sampler for .NET 6+ Oct 24, 2024
@tippmar-nr tippmar-nr merged commit f24a5da into main Oct 24, 2024
101 checks passed
@tippmar-nr tippmar-nr deleted the feature/modern-gc-sampler branch October 24, 2024 21:23
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