Skip to content

Commit 1fffc2c

Browse files
authored
Remove middleware warning, it's not reliable (#1625)
1 parent 956e891 commit 1fffc2c

File tree

2 files changed

+0
-55
lines changed

2 files changed

+0
-55
lines changed

src/Management/src/Endpoint/ConfigureActuatorsMiddlewareStartupFilter.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,15 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Reflection;
65
using Microsoft.AspNetCore.Builder;
76
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.AspNetCore.Http;
97
using Microsoft.Extensions.DependencyInjection;
10-
using Microsoft.Extensions.Logging;
118
using Steeltoe.Management.Endpoint.Actuators.CloudFoundry;
129

1310
namespace Steeltoe.Management.Endpoint;
1411

1512
internal sealed class ConfigureActuatorsMiddlewareStartupFilter : IStartupFilter
1613
{
17-
private readonly ILogger<ConfigureActuatorsMiddlewareStartupFilter> _logger;
18-
19-
public ConfigureActuatorsMiddlewareStartupFilter(ILogger<ConfigureActuatorsMiddlewareStartupFilter> logger)
20-
{
21-
ArgumentNullException.ThrowIfNull(logger);
22-
23-
_logger = logger;
24-
}
25-
2614
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
2715
{
2816
ArgumentNullException.ThrowIfNull(next);
@@ -45,30 +33,9 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
4533
app.UseCloudFoundrySecurity();
4634
}
4735

48-
int? beforeMiddlewareCount = GetMiddlewareCount(app);
4936
next.Invoke(app);
50-
int? afterMiddlewareCount = GetMiddlewareCount(app);
51-
52-
if (beforeMiddlewareCount != afterMiddlewareCount)
53-
{
54-
_logger.LogWarning(
55-
"Actuators were registered with automatic middleware setup, and at least one additional middleware was registered afterward. This combination is usually undesired. " +
56-
"To remove this warning, either remove the additional middleware registration or set configureMiddleware to false when registering actuators.");
57-
}
5837

5938
app.UseActuatorEndpoints();
6039
};
6140
}
62-
63-
private static int? GetMiddlewareCount(IApplicationBuilder app)
64-
{
65-
FieldInfo? componentsField = app.GetType().GetField("_components", BindingFlags.NonPublic | BindingFlags.Instance);
66-
return componentsField?.GetValue(app) is List<Func<RequestDelegate, RequestDelegate>> components ? components.Count(IsMiddleware) : null;
67-
}
68-
69-
private static bool IsMiddleware(Func<RequestDelegate, RequestDelegate> component)
70-
{
71-
// This type exists so that ASP.NET Core can identify where to inject UseRouting. It is not a real middleware.
72-
return component.Target == null || component.Target.ToString() != "Microsoft.AspNetCore.Builder.WebApplicationBuilder+WireSourcePipeline";
73-
}
7441
}

src/Management/test/Endpoint.Test/Actuators/All/AllActuatorsTest.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5-
using Microsoft.AspNetCore.Builder;
65
using Microsoft.AspNetCore.Cors.Infrastructure;
76
using Microsoft.AspNetCore.Hosting;
87
using Microsoft.Extensions.Configuration;
98
using Microsoft.Extensions.DependencyInjection;
10-
using Microsoft.Extensions.Logging;
119
using Microsoft.Extensions.Options;
1210
using Steeltoe.Common.TestResources;
1311
using Steeltoe.Management.Endpoint.Actuators.All;
@@ -134,24 +132,4 @@ public async Task Does_not_register_duplicate_services(HostBuilderType hostBuild
134132
host.Services.GetServices<InfoEndpointMiddleware>().Should().ContainSingle();
135133
host.Services.GetServices<IEndpointMiddleware>().OfType<InfoEndpointMiddleware>().Should().ContainSingle();
136134
}
137-
138-
[Fact]
139-
public async Task Logs_warning_when_custom_middleware_is_registered_without_configureMiddleware_false()
140-
{
141-
using var capturingLoggerProvider = new CapturingLoggerProvider((_, logLevel) => logLevel >= LogLevel.Warning);
142-
143-
WebApplicationBuilder builder = TestWebApplicationBuilderFactory.Create();
144-
builder.Logging.AddProvider(capturingLoggerProvider);
145-
builder.Services.AddAllActuators();
146-
await using WebApplication host = builder.Build();
147-
148-
host.UseRouting();
149-
host.UseActuatorEndpoints();
150-
151-
await host.StartAsync(TestContext.Current.CancellationToken);
152-
153-
capturingLoggerProvider.GetAll().Should().Contain($"WARN {typeof(ConfigureActuatorsMiddlewareStartupFilter)}: " +
154-
"Actuators were registered with automatic middleware setup, and at least one additional middleware was registered afterward. This combination is usually undesired. " +
155-
"To remove this warning, either remove the additional middleware registration or set configureMiddleware to false when registering actuators.");
156-
}
157135
}

0 commit comments

Comments
 (0)