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

[App Insights] Adding Data Plane SDK #4088

Merged
merged 15 commits into from
Mar 1, 2018
Merged
30 changes: 29 additions & 1 deletion src/SDKs/ApplicationInsights/ApplicationInsights.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationInsights.Tests", "ApplicationInsights.Tests\ApplicationInsights.Tests.csproj", "{D0BC5FFA-C113-4212-BE4A-F95CC8BB4D91}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Management.ApplicationInsights", "Management.ApplicationInsights\Microsoft.Azure.Management.ApplicationInsights.csproj", "{4A1E2ACF-218C-481F-A501-7BB3F3C0B873}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.ApplicationInsights", "Data.ApplicationInsights\Microsoft.Azure.ApplicationInsights.csproj", "{BC9AA77F-1605-4386-B04E-368B1363F395}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data.ApplicationInsights.Tests", "Data.ApplicationInsights.Tests\Data.ApplicationInsights.Tests.csproj", "{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,6 +45,30 @@ Global
{4A1E2ACF-218C-481F-A501-7BB3F3C0B873}.Portable-Release|Any CPU.Build.0 = Release|Any CPU
{4A1E2ACF-218C-481F-A501-7BB3F3C0B873}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A1E2ACF-218C-481F-A501-7BB3F3C0B873}.Release|Any CPU.Build.0 = Release|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Net45-Release|Any CPU.Build.0 = Release|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Portable-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Portable-Debug|Any CPU.Build.0 = Debug|Any CPU
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the intention behind building against portable configurations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None -- not sure when this snuck in. I removed it while changing up the directory structure.

{BC9AA77F-1605-4386-B04E-368B1363F395}.Portable-Release|Any CPU.ActiveCfg = Release|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Portable-Release|Any CPU.Build.0 = Release|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC9AA77F-1605-4386-B04E-368B1363F395}.Release|Any CPU.Build.0 = Release|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Net45-Release|Any CPU.Build.0 = Release|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Portable-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Portable-Debug|Any CPU.Build.0 = Debug|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Portable-Release|Any CPU.ActiveCfg = Release|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Portable-Release|Any CPU.Build.0 = Release|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EE7F43C-EB97-46D0-B716-C972BBB8DEBB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" />
<PropertyGroup>
<PackageId>Data.ApplicationInsights.Tests</PackageId>
<Description>Data.ApplicationInsights.Tests Class library</Description>
<PackageId>Data.ApplicationInsights.Tests</PackageId>
<VersionPrefix>1.0.0-preview</VersionPrefix>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Update="SessionRecords\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="[1.6.0-preview, 2.0.0)" />
<ProjectReference Include="..\Data.ApplicationInsights\Microsoft.Azure.ApplicationInsights.csproj" />
<!-- Enable below line in local to work around the bug that cannot find test cases -->
<!--<PackageReference Update="Microsoft.NET.Test.Sdk" Version="15.3.0" />-->
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Azure.ApplicationInsights;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;

