Skip to content

Add logfile actuator #1499

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

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
37d4b74
Add logfile actuator
tscrypter Apr 3, 2025
a0e8fe2
fix build warnings
tscrypter Apr 3, 2025
711c98f
fix style in Logfile actuator files
tscrypter Apr 3, 2025
ee6cf15
♻️ Rename Logfile to LogFile actuator
tscrypter Apr 4, 2025
7f8d4f9
Merge branch 'main' into main
tscrypter Apr 4, 2025
e48a003
suggested doc update for LogFile svc extensions
tscrypter Apr 7, 2025
d361f82
Suggested docs update for LogFile options
tscrypter Apr 7, 2025
26511de
Replace delimited with separated (#1500)
bart-vmware Apr 4, 2025
f1f808b
Address PR feedback
tscrypter Apr 8, 2025
ee63559
Address PR feedback
tscrypter Apr 8, 2025
88324e5
🚨 Fix public API entries
tscrypter Apr 8, 2025
52cd3b0
Merge branch 'main' into main
tscrypter Apr 8, 2025
5f98eca
Allow network share paths with disk health contributor, better except…
TimHess Apr 8, 2025
04eb095
Merge branch 'SteeltoeOSS:main' into main
tscrypter Apr 9, 2025
013e333
Update src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointH…
tscrypter Apr 9, 2025
5367550
Update src/Management/test/Endpoint.Test/Actuators/LogFile/EndpointMi…
tscrypter Apr 9, 2025
2b016ef
Update src/Management/test/Endpoint.Test/Actuators/LogFile/EndpointMi…
tscrypter Apr 9, 2025
416957d
🎨 Fix casing in namespace
tscrypter Apr 9, 2025
a65eb25
restore PublicAPI.Unshipped.txt
tscrypter Apr 15, 2025
361636e
start adding range header support
tscrypter Apr 15, 2025
629afc2
add public api changes
tscrypter Apr 15, 2025
5c1f8aa
fix some build errors
tscrypter Apr 15, 2025
5679892
Use default Encoding for this .NET
tscrypter Apr 15, 2025
fefff15
Merge branch 'main' into main
tscrypter Apr 15, 2025
f106e48
Merge branch 'main' into main
tscrypter Apr 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Steeltoe.Management.Endpoint.Actuators.HttpExchanges;
using Steeltoe.Management.Endpoint.Actuators.Hypermedia;
using Steeltoe.Management.Endpoint.Actuators.Info;
using Steeltoe.Management.Endpoint.Actuators.Logfile;
using Steeltoe.Management.Endpoint.Actuators.Loggers;
using Steeltoe.Management.Endpoint.Actuators.Refresh;
using Steeltoe.Management.Endpoint.Actuators.RouteMappings;
Expand Down Expand Up @@ -70,6 +71,7 @@ public static IServiceCollection AddAllActuators(this IServiceCollection service
services.AddRouteMappingsActuator(configureMiddleware);
services.AddRefreshActuator(configureMiddleware);
services.AddServicesActuator(configureMiddleware);
services.AddLogFileActuator(configureMiddleware);

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 Steeltoe.Management.Endpoint.Configuration;

namespace Steeltoe.Management.Endpoint.Actuators.Logfile;
Copy link
Member

Choose a reason for hiding this comment

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

The namespaces still have the old casing (also in tests).


internal sealed class ConfigureLogFileEndpointOptions : ConfigureEndpointOptions<LogFileEndpointOptions>
{
private const string ManagementInfoPrefix = "management:endpoints:logfile";

public ConfigureLogFileEndpointOptions(IConfiguration configuration)
: base(configuration, ManagementInfoPrefix, "logfile")
{
ArgumentNullException.ThrowIfNull(configuration);
}

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

base.Configure(options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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 Microsoft.Extensions.Hosting;

namespace Steeltoe.Management.Endpoint.Actuators.Logfile;

public static class EndpointServiceCollectionExtensions

Check failure on line 11 in src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_macOS)

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs#L11

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs(11,21): Error RS0016: Symbol 'EndpointServiceCollectionExtensions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 11 in src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_ubuntu)

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs#L11

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs(11,21): Error RS0016: Symbol 'EndpointServiceCollectionExtensions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 11 in src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs

View check run for this annotation

Azure Pipelines / Steeltoe Package

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs#L11

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs(11,21): Error RS0016: Symbol 'EndpointServiceCollectionExtensions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 11 in src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs#L11

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs(11,21): Error RS0016: Symbol 'EndpointServiceCollectionExtensions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 11 in src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs

View check run for this annotation

Azure Pipelines / Steeltoe Sonar Analysis

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs#L11

src/Management/src/Endpoint/Actuators/LogFile/EndpointServiceCollectionExtensions.cs(11,21): Error RS0016: Symbol 'EndpointServiceCollectionExtensions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
/// <summary>
/// Adds the logfile actuator to the service container and configure the ASP.NET Core middleware pipeline.
/// </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 AddLogFileActuator(this IServiceCollection services)
{
return AddLogFileActuator(services, true);
}

/// <summary>
/// Adds the logfile actuator to the service container.
/// </summary>
/// <param name="services">
/// The <see cref="IServiceCollection" /> to add services to.
/// </param>
/// <param name="configureMiddleware">
/// When <c>false</c>, skips configuration of the ASP.NET Core middleware pipeline. While this provides full control over the pipeline order, it requires
/// manual addition of the appropriate middleware for actuators to work correctly.
/// </param>
/// <returns>
/// The incoming <paramref name="services" /> so that additional calls can be chained.
/// </returns>
public static IServiceCollection AddLogFileActuator(this IServiceCollection services, bool configureMiddleware)
{
ArgumentNullException.ThrowIfNull(services);

services.TryAddSingleton<IHostEnvironment>(serviceProvider => serviceProvider.GetService<IHostEnvironment>()!);

services.AddCoreActuatorServices<LogFileEndpointOptions, ConfigureLogFileEndpointOptions, LogFileEndpointMiddleware,
ILogFileEndpointHandler, LogFileEndpointHandler, object?, string>(configureMiddleware);

return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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.

namespace Steeltoe.Management.Endpoint.Actuators.Logfile;

public interface ILogFileEndpointHandler : IEndpointHandler<object?, string>;

Check failure on line 7 in src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_macOS)

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs#L7

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs(7,18): Error RS0016: Symbol 'ILogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 7 in src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_ubuntu)

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs#L7

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs(7,18): Error RS0016: Symbol 'ILogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 7 in src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe Package

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs#L7

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs(7,18): Error RS0016: Symbol 'ILogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 7 in src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs#L7

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs(7,18): Error RS0016: Symbol 'ILogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 7 in src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe Sonar Analysis

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs#L7

src/Management/src/Endpoint/Actuators/LogFile/ILogFileEndpointHandler.cs(7,18): Error RS0016: Symbol 'ILogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 System.Reflection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Steeltoe.Management.Configuration;

namespace Steeltoe.Management.Endpoint.Actuators.Logfile;

public sealed class LogFileEndpointHandler : ILogFileEndpointHandler

Check failure on line 12 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_macOS)

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs#L12

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs(12,21): Error RS0016: Symbol 'LogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_ubuntu)

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs#L12

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs(12,21): Error RS0016: Symbol 'LogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe Package

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs#L12

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs(12,21): Error RS0016: Symbol 'LogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs#L12

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs(12,21): Error RS0016: Symbol 'LogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs

View check run for this annotation

Azure Pipelines / Steeltoe Sonar Analysis

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs#L12

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointHandler.cs(12,21): Error RS0016: Symbol 'LogFileEndpointHandler' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
private readonly IOptionsMonitor<LogFileEndpointOptions> _optionsMonitor;
private readonly ILogger<LogFileEndpointHandler> _logger;

public EndpointOptions Options => _optionsMonitor.CurrentValue;

public LogFileEndpointHandler(IOptionsMonitor<LogFileEndpointOptions> optionsMonitorMonitor, ILoggerFactory loggerFactory)
{
ArgumentNullException.ThrowIfNull(optionsMonitorMonitor);
ArgumentNullException.ThrowIfNull(loggerFactory);

_optionsMonitor = optionsMonitorMonitor;
_logger = loggerFactory.CreateLogger<LogFileEndpointHandler>();
}

public async Task<string> InvokeAsync(object? argument, CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

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

If this returned Task<string?>, the middleware could respond with 404 when null is returned by overriding WriteResponseAsync. Should catch a FileNotFoundException here to detect this. This is normal behavior; some logging frameworks don't create the file until there's something to log, so it shouldn't log a warning. But when the configured path is null, the endpoint was turned on without configuring a path, which is a mistake, so a warning should be logged in that case (and null should be returned).

Copy link
Member

Choose a reason for hiding this comment

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

To support byte ranges, object? argument probably needs to change, so the range can be communicated. The range should be read from HTTP headers by overriding ParseRequestAsync in middleware. We try to keep the handlers agnostic from HttpContext.

{
_logger.LogTrace("Invoking LogfileEndpointHandler with argument: {Argument}", argument);
cancellationToken.ThrowIfCancellationRequested();

string logFilePath = GetLogFilePath();

if (!string.IsNullOrEmpty(logFilePath))
{
return await File.ReadAllTextAsync(logFilePath, cancellationToken);
}

_logger.LogWarning("Log file path is not set");
return string.Empty;
}

internal string GetLogFilePath()
{
_logger.LogTrace("Getting log file path");

if (!string.IsNullOrEmpty(_optionsMonitor.CurrentValue.FilePath))
{
string entryAssemblyDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!;
return Path.Combine(entryAssemblyDirectory, _optionsMonitor.CurrentValue.FilePath ?? string.Empty);
}

_logger.LogWarning("File path is not set");
return string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.Logging;
using Microsoft.Extensions.Options;
using Steeltoe.Management.Endpoint.Configuration;
using Steeltoe.Management.Endpoint.Middleware;

namespace Steeltoe.Management.Endpoint.Actuators.Logfile;

internal sealed class LogFileEndpointMiddleware(
ILogFileEndpointHandler endpointHandler, IOptionsMonitor<ManagementOptions> managementOptionsMonitor, ILoggerFactory loggerFactory)
: EndpointMiddleware<object?, string>(endpointHandler, managementOptionsMonitor, loggerFactory)
{
protected override async Task<string> InvokeEndpointHandlerAsync(object? request, CancellationToken cancellationToken)
{
return await EndpointHandler.InvokeAsync(request, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 Steeltoe.Management.Configuration;

namespace Steeltoe.Management.Endpoint.Actuators.Logfile;

public sealed class LogFileEndpointOptions : EndpointOptions

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_macOS)

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'LogFileEndpointOptions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_macOS)

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'implicit constructor for 'LogFileEndpointOptions'' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_ubuntu)

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'LogFileEndpointOptions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management (Management_ubuntu)

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'implicit constructor for 'LogFileEndpointOptions'' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe Package

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'LogFileEndpointOptions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe.Management

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'LogFileEndpointOptions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 9 in src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs

View check run for this annotation

Azure Pipelines / Steeltoe Sonar Analysis

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs#L9

src/Management/src/Endpoint/Actuators/LogFile/LogFileEndpointOptions.cs(9,21): Error RS0016: Symbol 'LogFileEndpointOptions' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
/// <summary>
/// Gets or sets the file path to the log file on disk. The path can be absolute or relative to
/// <see cref="System.Reflection.Assembly.GetEntryAssembly()" />.
/// </summary>
public string? FilePath { get; set; }
}
12 changes: 12 additions & 0 deletions src/Management/src/Endpoint/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static Steeltoe.Management.Endpoint.Actuators.Info.EndpointServiceCollectionExte
static Steeltoe.Management.Endpoint.Actuators.Info.EndpointServiceCollectionExtensions.AddInfoActuator(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, bool configureMiddleware) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.Info.EndpointServiceCollectionExtensions.AddInfoContributor(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Type! infoContributorType) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.Info.EndpointServiceCollectionExtensions.AddInfoContributor<T>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.LogFile.EndpointServiceCollectionExtensions.AddLogFileActuator(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.LogFile.EndpointServiceCollectionExtensions.AddLogFileActuator(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, bool configureMiddleware) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.Loggers.EndpointServiceCollectionExtensions.AddLoggersActuator(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.Loggers.EndpointServiceCollectionExtensions.AddLoggersActuator(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, bool configureMiddleware) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Steeltoe.Management.Endpoint.Actuators.Loggers.LoggersResponse.Error.get -> Steeltoe.Management.Endpoint.Actuators.Loggers.LoggersResponse!
Expand Down Expand Up @@ -262,6 +264,16 @@ Steeltoe.Management.Endpoint.Actuators.Info.InfoBuilder.WithInfo(string! key, ob
Steeltoe.Management.Endpoint.Actuators.Info.InfoBuilder.WithInfo(System.Collections.Generic.IDictionary<string!, object!>! details) -> Steeltoe.Management.Endpoint.Actuators.Info.InfoBuilder!
Steeltoe.Management.Endpoint.Actuators.Info.InfoEndpointOptions
Steeltoe.Management.Endpoint.Actuators.Info.InfoEndpointOptions.InfoEndpointOptions() -> void
Steeltoe.Management.Endpoint.Actuators.LogFile.EndpointServiceCollectionExtensions
Steeltoe.Management.Endpoint.Actuators.LogFile.ILogFileEndpointHandler
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointHandler
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointHandler.InvokeAsync(object? argument, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<string!>!
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointHandler.LogFileEndpointHandler(Microsoft.Extensions.Options.IOptionsMonitor<Steeltoe.Management.Endpoint.Actuators.Logfile.LogfileEndpointOptions!>! optionsMonitorMonitor, Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> void
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointHandler.Options.get -> Steeltoe.Management.Configuration.EndpointOptions!
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointOptions
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointOptions.FilePath.get -> string?
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointOptions.FilePath.set -> void
Steeltoe.Management.Endpoint.Actuators.LogFile.LogFileEndpointOptions.LogFileEndpointOptions() -> void
Steeltoe.Management.Endpoint.Actuators.Loggers.EndpointServiceCollectionExtensions
Steeltoe.Management.Endpoint.Actuators.Loggers.ILoggersEndpointHandler
Steeltoe.Management.Endpoint.Actuators.Loggers.LoggerGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public async Task CloudFoundryEndpointMiddleware_ReturnsExpectedData()
links.Entries["refresh"].Href.Should().Be("http://localhost/cloudfoundryapplication/refresh");
links.Entries["mappings"].Href.Should().Be("http://localhost/cloudfoundryapplication/mappings");
links.Entries["loggers"].Href.Should().Be("http://localhost/cloudfoundryapplication/loggers");
links.Entries["logfile"].Href.Should().Be("http://localhost/cloudfoundryapplication/logfile");
links.Entries["self"].Href.Should().Be("http://localhost/cloudfoundryapplication");
links.Entries["threaddump"].Href.Should().Be("http://localhost/cloudfoundryapplication/threaddump");
links.Entries.Should().HaveCount(12);
links.Entries.Should().HaveCount(13);
}

[Fact]
Expand Down Expand Up @@ -119,6 +120,10 @@ public async Task CloudFoundryEndpointMiddleware_ServiceContractNotBroken()
"href": "http://localhost/cloudfoundryapplication/beans",
"templated": false
},
"logfile": {
"href": "http://localhost/cloudfoundryapplication/logfile",
"templated": false
},
"self": {
"href": "http://localhost/cloudfoundryapplication",
"templated": false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 System.Net;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Steeltoe.Common.TestResources;
using Steeltoe.Common.TestResources.IO;

namespace Steeltoe.Management.Endpoint.Test.Actuators.Logfile;

public sealed class EndpointMiddlewareTest : BaseTest
{
private static readonly Dictionary<string, string?> AppSettings = new()
{
["Logging:Console:IncludeScopes"] = "false",
["Logging:LogLevel:Default"] = "Warning",
["Logging:LogLevel:TestApp"] = "Information",
["Logging:LogLevel:Steeltoe"] = "Information",
["management:endpoints:enabled"] = "true",
["management:endpoints:actuator:exposure:include:0"] = "*"
};

private readonly TempFile _tempLogFile = new();

[Fact]
public async Task LogFileActuator_ReturnsExpectedData()
{
AppSettings["management:endpoints:logfile:filePath"] = _tempLogFile.FullPath;
await File.WriteAllTextAsync(_tempLogFile.FullPath, "This is a test log.");

WebHostBuilder builder = TestWebHostBuilderFactory.Create();
builder.UseStartup<Startup>();
builder.ConfigureAppConfiguration((_, configuration) => configuration.AddInMemoryCollection(AppSettings));

using IWebHost app = builder.Build();
await app.StartAsync();

using HttpClient client = app.GetTestClient();
HttpResponseMessage response = await client.GetAsync(new Uri("http://localhost/actuator/logfile"));
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

string actualLogContent = await response.Content.ReadAsStringAsync();

// assert
actualLogContent.Trim().Should().BeEquivalentTo("\"This is a test log.\"");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Steeltoe.Management.Endpoint.Actuators.Logfile;

namespace Steeltoe.Management.Endpoint.Test.Actuators.Logfile;

public sealed class EndpointServiceCollectionTest : BaseTest
{
[Fact]
public async Task AddLogFileActuator_AddsCorrectServices()
{
var services = new ServiceCollection();
services.AddSingleton(TestHostEnvironmentFactory.Create());

var appSettings = new Dictionary<string, string?>
{
["management:endpoints:logfile:path"] = "/some",
["management:endpoints:logfile:filePath"] = "/var/logs/app.log"
};

var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(appSettings);
IConfiguration configuration = configurationBuilder.Build();

services.AddSingleton(configuration);
services.AddLogging();
services.AddLogFileActuator();
await using ServiceProvider serviceProvider = services.BuildServiceProvider(true);

var options = serviceProvider.GetRequiredService<IOptionsMonitor<LogFileEndpointOptions>>();
Assert.Equal("/some", options.CurrentValue.Path);

var handler = serviceProvider.GetService<ILogFileEndpointHandler>();
Assert.NotNull(handler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 Steeltoe.Management.Configuration;
using Steeltoe.Management.Endpoint.Actuators.Logfile;

namespace Steeltoe.Management.Endpoint.Test.Actuators.Logfile;

public sealed class LogFileEndpointOptionsTest : BaseTest
{
[Fact]
public void AppliesDefaults()
{
LogFileEndpointOptions options = GetOptionsFromSettings<LogFileEndpointOptions, ConfigureLogFileEndpointOptions>();

options.Id.Should().Be("logfile");
options.RequiredPermissions.Should().Be(EndpointPermissions.Restricted);
options.Path.Should().Be("logfile");
options.FilePath.Should().BeNull();
options.AllowedVerbs.Should().Contain("Get");
options.AllowedVerbs.Should().HaveCount(1);
}

[Fact]
public void CanOverrideDefaults()
{
var appSettings = new Dictionary<string, string?>
{
["management:endpoints:logfile:path"] = "testPath",
["management:endpoints:logfile:filePath"] = "logs/application.log"
};

LogFileEndpointOptions options = GetOptionsFromSettings<LogFileEndpointOptions, ConfigureLogFileEndpointOptions>(appSettings);

options.Id.Should().Be("logfile");
options.RequiredPermissions.Should().Be(EndpointPermissions.Restricted);
options.Path.Should().Be("testPath");
options.AllowedVerbs.Should().Contain("Get");
options.FilePath.Should().Be("logs/application.log");
options.AllowedVerbs.Should().Contain("Get");
options.AllowedVerbs.Should().HaveCount(1);
}
}
Loading
Loading