-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log esdb version periodically in the server logs
- Loading branch information
Showing
6 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Collections.Generic; | ||
using Serilog; | ||
using Serilog.Events; | ||
|
||
namespace EventStore.Core.Tests.Fakes; | ||
|
||
public class FakeLogger : ILogger { | ||
public List<LogEvent> LogMessages { get; } = new(); | ||
|
||
public void Write(LogEvent logEvent) { | ||
LogMessages.Add(logEvent); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/EventStore.Core.Tests/Services/PeriodicLogs/PeriodicallyLoggingServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Linq; | ||
using EventStore.Core.Messages; | ||
using EventStore.Core.Services.PeriodicLogs; | ||
using EventStore.Core.Services.TimerService; | ||
using EventStore.Core.Tests.Fakes; | ||
using NUnit.Framework; | ||
|
||
namespace EventStore.Core.Tests.Services.PeriodicLogs; | ||
|
||
public class PeriodicallyLoggingServiceTests { | ||
|
||
private FakePublisher _publisher; | ||
private FakeLogger _logger; | ||
private string _esVersion; | ||
|
||
[SetUp] | ||
public void SetUp() { | ||
_publisher = new(); | ||
_logger = new FakeLogger(); | ||
_esVersion = "0.0.0.0"; | ||
} | ||
|
||
[Test] | ||
public void on_start() { | ||
// given | ||
var sut = new PeriodicallyLoggingService(_publisher, _esVersion, _logger); | ||
|
||
// when | ||
sut.Handle(new SystemMessage.SystemStart()); | ||
|
||
// then | ||
Assert.IsInstanceOf<MonitoringMessage.CheckEsVersion>(_publisher.Messages.Single()); | ||
Assert.IsEmpty(_logger.LogMessages); | ||
} | ||
|
||
[Test] | ||
public void log_es_version_periodically() { | ||
// given | ||
var sut = new PeriodicallyLoggingService(_publisher, _esVersion, _logger); | ||
|
||
// when | ||
sut.Handle(new MonitoringMessage.CheckEsVersion()); | ||
|
||
// then | ||
var schedule = (TimerMessage.Schedule)_publisher.Messages.Single(); | ||
Assert.AreEqual(TimeSpan.FromHours(12), schedule.TriggerAfter); | ||
Assert.IsInstanceOf<MonitoringMessage.CheckEsVersion>(schedule.ReplyMessage); | ||
|
||
var logMessage = _logger.LogMessages.Single(); | ||
Assert.AreEqual($"Current version of Event Store is : \"0.0.0.0\" ", logMessage.RenderMessage()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/EventStore.Core/Services/PeriodicLogs/PeriodicallyLoggingService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using EventStore.Common.Utils; | ||
using EventStore.Core.Bus; | ||
using EventStore.Core.Messages; | ||
using EventStore.Core.Messaging; | ||
using EventStore.Core.Services.TimerService; | ||
using Serilog; | ||
|
||
namespace EventStore.Core.Services.PeriodicLogs; | ||
|
||
public class PeriodicallyLoggingService : | ||
IHandle<SystemMessage.SystemStart>, | ||
IHandle<MonitoringMessage.CheckEsVersion> { | ||
|
||
private static readonly TimeSpan _interval = TimeSpan.FromHours(12); | ||
|
||
private readonly IPublisher _publisher; | ||
private readonly string _esVersion; | ||
private readonly ILogger _logger; | ||
private readonly TimerMessage.Schedule _esVersionScheduleLog; | ||
|
||
public PeriodicallyLoggingService(IPublisher publisher, string esVersion, ILogger logger) { | ||
Ensure.NotNull(publisher, nameof(publisher)); | ||
Ensure.NotNull(logger, nameof(logger)); | ||
|
||
_publisher = publisher; | ||
_esVersion = esVersion; | ||
_logger = logger; | ||
_esVersionScheduleLog = TimerMessage.Schedule.Create(_interval, new PublishEnvelope(publisher), | ||
new MonitoringMessage.CheckEsVersion()); | ||
} | ||
|
||
public void Handle(SystemMessage.SystemStart message) { | ||
_publisher.Publish(new MonitoringMessage.CheckEsVersion()); | ||
} | ||
|
||
public void Handle(MonitoringMessage.CheckEsVersion message) { | ||
_logger.Information("Current version of Event Store is : {esVersion} ", _esVersion); | ||
_publisher.Publish(_esVersionScheduleLog); | ||
} | ||
|
||
} |