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

Update packages (minor + major) #31

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 33 additions & 33 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Version="8.0.0" Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageVersion Version="8.0.1" Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageVersion Version="3.6.133" Include="Nerdbank.GitVersioning" />
<PackageVersion Version="4.3.0" Include="App.Metrics.Abstractions" />
<PackageVersion Version="4.3.0" Include="App.Metrics.AspNetCore.All" />
<PackageVersion Version="4.3.0" Include="App.Metrics.Formatters.Prometheus" />
<PackageVersion Version="7.0.0" Include="AspNetCore.HealthChecks.System" />
<PackageVersion Version="7.0.0" Include="AspNetCore.HealthChecks.Uris" />
<PackageVersion Version="7.0.0" Include="AspNetCore.HealthChecks.Hangfire" />
<PackageVersion Version="7.0.0" Include="AspNetCore.HealthChecks.MongoDb" />
<PackageVersion Version="8.0.0" Include="AspNetCore.HealthChecks.System" />
<PackageVersion Version="8.0.0" Include="AspNetCore.HealthChecks.Uris" />
<PackageVersion Version="8.0.0" Include="AspNetCore.HealthChecks.Hangfire" />
<PackageVersion Version="8.0.0" Include="AspNetCore.HealthChecks.MongoDb" />
<PackageVersion Version="5.0.0" Include="AspNetCoreRateLimit" />
<PackageVersion Version="2.2.1" Include="BouncyCastle.NetCore" />
<PackageVersion Version="2.0.24" Include="Chronos.Abstractions" />
<PackageVersion Version="2.0.24" Include="Chronos.Net" />
<PackageVersion Version="11.8.1" Include="FluentValidation" />
<PackageVersion Version="3.25.1" Include="Google.Protobuf" />
<PackageVersion Version="11.9.0" Include="FluentValidation" />
<PackageVersion Version="3.25.2" Include="Google.Protobuf" />
<PackageVersion Version="2.46.6" Include="Grpc" />
<PackageVersion Version="2.60.0" Include="Grpc.Tools">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Version="1.8.6" Include="HangFire" />
<PackageVersion Version="1.8.9" Include="HangFire" />
<PackageVersion Version="1.8.0" Include="Hangfire.MemoryStorage" />
<PackageVersion Version="1.20.4" Include="Hangfire.PostgreSql" />
<PackageVersion Version="1.20.5" Include="Hangfire.PostgreSql" />
<PackageVersion Version="2.5.0" Include="KafkaFlow" />
<PackageVersion Version="2.5.0" Include="KafkaFlow.Extensions.Hosting" />
<PackageVersion Version="2.5.0" Include="KafkaFlow.LogHandler.Microsoft" />
Expand All @@ -39,12 +39,12 @@
<PackageVersion Version="1.5.0-rc.1" Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" />
<PackageVersion Version="1.7.0" Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageVersion Version="1.0.0-beta.7" Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" />
<PackageVersion Version="1.6.0" Include="OpenTelemetry.Extensions.Hosting" />
<PackageVersion Version="1.5.0-beta.1" Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageVersion Version="1.5.0-beta.1" Include="OpenTelemetry.Instrumentation.Http" />
<PackageVersion Version="1.5.1" Include="OpenTelemetry.Instrumentation.Runtime" />
<PackageVersion Version="1.7.0" Include="OpenTelemetry.Extensions.Hosting" />
<PackageVersion Version="1.7.0" Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageVersion Version="1.7.0" Include="OpenTelemetry.Instrumentation.Http" />
<PackageVersion Version="1.7.0" Include="OpenTelemetry.Instrumentation.Runtime" />
<PackageVersion Version="0.5.0-beta.3" Include="OpenTelemetry.Instrumentation.Process" />
<PackageVersion Version="8.0.0" Include="Serilog.AspNetCore" />
<PackageVersion Version="8.0.1" Include="Serilog.AspNetCore" />
<PackageVersion Version="3.1.0" Include="Serilog.Enrichers.Span" />
<PackageVersion Version="3.1.0" Include="Serilog.Enrichers.Thread" />
<PackageVersion Version="1.51.91" Include="ODataQueryHelper.Core" />
Expand All @@ -55,29 +55,29 @@
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.Configuration" />
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.DependencyInjection" />
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.Http.Polly" />
<PackageVersion Version="8.0.1" Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
<PackageVersion Version="8.0.1" Include="Microsoft.Extensions.Http.Polly" />
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.Caching.Abstractions" />
<PackageVersion Version="8.0.0" Include="Microsoft.Extensions.Http" />
<PackageVersion Version="3.0.0" Include="Microsoft.FeatureManagement.AspNetCore" />
<PackageVersion Version="8.0.0" Include="Microsoft.EntityFrameworkCore" />
<PackageVersion Version="8.0.0" Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageVersion Version="8.0.0" Include="Microsoft.EntityFrameworkCore.Tools">
<PackageVersion Version="3.1.1" Include="Microsoft.FeatureManagement.AspNetCore" />
<PackageVersion Version="8.0.1" Include="Microsoft.EntityFrameworkCore" />
<PackageVersion Version="8.0.1" Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageVersion Version="8.0.1" Include="Microsoft.EntityFrameworkCore.Tools">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Version="8.0.0" Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageVersion Version="8.0.0" Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
<PackageVersion Version="8.0.1" Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageVersion Version="8.0.1" Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
<PackageVersion Version="2.2.0" Include="Microsoft.AspNetCore.Hosting.Abstractions" />
<PackageVersion Version="7.0.10" Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageVersion Version="8.0.0" Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageVersion Version="8.0.0" Include="Microsoft.AspNetCore.Authorization" />
<PackageVersion Version="2.22.0" Include="MongoDB.Driver" />
<PackageVersion Version="8.0.1" Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageVersion Version="8.0.1" Include="Microsoft.AspNetCore.Authorization" />
<PackageVersion Version="2.23.1" Include="MongoDB.Driver" />
<PackageVersion Version="2.2.0" Include="MongoDBMigrations" />
<PackageVersion Version="6.0.1" Include="Minio" />
<PackageVersion Version="13.0.3" Include="Newtonsoft.Json" />
<PackageVersion Version="7.0.3" Include="Microsoft.IdentityModel.Tokens" />
<PackageVersion Version="7.0.3" Include="System.IdentityModel.Tokens.Jwt" />
<PackageVersion Version="7.3.0" Include="Microsoft.IdentityModel.Tokens" />
<PackageVersion Version="7.3.0" Include="System.IdentityModel.Tokens.Jwt" />
<PackageVersion Version="6.5.0" Include="Swashbuckle.AspNetCore.Annotations" />
<PackageVersion Version="6.5.0" Include="Swashbuckle.AspNetCore.SwaggerUI" />
<PackageVersion Version="4.1.0" Include="jose-jwt" />
Expand All @@ -86,17 +86,17 @@
<PackageVersion Version="1.6.4" Include="Restease" />
<PackageVersion Version="2.13.1" Include="AutoBogus" />
<PackageVersion Version="2.4.1" Include="NaughtyStrings.Bogus" />
<PackageVersion Version="34.0.2" Include="Bogus" />
<PackageVersion Version="35.4.0" Include="Bogus" />
<PackageVersion Version="6.12.0" Include="FluentAssertions" />
<PackageVersion Version="17.8.0" Include="Microsoft.NET.Test.Sdk" />
<PackageVersion Version="4.5.0" Include="NUnit3TestAdapter" />
<PackageVersion Version="5.1.0" Include="NSubstitute" />
<PackageVersion Version="1.0.16" Include="NSubstitute.Analyzers.CSharp" />
<PackageVersion Version="3.14.0" Include="NUnit" />
<PackageVersion Version="4.0.1" Include="NUnit" />
<PackageVersion Version="1.2.1.1" Include="NUnit.Allure" />
<PackageVersion Version="4.1.1" Include="Unleash.Client" />
<PackageVersion Version="3.0.23" Include="Vogen" />
<PackageVersion Version="1.5.40" Include="WireMock.Net" />
<PackageVersion Version="13.7.1" Include="YamlDotNet" />
<PackageVersion Version="4.1.5" Include="Unleash.Client" />
<PackageVersion Version="3.0.24" Include="Vogen" />
<PackageVersion Version="1.5.47" Include="WireMock.Net" />
<PackageVersion Version="15.1.0" Include="YamlDotNet" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Chronos.Abstractions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using PiBox.Hosting.Abstractions.Attributes;

