Skip to content

Commit

Permalink
Merge pull request #2775 from Particular/change-log-level
Browse files Browse the repository at this point in the history
Remove the IsDebugEnabled check from audit expiration
  • Loading branch information
WilliamBZA authored Feb 1, 2022
2 parents 7f6ba57 + 62ff0e5 commit 019c41b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace ServiceControl.Audit.Auditing.BodyStorage
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ public Task StopAsync(CancellationToken cancellationToken)
}

static readonly ILog Logger = LogManager.GetLogger(typeof(EmbeddedRavenDbHostedService));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,18 @@ public static void Clean(int deletionBatchSize, DocumentDatabase database, DateT

var deletedAuditDocuments = Chunker.ExecuteInChunks(items.Count, (itemsForBatch, db, s, e) =>
{
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} audit documents.");
}
logger.Debug($"Batching deletion of {s}-{e} audit documents.");

var results = db.Batch(itemsForBatch.GetRange(s, e - s + 1), CancellationToken.None);
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} audit documents completed.");
}
logger.Debug($"Batching deletion of {s}-{e} audit documents completed.");

return results.Count(x => x.Deleted == true);
}, items, database, cancellationToken);

var deletedAttachments = Chunker.ExecuteInChunks(attachments.Count, (att, db, s, e) =>
{
var deleted = 0;
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} attachment audit documents.");
}
logger.Debug($"Batching deletion of {s}-{e} attachment audit documents.");

db.TransactionalStorage.Batch(accessor =>
{
Expand All @@ -119,27 +110,18 @@ public static void Clean(int deletionBatchSize, DocumentDatabase database, DateT
deleted++;
}
});
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} attachment audit documents completed.");
}
logger.Debug($"Batching deletion of {s}-{e} attachment audit documents completed.");

return deleted;
}, attachments, database, cancellationToken);

if (deletedAttachments + deletedAuditDocuments == 0)
{
if (logger.IsDebugEnabled)
{
logger.Debug("No expired audit documents found");
}
logger.Debug("No expired audit documents found");
}
else
{
if (logger.IsDebugEnabled)
{
logger.Debug($"Deleted {deletedAuditDocuments} expired audit documents and {deletedAttachments} message body attachments. Batch execution took {stopwatch.ElapsedMilliseconds} ms");
}
logger.Debug($"Deleted {deletedAuditDocuments} expired audit documents and {deletedAttachments} message body attachments. Batch execution took {stopwatch.ElapsedMilliseconds} ms");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using NServiceBus.Logging;
using Raven.Abstractions;
using Raven.Abstractions.Logging;
using Raven.Database;
using ServiceControl.SagaAudit;
using Settings;
Expand All @@ -15,7 +15,7 @@ public static Task<TimerJobExecutionResult> RunCleanup(int deletionBatchSize, Do
{
var threshold = SystemTime.UtcNow.Add(-settings.AuditRetentionPeriod);

logger.Debug("Trying to find expired ProcessedMessage, SagaHistory and KnownEndpoint documents to delete (with threshold {0})", threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
logger.Debug($"Trying to find expired ProcessedMessage, SagaHistory and KnownEndpoint documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
AuditMessageCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
KnownEndpointsCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
SagaHistoryCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Raven.Abstractions.Logging;
using NServiceBus.Logging;
using Raven.Database;
using Raven.Database.Plugins;

Expand Down Expand Up @@ -50,12 +50,12 @@ public void Execute(DocumentDatabase database)
var due = TimeSpan.FromSeconds(deleteFrequencyInSeconds);
var deletionBatchSize = RavenBootstrapper.Settings.ExpirationProcessBatchSize;

logger.Info("Running deletion of expired documents every {0} seconds", deleteFrequencyInSeconds);
logger.Info("Deletion batch size set to {0}", deletionBatchSize);
logger.Info("Retention period for audits and saga history is {0}", RavenBootstrapper.Settings.AuditRetentionPeriod);
logger.Info($"Running deletion of expired documents every {deleteFrequencyInSeconds} seconds");
logger.Info($"Deletion batch size set to {deletionBatchSize}");
logger.Info($"Retention period for audits and saga history is {RavenBootstrapper.Settings.AuditRetentionPeriod}");

timer = new AsyncTimer(
token => ExpiredDocumentsCleaner.RunCleanup(deletionBatchSize, database, RavenBootstrapper.Settings, token), due, due, e => { logger.ErrorException("Error when trying to find expired documents", e); });
token => ExpiredDocumentsCleaner.RunCleanup(deletionBatchSize, database, RavenBootstrapper.Settings, token), due, due, e => { logger.Error("Error when trying to find expired documents", e); });
}

ILog logger = LogManager.GetLogger(typeof(ExpiredDocumentsCleanerBundle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,22 @@ public static void Clean(int deletionBatchSize, DocumentDatabase database, DateT

var deleteKnownEndpointDocuments = Chunker.ExecuteInChunks(items.Count, (itemsForBatch, db, s, e) =>
{
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} known endpoint documents.");
}
logger.Debug($"Batching deletion of {s}-{e} known endpoint documents.");

var results = db.Batch(itemsForBatch.GetRange(s, e - s + 1), CancellationToken.None);
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} known endpoint documents completed.");
}
logger.Debug($"Batching deletion of {s}-{e} known endpoint documents completed.");

return results.Count(x => x.Deleted == true);
}, items, database, cancellationToken);


if (deleteKnownEndpointDocuments == 0)
{
if (logger.IsDebugEnabled)
{
logger.Debug("No expired known endpoints documents found");
}
logger.Debug("No expired known endpoints documents found");
}
else
{
if (logger.IsDebugEnabled)
{
logger.Debug($"Deleted {deleteKnownEndpointDocuments} expired known endpoint documents. Batch execution took {stopwatch.ElapsedMilliseconds} ms");
}
logger.Debug($"Deleted {deleteKnownEndpointDocuments} expired known endpoint documents. Batch execution took {stopwatch.ElapsedMilliseconds} ms");
}
}

Expand Down
20 changes: 4 additions & 16 deletions src/ServiceControl.SagaAudit/SagaHistoryCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,21 @@ public static void Clean(int deletionBatchSize, DocumentDatabase database, DateT

var deletionCount = Chunker.ExecuteInChunks(items.Count, (itemsForBatch, db, s, e) =>
{
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} saga history documents.");
}
logger.Debug($"Batching deletion of {s}-{e} saga history documents.");

var results = db.Batch(itemsForBatch.GetRange(s, e - s + 1), CancellationToken.None);
if (logger.IsDebugEnabled)
{
logger.Debug($"Batching deletion of {s}-{e} saga history documents completed.");
}
logger.Debug($"Batching deletion of {s}-{e} saga history documents completed.");

return results.Count(x => x.Deleted == true);
}, items, database, cancellationToken);

