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

[POC] AAD: Configuring ServerTelemetryChannel and QuickPulseServiceClient #2220

Closed
wants to merge 116 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
84eba5c
getting started. defining classes and tests
TimothyMothra Mar 11, 2021
180c039
more tests. currently passing
TimothyMothra Mar 12, 2021
d501eef
cleanup
TimothyMothra Mar 12, 2021
5a556d3
saving work in progress
TimothyMothra Mar 23, 2021
2f7f7f8
cleanup
TimothyMothra Mar 24, 2021
9beac17
cleanup
TimothyMothra Mar 24, 2021
14b65b2
cleanup
TimothyMothra Mar 24, 2021
8446075
save work in progress. all tests passing
TimothyMothra Mar 24, 2021
0fe4b8c
cleanup
TimothyMothra Mar 24, 2021
52785bb
change interface to abstract class.
TimothyMothra Mar 25, 2021
acb3fd0
cleanup
TimothyMothra Mar 25, 2021
66592c9
working reflection for GetTokenAsync
TimothyMothra Mar 25, 2021
33570ec
cleanup. tests pass
TimothyMothra Mar 25, 2021
f181df5
cleanup
TimothyMothra Mar 26, 2021
7b30407
rewriting reflection to fully use Expression.Lambda. tests partially …
TimothyMothra Mar 27, 2021
4e38ac2
cleanup
TimothyMothra Mar 29, 2021
862d3f2
change from Lambda<Func> to LambdaExpression. Tests pass
TimothyMothra Mar 29, 2021
ddcbecd
have a working example of aysnc + Expression tree. need to cleanup
TimothyMothra Mar 30, 2021
0a82f7b
this works. tests pass. needs significant cleanup.
TimothyMothra Mar 30, 2021
47ce7e5
significant refactor. cleanup. all tests pass
TimothyMothra Mar 30, 2021
76fd2d7
update scope
TimothyMothra Mar 31, 2021
c5e44de
save change to publicapi doc
TimothyMothra Mar 31, 2021
46f35e6
cleanup
TimothyMothra Mar 31, 2021
dade297
TokenCredential + QuickPulse
TimothyMothra Apr 5, 2021
2464125
set default in abstract class
TimothyMothra Apr 5, 2021
c387eaa
update header key
TimothyMothra Apr 8, 2021
9f5e579
finished mapping out how to set CredentialEnvelope on all TelemetryCh…
TimothyMothra Apr 9, 2021
f2ac1d8
update request header. move to constants
TimothyMothra Apr 13, 2021
8a93434
Merge branch 'develop' into tilee/feature_aad
TimothyMothra Apr 14, 2021
159bbc9
update publicapi
TimothyMothra Apr 14, 2021
8061c8c
Merge branch 'tilee/feature_aad' into tilee/feature_aad_w_config
TimothyMothra Apr 14, 2021
d43a0a6
sample app and some minor fixes
TimothyMothra Apr 15, 2021
39632eb
fix
TimothyMothra Apr 15, 2021
f03f03f
Merge branch 'develop' into tilee/feature_aad
TimothyMothra Apr 15, 2021
fe3ad16
Merge branch 'tilee/feature_aad' into tilee/feature_aad_w_config
TimothyMothra Apr 15, 2021
8a498d5
remove sample app
TimothyMothra Apr 15, 2021
67d2780
remove samples app
TimothyMothra Apr 15, 2021
4f2a33d
undo
TimothyMothra Apr 15, 2021
5ad8a6d
fix
TimothyMothra Apr 15, 2021
7940b0f
changing scope
TimothyMothra Apr 15, 2021
740c1d0
merge develop
TimothyMothra Apr 28, 2021
e8316e0
merge develop
TimothyMothra Apr 28, 2021
e3cefeb
fxcop
TimothyMothra Apr 30, 2021
003873b
Merge branch 'develop' into tilee/feature_aad
TimothyMothra May 7, 2021
1ff482a
fix dependencies
TimothyMothra May 7, 2021
87876f2
fix dependencies
TimothyMothra May 7, 2021
930ef53
Merge branch 'develop' into tilee/feature_aad
TimothyMothra May 20, 2021
c9735a9
add new project
TimothyMothra May 20, 2021
b0b4b7e
add .Net v5 to linux build definition
TimothyMothra May 20, 2021
ca89417
cleanup
TimothyMothra May 20, 2021
5a4d63e
testing change to linux definition
TimothyMothra May 20, 2021
e4050ec
add support for net5.0 to Microsoft.ApplicationInsights.Tests.csproj
TimothyMothra May 20, 2021
5773479
fix for TimeSpan cannot be null
TimothyMothra May 20, 2021
926a6e7
fix
TimothyMothra May 20, 2021
0412341
remove extra test project
TimothyMothra May 20, 2021
0bcd87f
cleanup yml
TimothyMothra May 20, 2021
57088cb
disabling netcoreapp 2.1 in linux build.
TimothyMothra May 20, 2021
bbecdd8
Merge branch 'tilee/aad_newtestproject' into tilee/feature_aad
TimothyMothra May 20, 2021
a7c3462
migrate AAD tests to Base Test project
TimothyMothra May 21, 2021
5d6011a
update Endpoints for Ingestion
TimothyMothra May 21, 2021
edb4e57
merge develop
TimothyMothra May 21, 2021
d4b0378
moving tests to Base Test project
TimothyMothra May 21, 2021
a82e321
remove Authentication.Test project
TimothyMothra May 21, 2021
393f0a2
remove change to AssemblyInfo
TimothyMothra May 21, 2021
0bf32ba
resolving merge conflict
TimothyMothra May 21, 2021
f1e7a4f
Merge branch 'tilee/feature_aad' into tilee/feature_aad_w_config
TimothyMothra May 21, 2021
6d8a741
implementing the ingestion api switch. Needs tests
TimothyMothra May 21, 2021
5e3ef5d
Revert "resolving merge conflict"
TimothyMothra May 24, 2021
dbe07d0
Merge branch 'develop' into tilee/feature_aad
TimothyMothra May 24, 2021
dc11249
Merge branch 'develop' into tilee/feature_aad
TimothyMothra May 26, 2021
7d6ad67
remove Azure.Core dependency
TimothyMothra May 26, 2021
2f3b668
cleanup csproj
TimothyMothra May 26, 2021
4b9b761
cleanup EOF
TimothyMothra May 26, 2021
4cf03ca
cleanup test
TimothyMothra May 26, 2021
62bbe38
cleanup. removing abstract class CredentialEnvelope
TimothyMothra May 26, 2021
aac78ed
fxcop
TimothyMothra May 26, 2021
d70ce25
merge tilee/feature_aad
TimothyMothra May 26, 2021
080220f
merge conflict
TimothyMothra May 26, 2021
06132de
resolve merge conflicts
TimothyMothra May 26, 2021
ad1f387
revert changes to EndpointContainer
TimothyMothra May 26, 2021
52d8d2f
merge tilee/feature_aad
TimothyMothra May 26, 2021
7bfe41e
add interface ICredentialEnvelope
TimothyMothra May 26, 2021
6b00f3b
exception handling
TimothyMothra May 26, 2021
957f33f
set ConfigureAwait(true)
TimothyMothra May 26, 2021
86deb20
Merge branch 'tilee/feature_aad' into tilee/feature_aad_w_config
TimothyMothra May 26, 2021
f04ae0f
change to ICredentialEnvelope
TimothyMothra May 26, 2021
f04d2bd
saving work in progress
TimothyMothra May 27, 2021
9c11def
saving work in progress
TimothyMothra May 27, 2021
a144672
merge develop
TimothyMothra May 27, 2021
0fc7613
merge conflicts
TimothyMothra May 27, 2021
0c9c2a2
merge conflicts
TimothyMothra May 27, 2021
fc97568
merge conflict.
TimothyMothra May 27, 2021
6acc5bb
fix tests
TimothyMothra May 27, 2021
3c1fcae
refactor
TimothyMothra May 28, 2021
2053371
AAD: refactor
TimothyMothra May 28, 2021
4ecdfc4
change property to internal
TimothyMothra May 28, 2021
728081e
Merge branch 'develop' into tilee/aad_refactor
TimothyMothra May 28, 2021
fc1895a
merge refactor branch
TimothyMothra May 28, 2021
8cdfde4
merge conflict
TimothyMothra May 28, 2021
f7a1d80
Merge branch 'develop' into tilee/feature_aad_w_config
TimothyMothra May 28, 2021
2006cad
rename param
TimothyMothra May 28, 2021
abf9b3c
aad with InMemoryChannel
TimothyMothra May 28, 2021
605b597
fix end of line
TimothyMothra May 28, 2021
cb2163d
configuration tests
TimothyMothra May 28, 2021
6d049fb
Transmission tests
TimothyMothra May 28, 2021
6e25d92
comments
TimothyMothra May 28, 2021
b077554
testing fix for InternalOperations
TimothyMothra May 28, 2021
7f0f929
fxcop
TimothyMothra May 28, 2021
eebc0a3
comment about InternalOperations
TimothyMothra May 28, 2021
8063dcf
cleanup
TimothyMothra May 28, 2021
025ca3c
merge branch tilee/aad_inmemorychannel
TimothyMothra May 29, 2021
a99b09c
merge conflict
TimothyMothra May 29, 2021
0f5dc3f
merge develop
TimothyMothra May 29, 2021
11c6a6b
merge conflicts
TimothyMothra May 29, 2021
461c9e7
cleanup
TimothyMothra May 29, 2021
95f485d
merge develop
TimothyMothra Jun 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions BASE/src/Microsoft.ApplicationInsights/Channel/InMemoryChannel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Microsoft.ApplicationInsights.Channel
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -15,7 +14,7 @@
/// Represents a communication channel for sending telemetry to Application Insights via HTTPS. There will be a buffer that will not be persisted, to enforce the
/// queued telemetry items to be sent, <see cref="ITelemetryChannel.Flush"/> should be called.
/// </summary>
public class InMemoryChannel : ITelemetryChannel, IAsyncFlushable
public class InMemoryChannel : ITelemetryChannel, IAsyncFlushable, ISupportCredentialEnvelope
{
private readonly TelemetryBuffer buffer;
private readonly InMemoryTransmitter transmitter;
Expand Down Expand Up @@ -96,6 +95,20 @@ public TimeSpan SendingInterval
}
}

