-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from allegro/feature/application-insights-exte…
…nsions feat: Application Insights Extensions with many features
- Loading branch information
Showing
54 changed files
with
3,419 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
.github/workflows/Allegro.Extensions.ApplicationInsights.ci.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Build Allegro.Extensions.ApplicationInsights | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'src/Allegro.Extensions.ApplicationInsights/**' | ||
- 'src/*' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- 'src/Allegro.Extensions.ApplicationInsights/**' | ||
- 'src/*' | ||
|
||
jobs: | ||
ci1: | ||
uses: ./.github/workflows/template.yml | ||
with: | ||
projectName: Allegro.Extensions.ApplicationInsights.AspNetCore | ||
solutionName: Allegro.Extensions.ApplicationInsights | ||
ci2: | ||
uses: ./.github/workflows/template.yml | ||
with: | ||
projectName: Allegro.Extensions.ApplicationInsights.Prometheus | ||
solutionName: Allegro.Extensions.ApplicationInsights |
30 changes: 30 additions & 0 deletions
30
.github/workflows/Allegro.Extensions.ApplicationInsights.publish.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Publish Allegro.Extensions.ApplicationInsights | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'Allegro.Extensions.ApplicationInsights_*' | ||
|
||
jobs: | ||
publish1: | ||
uses: ./.github/workflows/template.yml | ||
with: | ||
projectName: Allegro.Extensions.ApplicationInsights.AspNetCore | ||
solutionName: Allegro.Extensions.ApplicationInsights | ||
publish: true | ||
tagName: ${{ github.ref_name }} | ||
secrets: | ||
nugetCertificate: ${{ secrets.NUGET_PRIVATE_KEY_P12 }} | ||
nugetCertificatePassword: ${{ secrets.GPG_PRIVATE_KEY_PASSWORD }} | ||
nugetApiKey: ${{ secrets.NUGET_API_KEY }} | ||
publish2: | ||
uses: ./.github/workflows/template.yml | ||
with: | ||
projectName: Allegro.Extensions.ApplicationInsights.Prometheus | ||
solutionName: Allegro.Extensions.ApplicationInsights | ||
publish: true | ||
tagName: ${{ github.ref_name }} | ||
secrets: | ||
nugetCertificate: ${{ secrets.NUGET_PRIVATE_KEY_P12 }} | ||
nugetCertificatePassword: ${{ secrets.GPG_PRIVATE_KEY_PASSWORD }} | ||
nugetApiKey: ${{ secrets.NUGET_API_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...icationInsights/Allegro.Extensions.ApplicationInsights.AspNetCore.UnitTests/.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[*.{cs,fs}] | ||
dotnet_diagnostic.CS1591.severity = none |
250 changes: 250 additions & 0 deletions
250
...Extensions.ApplicationInsights.AspNetCore.UnitTests/AdaptiveSamplingConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using FluentAssertions; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Moq; | ||
|
||
namespace Allegro.Extensions.ApplicationInsights.AspNetCore.UnitTests; | ||
|
||
[SuppressMessage("CSharp Extensions", "CSE001:Required properties initialization", Justification = "SampleConfig is perfectly fine to init with default constructor")] | ||
public class AdaptiveSamplingConfigurationTests | ||
{ | ||
[Fact] | ||
public void WhenConfigIsDefaultShouldReturnTelemetryProcessorWithConfigDefaultValues() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
|
||
var samplingTelemetryProcessor = ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor( | ||
telemetryProcessorMock.Object, | ||
new SamplingConfig()); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenEvaluationIntervalIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() { EvaluationInterval = TimeSpan.FromSeconds(5) } | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(5)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenExcludedTypesIsChanged_ShouldChangeTelemetryProcessorValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() { SamplingExcludedTypes = "Dependency" }; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Dependency"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenInitialSamplingPercentageIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() { InitialSamplingPercentage = 99 } | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(99); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenMaxSamplingPercentageIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() { MaxSamplingPercentage = 99 } | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(99); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenMinSamplingPercentageIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() { MinSamplingPercentage = 0.01 } | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.01); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenMovingAverageRatioIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() { MovingAverageRatio = 0.1 } | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.1); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenMaxTelemetryItemsPerSecondIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() { MaxTelemetryItemsPerSecond = 3 } | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(3); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenSamplingPercentageDecreaseTimeoutIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() | ||
{ | ||
SamplingPercentageDecreaseTimeout = TimeSpan.FromMinutes(1) | ||
} | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(1)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(15)); | ||
} | ||
|
||
[Fact] | ||
public void WhenSamplingPercentageIncreaseTimeoutIsNotNull_ShouldOverwriteTelemetryProcessorDefaultValue() | ||
{ | ||
var telemetryProcessorMock = new Mock<ITelemetryProcessor>(); | ||
var config = new SamplingConfig() | ||
{ | ||
AdaptiveSamplingConfig = new AdaptiveSamplingConfig() | ||
{ | ||
SamplingPercentageIncreaseTimeout = TimeSpan.FromMinutes(5) | ||
} | ||
}; | ||
|
||
var samplingTelemetryProcessor = | ||
ApplicationInsightsExtensions.CreateAdaptiveSamplingProcessor(telemetryProcessorMock.Object, config); | ||
|
||
samplingTelemetryProcessor.EvaluationInterval.Should().Be(TimeSpan.FromSeconds(15)); | ||
samplingTelemetryProcessor.ExcludedTypes.Should().Be("Event;Exception;Trace;PageView"); | ||
samplingTelemetryProcessor.IncludedTypes.Should().BeNull(); | ||
samplingTelemetryProcessor.InitialSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MaxSamplingPercentage.Should().Be(100); | ||
samplingTelemetryProcessor.MinSamplingPercentage.Should().Be(0.1); | ||
samplingTelemetryProcessor.MovingAverageRatio.Should().Be(0.25); | ||
samplingTelemetryProcessor.MaxTelemetryItemsPerSecond.Should().Be(5); | ||
samplingTelemetryProcessor.SamplingPercentageDecreaseTimeout.Should().Be(TimeSpan.FromMinutes(2)); | ||
samplingTelemetryProcessor.SamplingPercentageIncreaseTimeout.Should().Be(TimeSpan.FromMinutes(5)); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...s.AspNetCore.UnitTests/Allegro.Extensions.ApplicationInsights.AspNetCore.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" /> | ||
<PackageReference Include="Moq" Version="4.20.69" /> | ||
<PackageReference Include="xunit" Version="2.5.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Update="Meziantou.Analyzer" Version="2.0.85"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Update="SmartAnalyzers.CSharpExtensions.Annotations" Version="4.2.8"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; compile; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
<ProjectReference Include="..\Allegro.Extensions.ApplicationInsights.AspNetCore\Allegro.Extensions.ApplicationInsights.AspNetCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.