Skip to content

Commit

Permalink
Biting the bullet to switch to the provider model
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Mar 26, 2024
1 parent 25ad59e commit 2e7d123
Show file tree
Hide file tree
Showing 52 changed files with 521 additions and 848 deletions.
Expand Up @@ -5,6 +5,7 @@
using Infrastructure.WebApi;
using Microsoft.AspNetCore.Mvc;
using Operations;
using Persistence.RavenDB;
using Raven.Client.Documents;

public class FailedErrorsCountReponse
Expand All @@ -14,14 +15,14 @@ public class FailedErrorsCountReponse

[ApiController]
[Route("api")]
public class FailedErrorsController(IDocumentStore store, ImportFailedErrors failedErrors)
public class FailedErrorsController(IRavenSessionProvider sessionProvider, ImportFailedErrors failedErrors)
: ControllerBase
{
[Route("failederrors/count")]
[HttpGet]
public async Task<FailedErrorsCountReponse> GetFailedErrorsCount()
{
using var session = store.OpenAsyncSession();
using var session = sessionProvider.OpenSession();
var query =
session.Query<FailedErrorImport, FailedErrorImportIndex>().Statistics(out var stats);

Expand Down
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Infrastructure.WebApi;
using Microsoft.AspNetCore.Mvc;
using Persistence.RavenDB;
using Raven.Client.Documents;
using ServiceControl.Recoverability;

Expand All @@ -13,13 +14,13 @@ public class FailedMessageRetriesCountReponse

[ApiController]
[Route("api")]
public class FailedMessageRetriesController(IDocumentStore store) : ControllerBase
public class FailedMessageRetriesController(IRavenSessionProvider sessionProvider) : ControllerBase
{
[Route("failedmessageretries/count")]
[HttpGet]
public async Task<FailedMessageRetriesCountReponse> GetFailedMessageRetriesCount()
{
using var session = store.OpenAsyncSession();
using var session = sessionProvider.OpenSession();
await session.Query<FailedMessageRetry>().Statistics(out var stats).ToListAsync();

Response.WithEtag(stats.ResultEtag.ToString());
Expand Down

This file was deleted.

Expand Up @@ -5,9 +5,7 @@ namespace ServiceControl.AcceptanceTests.RavenDB.Shared;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ServiceBus.Management.Infrastructure.Settings;
using TestSupport;

static class WebApplicationBuilderExtensions
{
Expand All @@ -18,7 +16,6 @@ public static void AddServiceControlTesting(this WebApplicationBuilder hostBuild
hostBuilder.Logging.AddScenarioContextLogging();

hostBuilder.WebHost.UseTestServer(options => options.BaseAddress = new Uri(settings.RootUrl));
hostBuilder.Services.AddSingleton<IHostLifetime, TestServerHostLifetime>();

// This facilitates receiving the test server anywhere where DI is available
hostBuilder.Services.AddSingleton(provider => (TestServer)provider.GetRequiredService<IServer>());
Expand Down
Expand Up @@ -13,7 +13,6 @@ public FailedAuditImportIndex()
select new FailedAuditImport
{
Id = cc.Id,
Message = cc.Message
};
}
}
Expand Down
Expand Up @@ -11,7 +11,6 @@ public void AddPersistence(IServiceCollection services)
{
ConfigureLifecycle(services, databaseConfiguration);

services.AddSingleton<IRavenSessionProvider, RavenSessionProvider>();
services.AddSingleton<IAuditDataStore, RavenAuditDataStore>();
services.AddSingleton<IAuditIngestionUnitOfWorkFactory, RavenAuditIngestionUnitOfWorkFactory>();
services.AddSingleton<IFailedAuditStorage, RavenFailedAuditStorage>();
Expand All @@ -23,6 +22,8 @@ public void AddPersistence(IServiceCollection services)
static void ConfigureLifecycle(IServiceCollection services, DatabaseConfiguration databaseConfiguration)
{
services.AddSingleton(databaseConfiguration);

services.AddSingleton<IRavenSessionProvider, RavenSessionProvider>();
services.AddHostedService<RavenPersistenceLifecycleHostedService>();

var serverConfiguration = databaseConfiguration.ServerConfiguration;
Expand Down
Expand Up @@ -7,20 +7,17 @@
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Persistence.RavenDB;
using Raven.Client.Documents;
using Raven.Client.Documents.Operations.Indexes;

class CheckRavenDBIndexErrors : CustomCheck
class CheckRavenDBIndexErrors(IRavenDocumentStoreProvider documentStoreProvider) : CustomCheck("Error Database Index Errors",
"ServiceControl Health", TimeSpan.FromMinutes(5))
{
public CheckRavenDBIndexErrors(IDocumentStore store)
: base("Error Database Index Errors", "ServiceControl Health", TimeSpan.FromMinutes(5))
public override async Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
this.store = store;
}

public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
var response = store.Maintenance.Send(new GetIndexErrorsOperation());
var documentStore = documentStoreProvider.GetDocumentStore();
var response = await documentStore.Maintenance.SendAsync(new GetIndexErrorsOperation(), cancellationToken);

// Filter response as RavenDB5+ will return entries without errors
var indexErrors = response
Expand Down Expand Up @@ -51,7 +48,5 @@ public override Task<CheckResult> PerformCheck(CancellationToken cancellationTok
}

static readonly ILog Logger = LogManager.GetLogger<CheckRavenDBIndexLag>();

readonly IDocumentStore store;
}
}
Expand Up @@ -7,21 +7,17 @@
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Persistence.RavenDB;
using Raven.Client.Documents;
using Raven.Client.Documents.Operations;
using CustomCheck = NServiceBus.CustomChecks.CustomCheck;

class CheckRavenDBIndexLag : CustomCheck
class CheckRavenDBIndexLag(IRavenDocumentStoreProvider documentStoreProvider) : CustomCheck("Error Database Index Lag", "ServiceControl Health", TimeSpan.FromMinutes(5))
{
public CheckRavenDBIndexLag(IDocumentStore store)
: base("Error Database Index Lag", "ServiceControl Health", TimeSpan.FromMinutes(5))
{
this.store = store;
}

public override async Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
var statistics = await store.Maintenance.SendAsync(new GetStatisticsOperation(), cancellationToken);
var documentStore = documentStoreProvider.GetDocumentStore();
var statistics = await documentStore.Maintenance.SendAsync(new GetStatisticsOperation(), cancellationToken);
var indexes = statistics.Indexes.OrderBy(x => x.Name).ToArray();

CreateDiagnosticsLogEntry(statistics, indexes);
Expand Down Expand Up @@ -84,7 +80,5 @@ static void CreateDiagnosticsLogEntry(DatabaseStatistics statistics, IndexInform
static readonly TimeSpan IndexLagThresholdWarning = TimeSpan.FromMinutes(1);
static readonly TimeSpan IndexLagThresholdError = TimeSpan.FromMinutes(10);
static readonly ILog Log = LogManager.GetLogger<CheckRavenDBIndexLag>();

readonly IDocumentStore store;
}
}

0 comments on commit 2e7d123

Please sign in to comment.