/// <summary>
/// Gets or sets the <see cref="CredentialEnvelope"/> which is used for AAD.
/// FOR INTERNAL USE. Customers should use <see cref="TelemetryConfiguration.SetAzureTokenCredential"/> instead.
Copy link
Member

Choose a reason for hiding this comment

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

We don't really need this comment anymore since ISupportCredentialEnvelope is, itself, internal.

/// </summary>
/// <remarks>
/// <see cref="ISupportCredentialEnvelope.CredentialEnvelope"/> on <see cref="InMemoryChannel"/> sets <see cref="InMemoryTransmitter.CredentialEnvelope"/>
/// which is used to set <see cref="Transmission.CredentialEnvelope"/> just before calling <see cref="Transmission.SendAsync"/>.
/// </remarks>
CredentialEnvelope ISupportCredentialEnvelope.CredentialEnvelope
{
get => this.transmitter.CredentialEnvelope;
set => this.transmitter.CredentialEnvelope = value;
}

/// <summary>
/// Gets or sets the HTTP address where the telemetry is sent.
/// </summary>
Expand Down Expand Up @@ -126,20 +139,6 @@ public int BacklogSize
set { this.buffer.BacklogSize = value; }
}

/// <summary>
/// Gets or sets the <see cref="CredentialEnvelope"/> which is used for AAD.
/// FOR INTERNAL USE. Customers should use <see cref="TelemetryConfiguration.SetAzureTokenCredential"/> instead.
/// </summary>
/// <remarks>
/// <see cref="InMemoryChannel.CredentialEnvelope"/> sets <see cref="InMemoryTransmitter.CredentialEnvelope"/>
/// which is used to set <see cref="Transmission.CredentialEnvelope"/> just before calling <see cref="Transmission.SendAsync"/>.
/// </remarks>
internal CredentialEnvelope CredentialEnvelope
{
get => this.transmitter.CredentialEnvelope;
set => this.transmitter.CredentialEnvelope = value;
}