if (deletionCount == 0)
{
if (logger.IsDebugEnabled)
{
logger.Debug("No expired saga history documents found");
}
logger.Debug("No expired saga history documents found");
}
else
{
if (logger.IsDebugEnabled)
{
logger.Debug($"Deleted {deletionCount} expired saga history documents. Batch execution took {stopwatch.ElapsedMilliseconds} ms");
}
logger.Debug($"Deleted {deletionCount} expired saga history documents. Batch execution took {stopwatch.ElapsedMilliseconds} ms");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Threading;
using System.Threading.Tasks;
using BackgroundTasks;
using NServiceBus.Logging;
using Raven.Abstractions;
using Raven.Abstractions.Logging;
using Raven.Database;
using SagaAudit;
using ServiceBus.Management.Infrastructure.Settings;
Expand All @@ -16,19 +16,19 @@ public static Task<TimerJobExecutionResult> RunCleanup(int deletionBatchSize, Do
{
var threshold = SystemTime.UtcNow.Add(-settings.ErrorRetentionPeriod);

logger.Debug("Trying to find expired FailedMessage documents to delete (with threshold {0})", threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
logger.Debug($"Trying to find expired FailedMessage documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
ErrorMessageCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);

threshold = SystemTime.UtcNow.Add(-settings.EventsRetentionPeriod);

logger.Debug("Trying to find expired EventLogItem documents to delete (with threshold {0})", threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
logger.Debug($"Trying to find expired EventLogItem documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
EventLogItemsCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);

if (settings.AuditRetentionPeriod.HasValue)
{
threshold = SystemTime.UtcNow.Add(-settings.AuditRetentionPeriod.Value);

logger.Debug("Trying to find expired ProcessedMessage and SagaHistory documents to delete (with threshold {0})", threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture));
logger.Debug($"Trying to find expired ProcessedMessage and SagaHistory documents to delete (with threshold {threshold.ToString(Default.DateTimeFormatsToWrite, CultureInfo.InvariantCulture)})");
AuditMessageCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
SagaHistoryCleaner.Clean(deletionBatchSize, database, threshold, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using BackgroundTasks;
using Raven.Abstractions.Logging;
using NServiceBus.Logging;
using Raven.Database;
using Raven.Database.Plugins;

Expand Down Expand Up @@ -51,19 +51,19 @@ public void Execute(DocumentDatabase database)
var due = TimeSpan.FromSeconds(deleteFrequencyInSeconds);
var deletionBatchSize = RavenBootstrapper.Settings.ExpirationProcessBatchSize;

logger.Info("Running deletion of expired documents every {0} seconds", deleteFrequencyInSeconds);
logger.Info("Deletion batch size set to {0}", deletionBatchSize);
logger.Info("Retention period for errors is {0}", RavenBootstrapper.Settings.ErrorRetentionPeriod);
logger.Info($"Running deletion of expired documents every {deleteFrequencyInSeconds} seconds");
logger.Info($"Deletion batch size set to {deletionBatchSize}");
logger.Info($"Retention period for errors is {RavenBootstrapper.Settings.ErrorRetentionPeriod}");

var auditRetention = RavenBootstrapper.Settings.AuditRetentionPeriod;

if (auditRetention.HasValue)
{
logger.Info("Retention period for audits and saga history is {0}", RavenBootstrapper.Settings.AuditRetentionPeriod);
logger.InfoFormat("Retention period for audits and saga history is {0}", RavenBootstrapper.Settings.AuditRetentionPeriod);
}

timer = new TimerJob(
token => ExpiredDocumentsCleaner.RunCleanup(deletionBatchSize, database, RavenBootstrapper.Settings, token), due, due, e => { logger.ErrorException("Error when trying to find expired documents", e); });
token => ExpiredDocumentsCleaner.RunCleanup(deletionBatchSize, database, RavenBootstrapper.Settings, token), due, due, e => { logger.Error("Error when trying to find expired documents", e); });
}

ILog logger = LogManager.GetLogger(typeof(ExpiredDocumentsCleanerBundle));
Expand Down

0 comments on commit 019c41b

Please sign in to comment.