namespace PiBox.Hosting.Abstractions.Middlewares
{
[Middleware]
public sealed class EnrichRequestMetricsMiddleware : ApiMiddleware
{
public EnrichRequestMetricsMiddleware(RequestDelegate next, IDateTimeProvider dateTimeProvider) : base(next,
dateTimeProvider)
{
}

public override Task Invoke(HttpContext context)
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

{
var tagsFeature = context.Features.Get<IHttpMetricsTagsFeature>();
if (tagsFeature == null) return Next.Invoke(context);
var authorizedParty = context.User.Claims.SingleOrDefault(x => x.Type == "azp")?.Value;
tagsFeature.Tags.Add(new KeyValuePair<string, object>("azp", authorizedParty ?? ""));

return Next.Invoke(context);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Security.Claims;
using Chronos.Abstractions;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using NSubstitute;
using NUnit.Framework;
using PiBox.Hosting.Abstractions.Middlewares;

namespace PiBox.Hosting.Abstractions.Tests.Middlewares
{
public class EnrichRequestMetricsMiddlewareTests
{
private readonly IDateTimeProvider _dateTimeProvider = Substitute.For<IDateTimeProvider>();

private static HttpContext GetContext()
{
return new DefaultHttpContext { Response = { Body = new MemoryStream() } };
}

[SetUp]
public void Setup()
{
_dateTimeProvider.UtcNow.Returns(new DateTime(2020, 1, 1));
}

[Test]
public async Task ExistingAzpClaimShouldAddTagWithUserIdToMetrics()
{
var httpMetricsTagsFeature = Substitute.For<IHttpMetricsTagsFeature>();
httpMetricsTagsFeature.Tags.Returns(new List<KeyValuePair<string, object>>());
var middleware = new EnrichRequestMetricsMiddleware(x =>
{
x.Response.StatusCode = 200;
return Task.CompletedTask;
}, _dateTimeProvider);
var context = GetContext();

context.User = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim("azp", "userid1") }));
context.Features.Set(httpMetricsTagsFeature);

await middleware.Invoke(context);
var metrics = context.Features.Get<IHttpMetricsTagsFeature>();
metrics.Tags.Should().Contain(x => x.Key == "azp" && x.Value.ToString() == "userid1");
}

[Test]
public async Task NonExistingAzpClaimShouldAddTagWithEmptyValueToMetrics()
{
var httpMetricsTagsFeature = Substitute.For<IHttpMetricsTagsFeature>();
httpMetricsTagsFeature.Tags.Returns(new List<KeyValuePair<string, object>>());
var middleware = new EnrichRequestMetricsMiddleware(x =>
{
x.Response.StatusCode = 200;
return Task.CompletedTask;
}, _dateTimeProvider);
var context = GetContext();

context.User = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim("azp1", "userid1") }));
context.Features.Set(httpMetricsTagsFeature);