internal bool IsDisposed => this.isDisposed;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal TimeSpan SendingInterval
/// Gets or sets the <see cref="CredentialEnvelope"/> which is used for AAD.
/// </summary>
/// <remarks>
/// <see cref="InMemoryChannel.CredentialEnvelope"/> sets <see cref="InMemoryTransmitter.CredentialEnvelope"/>
/// <see cref="ISupportCredentialEnvelope.CredentialEnvelope"/> on <see cref="InMemoryChannel"/> sets <see cref="InMemoryTransmitter.CredentialEnvelope"/>
/// which is used to set <see cref="Transmission.CredentialEnvelope"/> just before calling <see cref="Transmission.SendAsync"/>.
/// </remarks>
internal CredentialEnvelope CredentialEnvelope { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication
{
/// <summary>
/// This interface defines a class that accepts the <see cref="Authentication.CredentialEnvelope"/> as a property.
/// </summary>
internal interface ISupportCredentialEnvelope
{
/// <summary>
/// Gets or sets the <see cref="Authentication.CredentialEnvelope"/>.
/// </summary>
CredentialEnvelope CredentialEnvelope { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ public string ConnectionString

/// <summary>
/// Gets an envelope for Azure.Core.TokenCredential which provides an AAD Authenticated token.
/// FOR INTERNAL USE ONLY. To set the Credential use <see cref="SetAzureTokenCredential"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public CredentialEnvelope CredentialEnvelope { get; private set; }

/// <summary>
Expand Down Expand Up @@ -504,9 +506,9 @@ private static void SetTelemetryChannelEndpoint(ITelemetryChannel channel, strin

private static void SetTelemetryChannelCredentialEnvelope(ITelemetryChannel telemetryChannel, CredentialEnvelope credentialEnvelope)
{
if (telemetryChannel is InMemoryChannel inMemoryChannel)
if (telemetryChannel is ISupportCredentialEnvelope tc)
{
inMemoryChannel.CredentialEnvelope = credentialEnvelope;
tc.CredentialEnvelope = credentialEnvelope;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ internal class ResponseStatusCodes
public const int BadGateway = 502;
public const int ServiceUnavailable = 503;
public const int GatewayTimeout = 504;
public const int Unauthorized = 401; // AAD
public const int Forbidden = 403; // AAD
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.ApplicationInsights.Common.Extensions;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication;

internal class TransmissionSender
{
Expand Down Expand Up @@ -107,6 +108,15 @@ public virtual int ThrottleWindow
}
}

/// <summary>
/// Gets or sets the <see cref="CredentialEnvelope"/> which is used for AAD.
Copy link
Member

Choose a reason for hiding this comment

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

Instead of "AAD", suggest "authorization" or "auth-token acquisition".

/// </summary>
/// <remarks>
/// <see cref="ISupportCredentialEnvelope.CredentialEnvelope"/> on <see cref="ServerTelemetryChannel"/> sets <see cref="Transmitter.CredentialEnvelope"/> and then sets <see cref="TransmissionSender.CredentialEnvelope"/>
/// which is used to set <see cref="Transmission.CredentialEnvelope"/> just before calling <see cref="Transmission.SendAsync"/>.
/// </remarks>
internal CredentialEnvelope CredentialEnvelope { get; set; }

public virtual bool Enqueue(Func<Transmission> transmissionGetter)
{
bool enqueueSucceded = false;
Expand Down Expand Up @@ -197,9 +207,11 @@ private async Task StartSending(Transmission transmission)
try
{
TelemetryChannelEventSource.Log.TransmissionSendStarted(acceptedTransmission.Id);
acceptedTransmission.CredentialEnvelope = this.CredentialEnvelope;

transmissionTask = acceptedTransmission.SendAsync();
this.inFlightTransmissions.TryAdd(transmission.FlushAsyncId, transmissionTask);
responseContent = await transmissionTask.ConfigureAwait(false);
responseContent = await transmissionTask.ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down
16 changes: 15 additions & 1 deletion BASE/src/ServerTelemetryChannel/Implementation/Transmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Channel.Implementation;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication;

/// <summary>
/// Implements throttled and persisted transmission of telemetry to Application Insights.
Expand Down Expand Up @@ -59,7 +60,7 @@ internal Transmitter(

public event EventHandler<TransmissionProcessedEventArgs> TransmissionSent;

public string StorageFolder { get; set; }
public string StorageFolder { get; set; }

public int MaxBufferCapacity
{
Expand Down Expand Up @@ -126,6 +127,19 @@ public BackoffLogicManager BackoffLogicManager
get { return this.backoffLogicManager; }
}

/// <summary>
/// Gets or sets the <see cref="CredentialEnvelope"/> which is used for AAD.
/// </summary>
/// <remarks>
/// <see cref="ISupportCredentialEnvelope.CredentialEnvelope"/> on <see cref="ServerTelemetryChannel"/> sets <see cref="Transmitter.CredentialEnvelope"/> and then sets <see cref="TransmissionSender.CredentialEnvelope"/>
/// which is used to set <see cref="Transmission.CredentialEnvelope"/> just before calling <see cref="Transmission.SendAsync"/>.
/// </remarks>
internal CredentialEnvelope CredentialEnvelope
{
get => this.Sender.CredentialEnvelope;
set => this.Sender.CredentialEnvelope = value;
}

/// <summary>
/// Releases resources used by this <see cref="Transmitter"/> instance.
/// </summary>
Expand Down
19 changes: 18 additions & 1 deletion BASE/src/ServerTelemetryChannel/ServerTelemetryChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Common;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication;
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation;
using TelemetryBuffer = Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation.TelemetryBuffer;

/// <summary>
/// Represents a communication channel for sending telemetry to Application Insights via HTTP/S.
/// </summary>
public sealed class ServerTelemetryChannel : ITelemetryChannel, IAsyncFlushable, ITelemetryModule
public sealed class ServerTelemetryChannel : ITelemetryChannel, IAsyncFlushable, ITelemetryModule, ISupportCredentialEnvelope
{
internal TelemetrySerializer TelemetrySerializer;
internal TelemetryBuffer TelemetryBuffer;
Expand Down Expand Up @@ -243,6 +244,20 @@ public int LocalThrottleWindow
set { this.Transmitter.ThrottleWindow = value; }
}

/// <summary>
/// Gets or sets the <see cref="CredentialEnvelope"/> which is used for AAD.
/// DO NOT SET DIRECTLY. Use <see cref="TelemetryConfiguration.SetAzureTokenCredential"/> instead.
/// </summary>
/// <remarks>
/// <see cref="ISupportCredentialEnvelope.CredentialEnvelope"/> on <see cref="ServerTelemetryChannel"/> sets <see cref="Transmitter.CredentialEnvelope"/> and then sets <see cref="TransmissionSender.CredentialEnvelope"/>
/// which is used to set <see cref="Transmission.CredentialEnvelope"/> just before calling <see cref="Transmission.SendAsync"/>.
/// </remarks>
CredentialEnvelope ISupportCredentialEnvelope.CredentialEnvelope
{
get => this.Transmitter.CredentialEnvelope;
set => this.Transmitter.CredentialEnvelope = value;
}

/// <summary>
/// Gets or sets first TelemetryProcessor in processor call chain.
/// </summary>
Expand Down Expand Up @@ -357,6 +372,8 @@ public void Initialize(TelemetryConfiguration configuration)
throw new ArgumentNullException(nameof(configuration));
}

((ISupportCredentialEnvelope)this).CredentialEnvelope = configuration.CredentialEnvelope;

this.Transmitter.Initialize();

if (this.EndpointAddress == null)
Expand Down
4 changes: 4 additions & 0 deletions examples/WebApp.AspNetCore/WebApp.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.4.0-beta.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\NETCORE\src\Microsoft.ApplicationInsights.AspNetCore\Microsoft.ApplicationInsights.AspNetCore.csproj" />
</ItemGroup>
Expand Down