Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -20,7 +20,7 @@ public class AuditThroughputCollectorHostedService(

protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
logger.LogInformation($"Starting {nameof(AuditThroughputCollectorHostedService)}");
logger.LogInformation("Starting {ServiceName}", nameof(AuditThroughputCollectorHostedService));

try
{
Expand All @@ -42,14 +42,14 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
logger.LogInformation($"Stopping {nameof(AuditThroughputCollectorHostedService)}");
logger.LogInformation("Stopping {ServiceName}", nameof(AuditThroughputCollectorHostedService));
}
}

async Task GatherThroughput(CancellationToken cancellationToken)
{
var utcYesterday = DateOnly.FromDateTime(timeProvider.GetUtcNow().DateTime).AddDays(-1);
logger.LogInformation($"Gathering throughput from audit for {utcYesterday.ToShortDateString()}");
logger.LogInformation("Gathering throughput from audit for {AuditDate}", utcYesterday.ToShortDateString());

await VerifyAuditInstances(cancellationToken);

Expand Down Expand Up @@ -115,18 +115,18 @@ async Task VerifyAuditInstances(CancellationToken cancellationToken)
{
if (remote.Status == "online" || remote.SemanticVersion is not null)
{
logger.LogInformation($"ServiceControl Audit instance at {remote.ApiUri} detected running version {remote.SemanticVersion}");
logger.LogInformation("ServiceControl Audit instance at {RemoteApiUri} detected running version {RemoteSemanticVersion}", remote.ApiUri, remote.SemanticVersion);
}
else
{
logger.LogWarning($"Unable to determine the version of one or more ServiceControl Audit instances. For the instance with URI {remote.ApiUri}, the status was '{remote.Status}' and the version string returned was '{remote.VersionString}'.");
logger.LogWarning("Unable to determine the version of one or more ServiceControl Audit instances. For the instance with URI {RemoteApiUri}, the status was '{RemoteStatus}' and the version string returned was '{RemoteVersionString}'.", remote.ApiUri, remote.Status, remote.VersionString);
}
}

var allHaveAuditCounts = remotesInfo.All(auditQuery.ValidRemoteInstances);
if (!allHaveAuditCounts)
{
logger.LogWarning($"At least one ServiceControl Audit instance is either not running the required version ({auditQuery.MinAuditCountsVersion}) or is not configured for at least 2 days of retention. Audit throughput will not be available.");
logger.LogWarning("At least one ServiceControl Audit instance is either not running the required version ({RequiredAuditVersion}) or is not configured for at least 2 days of retention. Audit throughput will not be available.", auditQuery.MinAuditCountsVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ static ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<Ke

if (brokerThroughputQuery.HasInitialisationErrors(out var errorMessage))
{
logger.LogError($"Could not start {nameof(BrokerThroughputCollectorHostedService)}, due to initialisation errors:\n{errorMessage}");
logger.LogError("Could not start {ServiceName}, due to initialisation errors:\n{InitializationErrors}", nameof(BrokerThroughputCollectorHostedService), errorMessage);
return;
}

logger.LogInformation($"Starting {nameof(BrokerThroughputCollectorHostedService)}");
logger.LogInformation("Starting {ServiceName}", nameof(BrokerThroughputCollectorHostedService));

try
{
Expand All @@ -55,7 +55,7 @@ static ReadOnlyDictionary<string, string> LoadBrokerSettingValues(IEnumerable<Ke
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
logger.LogInformation($"Stopping {nameof(BrokerThroughputCollectorHostedService)}");
logger.LogInformation("Stopping {ServiceName}", nameof(BrokerThroughputCollectorHostedService));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ async Task Handle(MessageContext message, CancellationToken cancellationToken)

public async Task StartAsync(CancellationToken cancellationToken)
{
logger.LogInformation($"Starting {nameof(MonitoringThroughputHostedService)}");
logger.LogInformation("Starting {ServiceName}", nameof(MonitoringThroughputHostedService));

transportInfrastructure = await transportCustomization.CreateTransportInfrastructure(ServiceControlSettings.ServiceControlThroughputDataQueue, transportSettings, Handle, (_, __) => Task.FromResult(ErrorHandleResult.Handled), (_, __) => Task.CompletedTask);
await transportInfrastructure.Receivers[ServiceControlSettings.ServiceControlThroughputDataQueue].StartReceive(cancellationToken);
}

public async Task StopAsync(CancellationToken cancellationToken)
{
logger.LogInformation($"Stopping {nameof(MonitoringThroughputHostedService)}");
logger.LogInformation("Stopping {ServiceName}", nameof(MonitoringThroughputHostedService));

if (transportInfrastructure != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Hosting.Commands;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Abstractions;
using NServiceBus;
using NUnit.Framework;
using Particular.ServiceControl.Hosting;
Expand Down Expand Up @@ -57,7 +58,7 @@ public async Task CanRunMaintenanceMode()
public async Task CanRunImportFailedMessagesMode()
=> await new TestableImportFailedErrorsCommand().Execute(new HostArguments(Array.Empty<string>()), settings);

class TestableImportFailedErrorsCommand : ImportFailedErrorsCommand
class TestableImportFailedErrorsCommand() : ImportFailedErrorsCommand()
{
protected override EndpointConfiguration CreateEndpointConfiguration(Settings settings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using AcceptanceTesting.EndpointTemplates;
using Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NServiceBus.Routing;
Expand Down Expand Up @@ -146,7 +147,7 @@ public class MyContext : ScenarioContext
public class MessageThatWillFail : ICommand;

public class FakeReturnToSender(IErrorMessageDataStore errorMessageStore, MyContext myContext)
: ReturnToSender(errorMessageStore)
: ReturnToSender(errorMessageStore, NullLogger<ReturnToSender>.Instance)
{
public override Task HandleMessage(MessageContext message, IMessageDispatcher sender, string errorQueueTransportAddress, CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Abstractions;
using NLog;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NServiceBus;
using ServiceControl.Infrastructure;
using Settings;

class ImportFailedAuditsCommand(ILogger<ImportFailedAuditsCommand> logger) : AbstractCommand
class ImportFailedAuditsCommand : AbstractCommand
{
public override async Task Execute(HostArguments args, Settings settings)
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public override async Task Execute(HostArguments args, Settings settings)
}
catch (OperationCanceledException e) when (tokenSource.IsCancellationRequested)
{
logger.LogInformation(e, "Cancelled");
LoggerUtil.CreateStaticLogger<ImportFailedAuditsCommand>().LogInformation(e, "Cancelled");
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Settings;
using Transports;

class SetupCommand() : AbstractCommand
class SetupCommand : AbstractCommand
{
public override async Task Execute(HostArguments args, Settings settings)
{
Expand Down
19 changes: 10 additions & 9 deletions src/ServiceControl.Persistence.Tests/MonitoringDataStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using NUnit.Framework;
using ServiceControl.Monitoring;
using ServiceControl.Operations;
Expand All @@ -13,7 +14,7 @@ class MonitoringDataStoreTests : PersistenceTestBase
[Test]
public async Task Endpoints_load_from_dataStore_into_monitor()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);

Expand All @@ -26,7 +27,7 @@ public async Task Endpoints_load_from_dataStore_into_monitor()
[Test]
public async Task Endpoints_added_more_than_once_are_treated_as_same_endpoint()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);
await MonitoringDataStore.CreateIfNotExists(endpoint1);
Expand All @@ -40,7 +41,7 @@ public async Task Endpoints_added_more_than_once_are_treated_as_same_endpoint()
[Test]
public async Task Updating_existing_endpoint_does_not_create_new_ones()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);
await MonitoringDataStore.CreateOrUpdate(endpoint1, endpointInstanceMonitoring);
Expand All @@ -54,7 +55,7 @@ public async Task Updating_existing_endpoint_does_not_create_new_ones()
[Test]
public async Task Endpoint_is_created_if_doesnt_exist()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
var endpoint2 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host2", Name = "Name2" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);
Expand All @@ -69,7 +70,7 @@ public async Task Endpoint_is_created_if_doesnt_exist()
[Test]
public async Task Endpoint_is_created_if_doesnt_exist_on_update()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
var endpoint2 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host2", Name = "Name2" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);
Expand All @@ -84,7 +85,7 @@ public async Task Endpoint_is_created_if_doesnt_exist_on_update()
[Test]
public async Task Endpoint_is_updated()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);

Expand All @@ -93,7 +94,7 @@ public async Task Endpoint_is_updated()
Assert.That(endpointInstanceMonitoring.IsMonitored(endpointInstanceMonitoring.GetEndpoints()[0].Id), Is.False);

await MonitoringDataStore.UpdateEndpointMonitoring(endpoint1, true);
endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);

CompleteDatabaseOperation();
await MonitoringDataStore.WarmupMonitoringFromPersistence(endpointInstanceMonitoring);
Expand All @@ -104,7 +105,7 @@ public async Task Endpoint_is_updated()
[Test]
public async Task Endpoint_is_deleted()
{
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
var endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);
var endpoint1 = new EndpointDetails() { HostId = Guid.NewGuid(), Host = "Host1", Name = "Name1" };
await MonitoringDataStore.CreateIfNotExists(endpoint1);

Expand All @@ -114,7 +115,7 @@ public async Task Endpoint_is_deleted()

await MonitoringDataStore.Delete(endpointInstanceMonitoring.GetEndpoints()[0].Id);

endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents());
endpointInstanceMonitoring = new EndpointInstanceMonitoring(new FakeDomainEvents(), NullLogger<EndpointInstanceMonitor>.Instance);

CompleteDatabaseOperation();
await MonitoringDataStore.WarmupMonitoringFromPersistence(endpointInstanceMonitoring);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MessageFailures;
using MessageFailures.Api;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using NServiceBus.Extensibility;
using NServiceBus.Transport;
using NUnit.Framework;
Expand Down Expand Up @@ -47,7 +48,7 @@ public async Task It_removes_staging_id_header()
};
var message = CreateMessage(Guid.NewGuid().ToString(), headers);

await new ReturnToSender(null).HandleMessage(message, sender, "error");
await new ReturnToSender(null, NullLogger<ReturnToSender>.Instance).HandleMessage(message, sender, "error");

Assert.That(sender.Message.Headers.ContainsKey("ServiceControl.Retry.StagingId"), Is.False);
}
Expand All @@ -66,7 +67,7 @@ public async Task It_fetches_the_body_from_storage_if_provided()
};
var message = CreateMessage(Guid.NewGuid().ToString(), headers);

await new ReturnToSender(new FakeErrorMessageDataStore()).HandleMessage(message, sender, "error");
await new ReturnToSender(new FakeErrorMessageDataStore(), NullLogger<ReturnToSender>.Instance).HandleMessage(message, sender, "error");

Assert.That(Encoding.UTF8.GetString(sender.Message.Body.ToArray()), Is.EqualTo("MessageBodyId"));
}
Expand All @@ -84,7 +85,7 @@ public async Task It_uses_retry_to_if_provided()
};
var message = CreateMessage(Guid.NewGuid().ToString(), headers);

await new ReturnToSender(null).HandleMessage(message, sender, "error");
await new ReturnToSender(null, NullLogger<ReturnToSender>.Instance).HandleMessage(message, sender, "error");

Assert.Multiple(() =>
{
Expand All @@ -105,7 +106,7 @@ public async Task It_sends_directly_to_target_if_retry_to_is_not_provided()
};
var message = CreateMessage(Guid.NewGuid().ToString(), headers);

await new ReturnToSender(null).HandleMessage(message, sender, "error");
await new ReturnToSender(null, NullLogger<ReturnToSender>.Instance).HandleMessage(message, sender, "error");

Assert.Multiple(() =>
{
Expand All @@ -129,7 +130,7 @@ public async Task It_restores_body_id_and_target_addres_after_failure()

try
{
await new ReturnToSender(null).HandleMessage(message, sender, "error");
await new ReturnToSender(null, NullLogger<ReturnToSender>.Instance).HandleMessage(message, sender, "error");
}
catch (Exception)
{
Expand Down
Loading