await middleware.Invoke(context);
var metrics = context.Features.Get<IHttpMetricsTagsFeature>();
metrics.Tags.Should().Contain(x => x.Key == "azp" && x.Value.ToString() == "");
}

[Test]
public async Task NoHttpMetricsTagsFeatureShouldNotAddMetricTagsToResponse()
{
var httpMetricsTagsFeature = Substitute.For<IHttpMetricsTagsFeature>();
httpMetricsTagsFeature.Tags.Returns(new List<KeyValuePair<string, object>>());
var middleware = new EnrichRequestMetricsMiddleware(x =>
{
x.Response.StatusCode = 200;
return Task.CompletedTask;
}, _dateTimeProvider);
var context = GetContext();

context.User = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>() { new Claim("azp1", "userid1") }));

await middleware.Invoke(context);
var metrics = context.Features.Get<IHttpMetricsTagsFeature>();
metrics.Should().BeNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Chronos.Abstractions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand Down Expand Up @@ -126,14 +125,7 @@ internal void ConfigureMetrics()
resource.AddService(serviceName,
serviceVersion: entryAssembly.GetName().Version?.ToString() ?? "unknown", serviceInstanceId: Environment.MachineName);
})
.AddAspNetCoreInstrumentation(options =>
{
options.Enrich = (string metricName, HttpContext context, ref TagList tags) =>
{
var authorizedParty = context.User.Claims.SingleOrDefault(x => x.Type == "azp")?.Value;
tags.Add("azp", authorizedParty);
};
})
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddProcessInstrumentation()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using NUnit.Framework;
using PiBox.Hosting.WebHost.Logging;
Expand All @@ -17,7 +18,7 @@ public void TestDetermineLoggingIsSettingTheLevelToErrorForTheGivenPathsStatusco
StructuredLoggingExtensions.DetermineRequestLogLevel(new[] { "/metrics-text" })(httpContext, 0,
null);