namespace Data.ApplicationInsights.Tests
{
public abstract class DataPlaneTestBase
{
protected const string DefaultAppId = "DEMO_APP";
protected const string DefaultApiKey = "DEMO_KEY";

protected ApplicationInsightsDataClient GetClient(MockContext ctx, string appId = DefaultAppId, string apiKey = DefaultApiKey)
{
var credentials = new ApiKeyClientCredentials(apiKey);
var client = new ApplicationInsightsDataClient(credentials, HttpMockServer.CreateInstance());
client.AppId = appId;
client.BaseUri = new Uri("https://api.applicationinsights.io/v1");

return client;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Data.ApplicationInsights.Tests.Events;
using Microsoft.Azure.ApplicationInsights;
using Microsoft.Azure.ApplicationInsights.Models;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Newtonsoft.Json;
using Xunit;

namespace Data.ApplicationInsights.Tests.ScenarioTests.Events
{
public class EventsExtensionTests : EventsTestBase
{
[Theory]
[MemberData(nameof(TraceData))]
[MemberData(nameof(CustomEventsData))]
[MemberData(nameof(PageViewsData))]
[MemberData(nameof(BrowserTimingsData))]
[MemberData(nameof(RequestsData))]
[MemberData(nameof(DependenciesData))]
[MemberData(nameof(ExceptionsData))]
[MemberData(nameof(AvailabilityResultsData))]
[MemberData(nameof(PerformanceCountersData))]
[MemberData(nameof(CustomMetricsData))]
public async Task GetEventsAsync<T>(EventType eventType, MultiQueryAsync<T> multiQueryAsync, SingleQueryAsync<T> singleQueryAsync,
object unused1, object unused2) where T : EventsResultData
{
using (var ctx = MockContext.Start(GetType().FullName, $"GetEvents.{eventType}"))
{
var timespan = new TimeSpan(12, 0, 0);
var top = 10;

var client = GetClient(ctx);
var events = await multiQueryAsync(client, timespan, top);

Assert.NotNull(events);
Assert.NotNull(events.Value);
Assert.True(events.Value.Count > 0);
Assert.True(events.Value.Count <= top);

foreach (var e in events.Value)
{
AssertEvent(e, eventType);
}

Assert.True(!string.IsNullOrEmpty(events.Value[0].Id));

var evnt = await singleQueryAsync(client, events.Value[0].Id, timespan);

Assert.NotNull(evnt);
Assert.NotNull(evnt.Value);
Assert.True(evnt.Value.Count == 1);

Assert.Equal(JsonConvert.SerializeObject(evnt.Value[0]),
JsonConvert.SerializeObject(events.Value[0]));
}
}

[Theory]
[MemberData(nameof(TraceData))]
[MemberData(nameof(CustomEventsData))]
[MemberData(nameof(PageViewsData))]
[MemberData(nameof(BrowserTimingsData))]
[MemberData(nameof(RequestsData))]
[MemberData(nameof(DependenciesData))]
[MemberData(nameof(ExceptionsData))]
[MemberData(nameof(AvailabilityResultsData))]
[MemberData(nameof(PerformanceCountersData))]
[MemberData(nameof(CustomMetricsData))]
public void GetEvents<T>(EventType eventType, object unused1, object unused2,
MultiQuery<T> multiQuery, SingleQuery<T> singleQuery) where T : EventsResultData
{
using (var ctx = MockContext.Start(GetType().FullName, $"GetEvents.{eventType}"))
{
var timespan = new TimeSpan(12, 0, 0);
var top = 10;

var client = GetClient(ctx);
var events = multiQuery(client, timespan, top);

Assert.NotNull(events);
Assert.NotNull(events.Value);
Assert.True(events.Value.Count > 0);
Assert.True(events.Value.Count <= top);

foreach (var e in events.Value)
{
AssertEvent(e, eventType);
}

Assert.True(!string.IsNullOrEmpty(events.Value[0].Id));

var evnt = singleQuery(client, events.Value[0].Id, timespan);

Assert.NotNull(evnt);
Assert.NotNull(evnt.Value);
Assert.True(evnt.Value.Count == 1);

Assert.Equal(JsonConvert.SerializeObject(evnt.Value[0]),
JsonConvert.SerializeObject(events.Value[0]));
}
}

public delegate Task<EventsResults<T>> MultiQueryAsync<T>(ApplicationInsightsDataClient client, System.TimeSpan? timespan, int top) where T : EventsResultData;
public delegate Task<EventsResults<T>> SingleQueryAsync<T>(ApplicationInsightsDataClient client, string id, System.TimeSpan? timespan) where T : EventsResultData;

public delegate EventsResults<T> MultiQuery<T>(ApplicationInsightsDataClient client, System.TimeSpan? timespan, int top) where T : EventsResultData;
public delegate EventsResults<T> SingleQuery<T>(ApplicationInsightsDataClient client, string id, System.TimeSpan? timespan) where T : EventsResultData;

private static readonly object[] TraceParams = new object[]
{
EventType.Traces,
new MultiQueryAsync<EventsTraceResult>(async (client, timespan, top) => await client.GetTraceEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsTraceResult>(async (client, id, timespan) => await client.GetTraceEventAsync(id, timespan)),
new MultiQuery<EventsTraceResult>((client, timespan, top) => client.GetTraceEvents(timespan, top: top)),
new SingleQuery<EventsTraceResult>((client, id, timespan) => client.GetTraceEvent(id, timespan)),
};

private static readonly object[] CustomEventsParams = new object[]
{
EventType.CustomEvents,
new MultiQueryAsync<EventsCustomEventResult>(async (client, timespan, top) => await client.GetCustomEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsCustomEventResult>(async (client, id, timespan) => await client.GetCustomEventAsync(id, timespan)),
new MultiQuery<EventsCustomEventResult>((client, timespan, top) => client.GetCustomEvents(timespan, top: top)),
new SingleQuery<EventsCustomEventResult>((client, id, timespan) => client.GetCustomEvent(id, timespan)),
};

private static readonly object[] PageViewsParams = new object[]
{
EventType.PageViews,
new MultiQueryAsync<EventsPageViewResult>(async (client, timespan, top) => await client.GetPageViewEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsPageViewResult>(async (client, id, timespan) => await client.GetPageViewEventAsync(id, timespan)),
new MultiQuery<EventsPageViewResult>((client, timespan, top) => client.GetPageViewEvents(timespan, top: top)),
new SingleQuery<EventsPageViewResult>((client, id, timespan) => client.GetPageViewEvent(id, timespan)),
};

private static readonly object[] BrowserTimingsParams = new object[]
{
EventType.BrowserTimings,
new MultiQueryAsync<EventsBrowserTimingResult>(async (client, timespan, top) => await client.GetBrowserTimingEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsBrowserTimingResult>(async (client, id, timespan) => await client.GetBrowserTimingEventAsync(id, timespan)),
new MultiQuery<EventsBrowserTimingResult>((client, timespan, top) => client.GetBrowserTimingEvents(timespan, top: top)),
new SingleQuery<EventsBrowserTimingResult>((client, id, timespan) => client.GetBrowserTimingEvent(id, timespan)),
};

private static readonly object[] RequestsParams = new object[]
{
EventType.Requests,
new MultiQueryAsync<EventsRequestResult>(async (client, timespan, top) => await client.GetRequestEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsRequestResult>(async (client, id, timespan) => await client.GetRequestEventAsync(id, timespan)),
new MultiQuery<EventsRequestResult>((client, timespan, top) => client.GetRequestEvents(timespan, top: top)),
new SingleQuery<EventsRequestResult>((client, id, timespan) => client.GetRequestEvent(id, timespan)),
};

private static readonly object[] DependenciesParams = new object[]
{
EventType.Dependencies,
new MultiQueryAsync<EventsDependencyResult>(async (client, timespan, top) => await client.GetDependencyEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsDependencyResult>(async (client, id, timespan) => await client.GetDependencyEventAsync(id, timespan)),
new MultiQuery<EventsDependencyResult>((client, timespan, top) => client.GetDependencyEvents(timespan, top: top)),
new SingleQuery<EventsDependencyResult>((client, id, timespan) => client.GetDependencyEvent(id, timespan)),
};

private static readonly object[] ExceptionsParams = new object[]
{
EventType.Exceptions,
new MultiQueryAsync<EventsExceptionResult>(async (client, timespan, top) => await client.GetExceptionEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsExceptionResult>(async (client, id, timespan) => await client.GetExceptionEventAsync(id, timespan)),
new MultiQuery<EventsExceptionResult>((client, timespan, top) => client.GetExceptionEvents(timespan, top: top)),
new SingleQuery<EventsExceptionResult>((client, id, timespan) => client.GetExceptionEvent(id, timespan)),
};

private static readonly object[] AvailabilityResultsParams = new object[]
{
EventType.AvailabilityResults,
new MultiQueryAsync<EventsAvailabilityResultResult>(async (client, timespan, top) => await client.GetAvailabilityResultEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsAvailabilityResultResult>(async (client, id, timespan) => await client.GetAvailabilityResultEventAsync(id, timespan)),
new MultiQuery<EventsAvailabilityResultResult>((client, timespan, top) => client.GetAvailabilityResultEvents(timespan, top: top)),
new SingleQuery<EventsAvailabilityResultResult>((client, id, timespan) => client.GetAvailabilityResultEvent(id, timespan)),
};

private static readonly object[] PerformanceCountersParams = new object[]
{
EventType.PerformanceCounters,
new MultiQueryAsync<EventsPerformanceCounterResult>(async (client, timespan, top) => await client.GetPerformanceCounterEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsPerformanceCounterResult>(async (client, id, timespan) => await client.GetPerformanceCounterEventAsync(id, timespan)),
new MultiQuery<EventsPerformanceCounterResult>((client, timespan, top) => client.GetPerformanceCounterEvents(timespan, top: top)),
new SingleQuery<EventsPerformanceCounterResult>((client, id, timespan) => client.GetPerformanceCounterEvent(id, timespan)),
};

private static readonly object[] CustomMetricsParams = new object[]
{
EventType.CustomMetrics,
new MultiQueryAsync<EventsCustomMetricResult>(async (client, timespan, top) => await client.GetCustomMetricEventsAsync(timespan, top: top)),
new SingleQueryAsync<EventsCustomMetricResult>(async (client, id, timespan) => await client.GetCustomMetricEventAsync(id, timespan)),
new MultiQuery<EventsCustomMetricResult>((client, timespan, top) => client.GetCustomMetricEvents(timespan, top: top)),
new SingleQuery<EventsCustomMetricResult>((client, id, timespan) => client.GetCustomMetricEvent(id, timespan)),
};

public static IEnumerable<object[]> TraceData { get { yield return TraceParams; } }

public static IEnumerable<object[]> CustomEventsData { get { yield return CustomEventsParams; } }

public static IEnumerable<object[]> PageViewsData { get { yield return PageViewsParams; } }

public static IEnumerable<object[]> BrowserTimingsData { get { yield return BrowserTimingsParams; } }

public static IEnumerable<object[]> RequestsData { get { yield return RequestsParams; } }

public static IEnumerable<object[]> DependenciesData { get { yield return DependenciesParams; } }

public static IEnumerable<object[]> ExceptionsData { get { yield return ExceptionsParams; } }

public static IEnumerable<object[]> AvailabilityResultsData { get { yield return AvailabilityResultsParams; } }

public static IEnumerable<object[]> PerformanceCountersData { get { yield return PerformanceCountersParams; } }

public static IEnumerable<object[]> CustomMetricsData { get { yield return CustomMetricsParams; } }
}
}
Loading