Skip to content

Commit

Permalink
Database health check deactivation via configuration (#732)
Browse files Browse the repository at this point in the history
* feat: enable health check configuration for consumer api

* feat: enable health check configuration for admin api

* feat: enable health check configuration for sse server checks

* chore: fix formatting

* fix: handle data annotation validation error

* fix: handle data annotation validation error

* fix: handle data annotation validation error

* fix: handle data annotation validation error

* fix: handle data annotation validation error

* feat: enable health check configuration for sse server

* fix: show tier in adnim api

* feat: undo appsetting.override for postgres and sqlserver json

* feat: remove push notification configuration

* feat: revert changes to SeeServer/Program.cs

* Update ConsumerApi/appsettings.json

Co-authored-by: Timo Notheisen <[email protected]>

* feat: remove prop

* feat: remove sse health check

* feat: enable healtcheck by default

* feat: perform the check outside of the method instead of passing EnableHealthCheck

* fix: vulnerability

* Revert "fix: vulnerability"

This reverts commit ae718fb.

* ci: exclude vulnerability from npm audit

---------

Co-authored-by: Nikola Vetnić <[email protected]>
Co-authored-by: Timo Notheisen <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Vladimir Vuckovic <[email protected]>
Co-authored-by: Timo Notheisen <[email protected]>
  • Loading branch information
6 people authored Jul 10, 2024
1 parent e8cb7aa commit c958875
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .ci/aui/runChecks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ npm ci
npx eslint --ext ts ./src
npx prettier --check .
npx license-check --ignorePackages [email protected]
npx better-npm-audit audit
npx better-npm-audit audit --exclude 1098115
cd $INITIAL_DIR
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
3 changes: 3 additions & 0 deletions AdminApi/src/AdminApi/Configuration/DevicesConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
3 changes: 3 additions & 0 deletions AdminApi/src/AdminApi/Configuration/QuotasConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public static IServiceCollection AddCustomAspNetCore(this IServiceCollection ser
var module = configuration.Modules.GetType().GetProperty(moduleName)!.GetValue(configuration.Modules, null)!;
var provider = GetPropertyValue(module, "Infrastructure.SqlDatabase.Provider") as string;
var connectionString = (string)GetPropertyValue(module, "Infrastructure.SqlDatabase.ConnectionString");
var enableHealthCheck = Convert.ToBoolean(GetPropertyValue(module, "Infrastructure.SqlDatabase.EnableHealthCheck"));

if (!enableHealthCheck)
continue;

switch (provider)
{
Expand Down
17 changes: 17 additions & 0 deletions AdminApi/src/AdminApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@
}
},
"Modules": {
"Challenges": {
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Quotas": {
"Application": {
"Pagination": {
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Devices": {
Expand All @@ -26,6 +38,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
}
},
Expand Down
46 changes: 45 additions & 1 deletion ConsumerApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@
"MinimumBackoff": 2,
"MaximumBackoff": 120
}
},
"SqlDatabaseConfiguration": {
"EnableHealthCheck": true
}
},
"Modules": {
"Challenges": {},
"Challenges": {
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Quotas": {
"Application": {
"Pagination": {
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Devices": {
Expand All @@ -33,6 +47,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Files": {
Expand All @@ -41,6 +60,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Messages": {
Expand All @@ -51,6 +75,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Relationships": {
Expand All @@ -59,6 +88,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Synchronization": {
Expand All @@ -67,6 +101,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
},
"Tokens": {
Expand All @@ -75,6 +114,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog" Version="4.0.0"/>
<PackageReference Include="Serilog" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati
dbOptions.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
});

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public class SqlDatabase
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = null!;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
3 changes: 3 additions & 0 deletions Modules/Devices/src/Devices.ConsumerApi/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}

}
Expand Down
5 changes: 4 additions & 1 deletion Modules/Devices/src/Devices.ConsumerApi/DevicesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati

services.AddSingleton<ISignatureHelper, SignatureHelper>(_ => SignatureHelper.CreateEd25519WithRawKeyFormat());

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
3 changes: 3 additions & 0 deletions Modules/Files/src/Files.ConsumerApi/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
5 changes: 4 additions & 1 deletion Modules/Files/src/Files.ConsumerApi/FilesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati
: parsedConfiguration.Infrastructure.BlobStorage.ContainerName;
});

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
3 changes: 3 additions & 0 deletions Modules/Messages/src/Messages.ConsumerApi/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
5 changes: 4 additions & 1 deletion Modules/Messages/src/Messages.ConsumerApi/MessagesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati

services.AddApplication();

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
3 changes: 3 additions & 0 deletions Modules/Quotas/src/Quotas.ConsumerApi/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
5 changes: 4 additions & 1 deletion Modules/Quotas/src/Quotas.ConsumerApi/QuotasModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati
dbOptions.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
});

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);

services.AddResponseCaching();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati
options.DbOptions.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString;
});

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati

services.AddApplication();

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
3 changes: 3 additions & 0 deletions Modules/Tokens/src/Tokens.ConsumerApi/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SqlDatabaseConfiguration
[Required]
[MinLength(1)]
public string ConnectionString { get; set; } = string.Empty;

[Required]
public bool EnableHealthCheck { get; set; } = true;
}
}
}
5 changes: 4 additions & 1 deletion Modules/Tokens/src/Tokens.ConsumerApi/TokensModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati

services.AddApplication();

services.AddSqlDatabaseHealthCheck(Name, parsedConfiguration.Infrastructure.SqlDatabase.Provider, parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
if (parsedConfiguration.Infrastructure.SqlDatabase.EnableHealthCheck)
services.AddSqlDatabaseHealthCheck(Name,
parsedConfiguration.Infrastructure.SqlDatabase.Provider,
parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString);
}

public override void ConfigureEventBus(IEventBus eventBus)
Expand Down
1 change: 1 addition & 0 deletions SseServer/src/SseServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static void Configure(WebApplication app)
app.UseAuthentication().UseAuthorization();

app.MapControllers();

app.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = HealthCheckWriter.WriteResponse
Expand Down
5 changes: 5 additions & 0 deletions SseServer/src/SseServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"Infrastructure": {
"SqlDatabase": {
"EnableHealthCheck": true
}
}
}
},
Expand Down

0 comments on commit c958875

Please sign in to comment.