Skip to content

Commit

Permalink
drop /trace, change /httptrace to /httpexchanges (except on TPCF)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHess committed Sep 13, 2024
1 parent 44602e7 commit ba2fd37
Show file tree
Hide file tree
Showing 68 changed files with 1,346 additions and 1,743 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Steeltoe.Management.Endpoint.Actuators.Environment;
using Steeltoe.Management.Endpoint.Actuators.Health;
using Steeltoe.Management.Endpoint.Actuators.HeapDump;
using Steeltoe.Management.Endpoint.Actuators.HttpExchanges;
using Steeltoe.Management.Endpoint.Actuators.Hypermedia;
using Steeltoe.Management.Endpoint.Actuators.Info;
using Steeltoe.Management.Endpoint.Actuators.Loggers;
Expand All @@ -23,7 +24,6 @@
using Steeltoe.Management.Endpoint.Actuators.RouteMappings;
using Steeltoe.Management.Endpoint.Actuators.Services;
using Steeltoe.Management.Endpoint.Actuators.ThreadDump;
using Steeltoe.Management.Endpoint.Actuators.Trace;
using Steeltoe.Management.Endpoint.Configuration;
using Steeltoe.Management.Endpoint.ManagementPort;

Expand Down Expand Up @@ -98,7 +98,7 @@ public static IServiceCollection AddAllActuators(this IServiceCollection service
services.AddInfoActuator();
services.AddHealthActuator();
services.AddLoggersActuator();
services.AddTraceActuator(version);
services.AddHttpExchangesActuator();
services.AddMappingsActuator();
services.AddMetricsActuator();
services.AddRefreshActuator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ internal Task<SecurityResult> GetPermissionsAsync(HttpContext context)
}
else
{
if (requestPath.StartsWithSegments(basePath + endpointOptions.Path))
string? endpointPath = endpointOptions.Path;

if (endpointOptions.Id == "httpexchanges")
{
endpointPath = "httptrace";
}

if (requestPath.StartsWithSegments(basePath + endpointPath))
{
return endpointOptions;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.Configuration;
using Microsoft.Net.Http.Headers;
using Steeltoe.Management.Endpoint.Configuration;

namespace Steeltoe.Management.Endpoint.Actuators.HttpExchanges;

internal sealed class ConfigureHttpExchangesEndpointOptions(IConfiguration configuration)
: ConfigureEndpointOptions<HttpExchangesEndpointOptions>(configuration, ManagementInfoPrefix, "httpexchanges")
{
private const string ManagementInfoPrefix = "management:endpoints:httpexchanges";
private const int DefaultCapacity = 100;

private static readonly string[] DefaultAllowedRequestHeaders =
[
HeaderNames.Accept,
HeaderNames.AcceptCharset,
HeaderNames.AcceptEncoding,
HeaderNames.AcceptLanguage,
HeaderNames.Allow,
HeaderNames.CacheControl,
HeaderNames.Connection,
HeaderNames.ContentEncoding,
HeaderNames.ContentLength,
HeaderNames.ContentType,
HeaderNames.Date,
HeaderNames.DNT,
HeaderNames.Expect,
HeaderNames.Host,
HeaderNames.MaxForwards,
HeaderNames.Range,
HeaderNames.SecWebSocketExtensions,
HeaderNames.SecWebSocketVersion,
HeaderNames.TE,
HeaderNames.Trailer,
HeaderNames.TransferEncoding,
HeaderNames.Upgrade,
HeaderNames.UserAgent,
HeaderNames.Warning,
HeaderNames.XRequestedWith,
HeaderNames.XUACompatible
];

private static readonly string[] DefaultAllowedResponseHeaders =
[
HeaderNames.AcceptRanges,
HeaderNames.Age,
HeaderNames.Allow,
HeaderNames.AltSvc,
HeaderNames.Connection,
HeaderNames.ContentDisposition,
HeaderNames.ContentLanguage,
HeaderNames.ContentLength,
HeaderNames.ContentLocation,
HeaderNames.ContentRange,
HeaderNames.ContentType,
HeaderNames.Date,
HeaderNames.Expires,
HeaderNames.LastModified,
HeaderNames.Location,
HeaderNames.Server,
HeaderNames.TransferEncoding,
HeaderNames.Upgrade,
HeaderNames.XPoweredBy
];

public override void Configure(HttpExchangesEndpointOptions options)
{
ArgumentNullException.ThrowIfNull(options);

base.Configure(options);

if (options.Capacity == -1)
{
options.Capacity = DefaultCapacity;
}

// It's not possible to distinguish between null and an empty list in configuration.
// See https://github.com/dotnet/extensions/issues/1341.
// As a workaround, we interpret a single empty string element to clear the defaults.
if (options.RequestHeaders.Count == 0)
{
foreach (string defaultKey in DefaultAllowedRequestHeaders)
{
options.RequestHeaders.Add(defaultKey);
}
}
else if (options.RequestHeaders is [""])
{
options.RequestHeaders.Clear();
}
if (options.ResponseHeaders.Count == 0)
{
foreach (string defaultKey in DefaultAllowedResponseHeaders)
{
options.ResponseHeaders.Add(defaultKey);
}
}
else if (options.ResponseHeaders is [""])
{
options.ResponseHeaders.Clear();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Steeltoe.Management.Diagnostics;

namespace Steeltoe.Management.Endpoint.Actuators.HttpExchanges;

public static class EndpointServiceCollectionExtensions
{
/// <summary>
/// Adds the HttpExchanges actuator to the service container.
/// </summary>
/// <param name="services">
/// The <see cref="IServiceCollection" /> to add services to.
/// </param>
/// <returns>
/// The incoming <paramref name="services" /> so that additional calls can be chained.
/// </returns>
public static IServiceCollection AddHttpExchangesActuator(this IServiceCollection services)
{
return services.AddHttpExchangesActuator(_ => { });
}

/// <summary>
/// Adds the HttpExchanges (formerly known as Trace or HttpTrace) actuator to the service container.
/// </summary>
/// <param name="services">
/// The <see cref="IServiceCollection" /> to add services to.
/// </param>
/// <param name="configureOptions">A delegate to configure the <see cref="HttpExchangesEndpointOptions"/>.</param>
/// <returns>
/// The incoming <paramref name="services" /> so that additional calls can be chained.
/// </returns>
public static IServiceCollection AddHttpExchangesActuator(this IServiceCollection services, Action<HttpExchangesEndpointOptions> configureOptions)
{
ArgumentNullException.ThrowIfNull(services);

services.TryAddSingleton<IDiagnosticsManager, DiagnosticsManager>();
services.AddHostedService<DiagnosticsService>();

services.AddCommonActuatorServices();
services.AddHttpExchangesActuatorServices(configureOptions);

services.TryAddEnumerable(ServiceDescriptor.Singleton<IDiagnosticObserver, HttpExchangesDiagnosticObserver>());

services.TryAddSingleton<IHttpExchangesRepository>(provider =>
provider.GetServices<IDiagnosticObserver>().OfType<HttpExchangesDiagnosticObserver>().Single());

return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

namespace Steeltoe.Management.Endpoint.Actuators.Trace;
namespace Steeltoe.Management.Endpoint.Actuators.HttpExchanges;

public sealed class HttpTrace
public sealed class HttpExchange
{
public long Timestamp { get; }
public TracePrincipal? Principal { get; }
Expand All @@ -13,7 +13,7 @@ public sealed class HttpTrace
public TraceResponse Response { get; }
public long TimeTaken { get; }

public HttpTrace(TraceRequest request, TraceResponse response, long timestamp, TracePrincipal? principal, TraceSession? session, double timeTaken)
public HttpExchange(TraceRequest request, TraceResponse response, long timestamp, TracePrincipal? principal, TraceSession? session, double timeTaken)
{
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(response);
Expand Down
Loading

0 comments on commit ba2fd37

Please sign in to comment.