Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Ensure Heartbeat properties for App Services is included in AspNetCore #627

Merged
merged 10 commits into from
Apr 10, 2018

Conversation

d3r3kk
Copy link
Contributor

@d3r3kk d3r3kk commented Mar 30, 2018

Extension of issue microsoft/ApplicationInsights-dotnet-server#868 "Enabling Heartbeat in App Services..." in .NET Core scenarios.

  • I ran Unit Tests locally.
  • Changes in public surface reviewed
    • Add EnableHeartbeat to ApplicationInsightsServiceOptions, reviewed with @cijothomas
  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue.

@d3r3kk
Copy link
Contributor Author

d3r3kk commented Mar 30, 2018

Note that PR microsoft/ApplicationInsights-dotnet-server#873 must be submitted and available on myget before I will be able to successfully build this one. I've started this PR to facilitate code review prior to that condition being met.

EDIT: Changed PR to more current one.

@d3r3kk d3r3kk requested a review from cijothomas March 30, 2018 16:52
@d3r3kk d3r3kk self-assigned this Mar 30, 2018
@d3r3kk d3r3kk added this to the 2.3.0-beta1 milestone Mar 30, 2018
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.6.0-beta2-build12842" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.6.0-beta2-build12842" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" Version="2.6.0-beta2-build12842" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.6.0-beta2" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes will not be submitted. Once the PR in -dotnet-server completes I will update these references to the latest release there.

NuGet.config Outdated
@@ -4,6 +4,7 @@
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="applicationinsights" value="https://www.myget.org/F/applicationinsights/api/v3/index.json" />
<add key="Local" value="D:\dev\github\ai\bin\Debug\Nuget" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change will not be submitted. Only here for local development work while I wait for -dotnet-server to get posted to myget.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed this now, and have updated the dependencies to a myget package representing a more valid candidate for the next beta release here.

@d3r3kk
Copy link
Contributor Author

d3r3kk commented Apr 4, 2018

@cijothomas if you could take a look at this and provide a review I'd be grateful. Would very much like this to hit 2.6.0-beta3 timeframe.

  • Note the build should complete properly now, it's based off of MyGet packages from my PR in -dotnet-server.

EDIT: Added Note.

Copy link
Contributor

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

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

@@ -129,8 +131,8 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo
{
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

services.AddSingleton<ITelemetryInitializer, AzureWebAppRoleEnvironmentTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, DomainNameRoleInstanceTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, ApplicationInsights.AspNetCore.TelemetryInitializers.AzureWebAppRoleEnvironmentTelemetryInitializer>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be taken from the WindowsServer package? If not - aspnetcore and web might set different values for role name and role instance

Copy link
Contributor Author

@d3r3kk d3r3kk Apr 4, 2018

Choose a reason for hiding this comment

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

It most certainly can. I've added issue #624 to track this as a separate issue. There will need to be some work to consolidate the modules properly as the implementations have diverged.

EDIT: Updated to correct issue (I'd opened a duplicate)

// Disable heartbeat if user sets it (by default it is on)
if (!this.applicationInsightsServiceOptions.EnableHeartbeat)
{
foreach (var module in TelemetryModules.Instance.Modules)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this singleton be initialized at all in aspnetcore case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'm adding tests to prove that now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately ,no from my experiments and this issue
#506

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests added. Singleton is there, DiagnosticsTelemetryModule is there, and that is the IHeartbeatPropertyManager implementation at present.

Let's talk about a better public API for heartbeat in 2.7 timeframe.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just lucky(?) that only modules added from base sdk is present. (DiagnosticsTelemetryModule is added by base sdk)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is just lucky and we are indeed relying on the implementation details in the base SDK here.

Tests that I added are failing outside of the Visual Studio environment, I'm investigating now.

CHANGELOG.md Outdated
@@ -1,5 +1,8 @@
# Changelog

## Version 2.6.0-beta1
- [Add support for Heartbeat properties in AspNetCore. Add App Services and Azure Instanace Metedata heartbeat provider modules by default, support disable of heartbeats.](https://github.com/Microsoft/ApplicationInsights-aspnetcore/pull/627)
Copy link
Contributor

Choose a reason for hiding this comment

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

Metadata - spellcheck.
Add support for Heartbeat properties - we already had this support right? So just mention about the ability to turn-off hearbeat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

{
if (module is IHeartbeatPropertyManager hbeatMan)
{
hbeatMan.IsHeartbeatEnabled = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting IsHeartbeatEnabled to false will stop the HeartBeats collected/sent by the AppServicesHeartbeatTelemetryModule, AzureInstanceMetadataTelemetryModule modules as well - right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is the intention. Setting IsHeartbeatEnabled to false should disable heartbeats altogether.

Copy link
Contributor

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Blocking to prevent accidental merge.
Tests need to be addressed.

@d3r3kk
Copy link
Contributor Author

d3r3kk commented Apr 5, 2018

How do I debug my xUnit tests in .NET Core?

I can see the tests failing on the command line dotnet test Microsoft.ApplicationInsights.AspNetCore.Tests.csproj -l trx --no-build but I cannot seem to get this working in Visual Studio (probably due to issue #547). Unfortunately I'm forced to give up at this point and will resume sorting it out on Friday.

I've instrumented a .NET Core web app and will see if the thing behaves as expected tomorrow.

Is there any guidance that I can refer to on this matter? Multi-targeted framework solutions should probably be working in Visual Studio 2017...

@cijothomas
Copy link
Contributor

@d3r3kk What specific issue are you hitting with VS debugging? VS is not showing the tests in test runner/explorer? It shows the tets from the 1st target only. So if you are debugging net46, change the order so that net46 appears first.
https://github.com/Microsoft/ApplicationInsights-aspnetcore#testingdebugging

@d3r3kk d3r3kk force-pushed the dekeeler/appservice-heartbeats branch from 9b326b6 to 491bcad Compare April 7, 2018 08:51
@d3r3kk
Copy link
Contributor Author

d3r3kk commented Apr 8, 2018

@cijothomas Please re-review this change. I think I understand why the tests are failing but have not been able to step through in the debugger. Not sure why we are having this trouble, but moving to vstest might be superior in the long run.

@Dmitry-Matveev Dmitry-Matveev dismissed cijothomas’s stale review April 10, 2018 01:02

Tests are passing now. Other comments are addressed.

@d3r3kk d3r3kk merged commit a7c13ab into develop Apr 10, 2018
@d3r3kk d3r3kk deleted the dekeeler/appservice-heartbeats branch April 10, 2018 01:11
@d3r3kk
Copy link
Contributor Author

d3r3kk commented Apr 10, 2018

We are in. @cijothomas and @MS-TimothyMothra to help sort out versioning and such...

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.

3 participants