Assert.AreEqual(LogEventLevel.Error, logLevel);
LogEventLevel.Error.Should().Be(logLevel);
}

[Test]
Expand All @@ -31,7 +32,7 @@ public void TestDetermineLoggingIsSettingTheLevelToErrorForTheGivenPathsExceptio
StructuredLoggingExtensions.DetermineRequestLogLevel(new[] { "/metrics-text" })(httpContext, 0,
new Exception("test"));

Assert.AreEqual(LogEventLevel.Error, logLevel);
LogEventLevel.Error.Should().Be(logLevel);
}

[Test]
Expand All @@ -45,7 +46,7 @@ public void TestDetermineLoggingIsExcludingTheGivenPaths()
StructuredLoggingExtensions.DetermineRequestLogLevel(new[] { "/MeTRICS", "/metrics" })(httpContext,
0, null);

Assert.AreEqual(LogEventLevel.Verbose, logLevel);
LogEventLevel.Verbose.Should().Be(logLevel);
}

[Test]
Expand All @@ -58,7 +59,7 @@ public void TestDetermineLoggingIsExcludingTheGivenWildcardPaths()
StructuredLoggingExtensions.DetermineRequestLogLevel(new[] { "/MeTRICS", "/metrics*" })(
httpContext, 0, null);

Assert.AreEqual(LogEventLevel.Verbose, logLevel);
LogEventLevel.Verbose.Should().Be(logLevel);
}

[Test]
Expand All @@ -71,7 +72,7 @@ public void TestDetermineLoggingIsNotExcludingTheGivenWildcardPaths()
var logLevel =
StructuredLoggingExtensions.DetermineRequestLogLevel(new[] { "/hangfire*" })(httpContext, 0, null);

Assert.AreEqual(LogEventLevel.Information, logLevel);
LogEventLevel.Information.Should().Be(logLevel);
}

[TestCase("/metrics-text", new[] { "/MeTRICS", "/metrics" }, 499, null)]
Expand All @@ -86,7 +87,7 @@ public void TestDetermineLoggingIsNotExcludingTheGivenPaths(string actualPath, I
var logLevel =
StructuredLoggingExtensions.DetermineRequestLogLevel(paths)(httpContext, 0, exception);

Assert.AreEqual(LogEventLevel.Information, logLevel);
LogEventLevel.Information.Should().Be(logLevel);
}
}
}
Loading