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

Commit

Permalink
SDK connection strings (QuickPulse) (#1265)
Browse files Browse the repository at this point in the history
* work in progress

* tests are passing

* test init from config file

* quick pulse test improvements.
added helper class to build a configuration from xml.

* fxcop

* changelog

* merge conflict, restore tests

* resolve merge conflict

* update Defaults

* changelog

* name change
  • Loading branch information
TimothyMothra authored Oct 9, 2019
1 parent 4ae23aa commit 0320646
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 2.12.0-beta1
- [Enhancement to how QuickPulseTelemetryModule shares its ServiceEndpoint with QuickPulseTelemetryProcessor.](https://github.com/microsoft/ApplicationInsights-dotnet-server/pull/1266)
- [QuickPulse will support SDK Connection String](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1221)

## Version 2.11.0
- Updated Base SDK to 2.11.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void QuickPulseTelemetryModuleInitializesServiceClient_FromCode_WithDefau
{
// ARRANGE
var configuration = new TelemetryConfiguration();
var expectedEndpoint = QuickPulseDefaults.ServiceEndpoint;
var expectedEndpoint = QuickPulseDefaults.QuickPulseServiceEndpoint;

var module = new QuickPulseTelemetryModule(null, null, null, null, null, null);
TelemetryModules.Instance.Modules.Add(module);
Expand All @@ -145,7 +145,7 @@ public void QuickPulseTelemetryModuleInitializesServiceClient_FromConfigFile_Wit
{
// ARRANGE
var configuration = new TelemetryConfiguration();
var expectedEndpoint = QuickPulseDefaults.ServiceEndpoint;
var expectedEndpoint = QuickPulseDefaults.QuickPulseServiceEndpoint;

string configFileContents = TelemetryConfigurationFactoryHelper.BuildConfiguration(
module: @"<Add Type=""Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector""/>",
Expand Down Expand Up @@ -231,6 +231,64 @@ public void QuickPulseTelemetryModuleInitializesServiceClient_FromConfigFile_Wit
Assert.AreEqual(expectedEndpoint, processor.ServiceEndpoint.AbsoluteUri, "processor is invalid");
}

[TestMethod]
[TestCategory("QuickPulseEndpoint")]
[TestCategory("ConnectionString")]
public void QuickPulseTelemetryModuleInitializesServiceClient_WithConnectionString()
{
// ARRANGE
var explicitEndpoint = "https://127.0.0.1/";
var connectionString = $"InstrumentationKey=00000000-0000-0000-0000-000000000000;LiveEndpoint={explicitEndpoint}";
var expectedEndpoint = $"{explicitEndpoint}QuickPulseService.svc";

var configuration = new TelemetryConfiguration
{
ConnectionString = connectionString
};

var module = new QuickPulseTelemetryModule(null, null, null, null, null, null);
module.Initialize(configuration);
TelemetryModules.Instance.Modules.Add(module);
var processor = (IQuickPulseTelemetryProcessor)new QuickPulseTelemetryProcessor(new SimpleTelemetryProcessorSpy());

// ASSERT
Assert.IsInstanceOfType(module.ServiceClient, typeof(QuickPulseServiceClient));
Assert.AreEqual(expectedEndpoint, module.ServiceClient.ServiceUri.AbsoluteUri, "module is invalid");
Assert.AreEqual(expectedEndpoint, processor.ServiceEndpoint.AbsoluteUri, "processor is invalid");
}

[TestMethod]
[TestCategory("QuickPulseEndpoint")]
[TestCategory("ConnectionString")]
public void QuickPulseTelemetryModuleInitializesServiceClient_FromConfigFile_WithConnectionString()
{
// ARRANGE

var explicitEndpoint = "https://127.0.0.1/";
var connectionString = $"InstrumentationKey=00000000-0000-0000-0000-000000000000;LiveEndpoint={explicitEndpoint}";
var expectedEndpoint = $"{explicitEndpoint}QuickPulseService.svc";

var configuration = new TelemetryConfiguration();

string configFileContents = TelemetryConfigurationFactoryHelper.BuildConfiguration(
connectionString: connectionString,
module: @"<Add Type=""Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector""/>",
processor: @"<Add Type=""Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector""/>"
);
TelemetryConfigurationFactoryHelper.Initialize(configuration, TelemetryModules.Instance, configFileContents);

// ASSERT
var module = TelemetryModules.Instance.Modules.OfType<QuickPulseTelemetryModule>().SingleOrDefault();
Assert.IsNotNull(module, "module was not initialized");

var processor = configuration.TelemetryProcessors.OfType<IQuickPulseTelemetryProcessor>().SingleOrDefault();
Assert.IsNotNull(processor, "processor was not initialized");

Assert.IsInstanceOfType(module.ServiceClient, typeof(QuickPulseServiceClient));
Assert.AreEqual(expectedEndpoint, module.ServiceClient.ServiceUri.AbsoluteUri, "module is invalid");
Assert.AreEqual(expectedEndpoint, processor.ServiceEndpoint.AbsoluteUri, "processor is invalid");
}

[TestMethod]
public void QuickPulseTelemetryModuleDoesNothingWithoutInstrumentationKey()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

internal static class QuickPulseDefaults
{
private static readonly Uri QuickPulseServiceEndpoint = new Uri("https://rt.services.visualstudio.com/QuickPulseService.svc");
public static readonly Uri QuickPulseServiceEndpoint = new Uri("https://rt.services.visualstudio.com/QuickPulseService.svc");

/// <summary>
/// Dictionary of performance counters to collect for standard framework.
Expand Down Expand Up @@ -61,20 +61,6 @@ public static Dictionary<QuickPulseCounter, string> DefaultCountersToCollect
}
}

public static Uri ServiceEndpoint
{
get
{
return QuickPulseServiceEndpoint;
}
}

public static Dictionary<string, string> DefaultCounterOriginalStringMapping
{
get
{
return WebAppToStandardCounterMapping;
}
}
public static Dictionary<string, string> DefaultCounterOriginalStringMapping => WebAppToStandardCounterMapping;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ private void InitializeServiceClient(TelemetryConfiguration configuration)
Uri serviceEndpointUri;
if (string.IsNullOrWhiteSpace(this.QuickPulseServiceEndpoint))
{
// endpoint is not specified in configuration, use the default one
serviceEndpointUri = QuickPulseDefaults.ServiceEndpoint;
// endpoint is not explicitly specified, use the Endpoint from the TelemetryConfiguration (ex: https://rt.services.visualstudio.com/QuickPulseService.svc)
serviceEndpointUri = new Uri(configuration.EndpointContainer.Live, "QuickPulseService.svc");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Uri IQuickPulseTelemetryProcessor.ServiceEndpoint
set { this.serviceEndpoint = value; }
}

private Uri serviceEndpoint = QuickPulseDefaults.ServiceEndpoint;
private Uri serviceEndpoint = QuickPulseDefaults.QuickPulseServiceEndpoint;

private TelemetryConfiguration config = null;

Expand Down Expand Up @@ -719,7 +719,7 @@ private void RegisterSelfWithQuickPulseTelemetryModule()
if (module != null)
{
module.RegisterTelemetryProcessor(this);
this.serviceEndpoint = module.ServiceClient?.ServiceUri ?? QuickPulseDefaults.ServiceEndpoint;
this.serviceEndpoint = module.ServiceClient?.ServiceUri ?? QuickPulseDefaults.QuickPulseServiceEndpoint;
}
}
}
Expand Down

0 comments on commit 0320646

Please sign in to comment.