Skip to content

Commit

Permalink
RavenDB-20503 adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ppekrol committed Jan 11, 2024
1 parent 391e9ee commit f472df3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
}
Expand Down
16 changes: 8 additions & 8 deletions src/Raven.Server/Documents/Handlers/Admin/AdminLogsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public async Task Download()
if (to != null && logDateTime > to)
continue;
}

try
{
var entry = archive.CreateEntry(fileName);
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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
Expand All @@ -263,7 +263,7 @@ public async Task SetMicrosoftConfiguration()

NoContentStatus();
}

[RavenAction("/admin/logs/microsoft/enable", "POST", AuthorizationStatus.Operator)]
public Task EnableMicrosoftLog()
{
Expand All @@ -273,7 +273,7 @@ public Task EnableMicrosoftLog()
NoContentStatus();
return Task.CompletedTask;
}

[RavenAction("/admin/logs/microsoft/disable", "POST", AuthorizationStatus.Operator)]
public Task DisableMicrosoftLog()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyValuePair<string, SparrowLoggerWrapper>> _loggers;
private readonly NotificationCenter.NotificationCenter _notificationCenter;
private readonly ConcurrentDictionary<StringSegment, LogLevel> _configuration = new ConcurrentDictionary<StringSegment, LogLevel>();
private readonly ConcurrentDictionary<StringSegment, LogLevel> _configuration = new ConcurrentDictionary<StringSegment, LogLevel>();

public MicrosoftLoggingConfiguration(IEnumerable<KeyValuePair<string, SparrowLoggerWrapper>> loggers,NotificationCenter.NotificationCenter notificationCenter)
public MicrosoftLoggingConfiguration(IEnumerable<KeyValuePair<string, SparrowLoggerWrapper>> loggers, NotificationCenter.NotificationCenter notificationCenter)
{
_loggers = loggers;
_notificationCenter = notificationCenter;
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -126,7 +128,7 @@ public void ReadConfigurationAsync(BlittableJsonReaderObject blitConfiguration,
HandleReadConfigurationFailure(blitConfiguration, e);
}
}

private void ReadConfiguration(BlittableJsonReaderObject jConfiguration, string rootCategory)
{
jConfiguration.BlittableValidation();
Expand All @@ -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.";
Expand Down

0 comments on commit f472df3

Please sign in to comment.