From f472df3e313c3fc0fac390792512869cc11df79b Mon Sep 17 00:00:00 2001 From: Pawel Pekrol Date: Thu, 11 Jan 2024 09:21:45 +0100 Subject: [PATCH] RavenDB-20503 adjustments --- .../Logs/SetLogsConfigurationOperation.cs | 5 ++--- .../Handlers/Admin/AdminLogsHandler.cs | 16 ++++++++-------- .../MicrosoftLoggingConfiguration.cs | 18 ++++++++++-------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Raven.Client/ServerWide/Operations/Logs/SetLogsConfigurationOperation.cs b/src/Raven.Client/ServerWide/Operations/Logs/SetLogsConfigurationOperation.cs index 8e71cfcfdf30..aeb6544dce7d 100644 --- a/src/Raven.Client/ServerWide/Operations/Logs/SetLogsConfigurationOperation.cs +++ b/src/Raven.Client/ServerWide/Operations/Logs/SetLogsConfigurationOperation.cs @@ -12,7 +12,6 @@ namespace Raven.Client.ServerWide.Operations.Logs public class SetLogsConfigurationOperation : IServerOperation { private readonly Parameters _parameters; - private readonly bool _persist; public class Parameters { @@ -42,14 +41,14 @@ public SetLogsConfigurationOperation(Parameters parameters) public RavenCommand GetCommand(DocumentConventions conventions, JsonOperationContext context) { - return new SetLogsConfigurationCommand(_parameters, _persist); + return new SetLogsConfigurationCommand(_parameters); } private class SetLogsConfigurationCommand : RavenCommand { private readonly Parameters _parameters; - public SetLogsConfigurationCommand(Parameters parameters, bool persist) + public SetLogsConfigurationCommand(Parameters parameters) { _parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); } diff --git a/src/Raven.Server/Documents/Handlers/Admin/AdminLogsHandler.cs b/src/Raven.Server/Documents/Handlers/Admin/AdminLogsHandler.cs index adcca66281cf..7899d336d75b 100644 --- a/src/Raven.Server/Documents/Handlers/Admin/AdminLogsHandler.cs +++ b/src/Raven.Server/Documents/Handlers/Admin/AdminLogsHandler.cs @@ -140,7 +140,7 @@ public async Task Download() if (to != null && logDateTime > to) continue; } - + try { var entry = archive.CreateEntry(fileName); @@ -185,7 +185,7 @@ await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBody writer.WriteObject(json); } } - + [RavenAction("/admin/logs/microsoft/configuration", "GET", AuthorizationStatus.Operator)] public async Task GetMicrosoftConfiguration() { @@ -202,7 +202,7 @@ await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBody writer.WriteObject(json); } } - + [RavenAction("/admin/logs/microsoft/state", "GET", AuthorizationStatus.Operator)] public async Task GetMicrosoftLoggersState() { @@ -235,10 +235,10 @@ public async Task SetMicrosoftConfiguration() var parameters = await context.ReadForMemoryAsync(RequestBodyStream(), "logs/configuration"); if (parameters.TryGet("Configuration", out BlittableJsonReaderObject microsoftConfig) == false) throw new InvalidOperationException($"The request body doesn't contain required 'Configuration' property - {parameters}"); - - provider.Configuration.ReadConfigurationAsync(microsoftConfig, context, reset); + + provider.Configuration.ReadConfiguration(microsoftConfig, reset); provider.ApplyConfiguration(); - + if (parameters.TryGet("Persist", out bool persist) && persist) { try @@ -263,7 +263,7 @@ public async Task SetMicrosoftConfiguration() NoContentStatus(); } - + [RavenAction("/admin/logs/microsoft/enable", "POST", AuthorizationStatus.Operator)] public Task EnableMicrosoftLog() { @@ -273,7 +273,7 @@ public Task EnableMicrosoftLog() NoContentStatus(); return Task.CompletedTask; } - + [RavenAction("/admin/logs/microsoft/disable", "POST", AuthorizationStatus.Operator)] public Task DisableMicrosoftLog() { diff --git a/src/Raven.Server/Utils/MicrosoftLogging/MicrosoftLoggingConfiguration.cs b/src/Raven.Server/Utils/MicrosoftLogging/MicrosoftLoggingConfiguration.cs index 95932829a452..79407f2b95b5 100644 --- a/src/Raven.Server/Utils/MicrosoftLogging/MicrosoftLoggingConfiguration.cs +++ b/src/Raven.Server/Utils/MicrosoftLogging/MicrosoftLoggingConfiguration.cs @@ -19,14 +19,14 @@ public class MicrosoftLoggingConfiguration : IEnumerable<(string Category, LogLe private static readonly Logger Logger = LoggingSource.Instance.GetLogger("Server", nameof(MicrosoftLoggingConfiguration)); private const string NotificationKey = "microsoft-configuration-logs-error"; private const AlertType AlertType = NotificationCenter.Notifications.AlertType.MicrosoftLogsConfigurationLoadError; - + private readonly string _notificationId = AlertRaised.GetKey(AlertType, NotificationKey); private readonly IEnumerable> _loggers; private readonly NotificationCenter.NotificationCenter _notificationCenter; - private readonly ConcurrentDictionary _configuration = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _configuration = new ConcurrentDictionary(); - public MicrosoftLoggingConfiguration(IEnumerable> loggers,NotificationCenter.NotificationCenter notificationCenter) + public MicrosoftLoggingConfiguration(IEnumerable> loggers, NotificationCenter.NotificationCenter notificationCenter) { _loggers = loggers; _notificationCenter = notificationCenter; @@ -47,7 +47,7 @@ public LogLevel GetLogLevelForCategory(string categoryName) return LogLevel.None; } - + public IEnumerator<(string Category, LogLevel LogLevel)> GetEnumerator() { foreach (var (category, logLevel) in _configuration) @@ -57,7 +57,7 @@ public IEnumerator<(string Category, LogLevel LogLevel)> GetEnumerator() } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - + public void ReadConfiguration(string configurationPath, JsonOperationContext context, bool shouldThrow, bool reset = true) { FileStream stream; @@ -90,6 +90,7 @@ public void ReadConfiguration(string configurationPath, JsonOperationContext con ReadConfiguration(stream, context, reset); } } + public void ReadConfiguration(Stream streamConfiguration, JsonOperationContext context, bool reset = true) { BlittableJsonReaderObject blitConfiguration = null; @@ -109,7 +110,8 @@ public void ReadConfiguration(Stream streamConfiguration, JsonOperationContext c HandleReadConfigurationFailure(blitConfiguration, e); } } - public void ReadConfigurationAsync(BlittableJsonReaderObject blitConfiguration, JsonOperationContext context, bool reset = true) + + public void ReadConfiguration(BlittableJsonReaderObject blitConfiguration, bool reset = true) { try { @@ -126,7 +128,7 @@ public void ReadConfigurationAsync(BlittableJsonReaderObject blitConfiguration, HandleReadConfigurationFailure(blitConfiguration, e); } } - + private void ReadConfiguration(BlittableJsonReaderObject jConfiguration, string rootCategory) { jConfiguration.BlittableValidation(); @@ -149,7 +151,7 @@ private void ReadConfiguration(BlittableJsonReaderObject jConfiguration, string } } } - + private void HandleReadConfigurationFailure(BlittableJsonReaderObject blitConfiguration, Exception e) { var msg = $"Failed to read and apply Microsoft log configuration.";