Fix: Kafka replication factor hardcoded to 1 and No health check endpoints

This commit is contained in:
voltsrage
2026-06-21 17:24:09 +08:00
parent a91d79f3cd
commit 0d0bba19e6
9 changed files with 176 additions and 7 deletions
+51 -6
View File
@@ -1,5 +1,6 @@
using Elastic.Clients.Elasticsearch;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Prometheus;
using Serilog;
using StackExchange.Redis;
@@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Authorization;
using System.Text;
using Microsoft.OpenApi;
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
@@ -197,6 +199,13 @@ try
builder.Services.AddHostedService<GcsScoringService>();
builder.Services.AddHostedService<SofaScoringService>();
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>("postgresql", tags: new[] { "ready" })
.AddCheck<RedisHealthCheck>("redis", tags: new[] { "ready" })
.AddCheck<KafkaHealthCheck>("kafka", tags: new[] { "ready" })
.AddCheck<RabbitMqHealthCheck>("rabbitmq", tags: new[] { "ready" })
.AddCheck<ElasticsearchHealthCheck>("elasticsearch", tags: new[] { "ready" });
builder.Services.AddControllers()
.AddJsonOptions(opts =>
{
@@ -209,6 +218,31 @@ try
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "VigilCare Clinical API",
Version = "v1",
Description = "Clinical monitoring and alerting platform API"
});
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Name = "Authorization",
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
Description = "Enter your JWT token"
});
options.AddSecurityRequirement(document => new OpenApiSecurityRequirement
{
{
new OpenApiSecuritySchemeReference("Bearer", document),
new List<string>()
}
});
var xmlPath = Path.Combine(AppContext.BaseDirectory,
$"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
options.IncludeXmlComments(xmlPath);
@@ -260,6 +294,12 @@ try
});
}
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "VigilCare Clinical API v1");
});
app.UseMiddleware<CorrelationIdMiddleware>();
app.UseMiddleware<FhirApiKeyOrJwtMiddleware>();
app.UseMiddleware<ExceptionHandlerMiddleware>();
@@ -269,14 +309,19 @@ try
app.UseAuthentication();
app.UseAuthorization();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
app.MapHealthChecks("/health/live", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
app.UseSwagger();
app.UseSwaggerUI();
}
Predicate = _ => false,
ResponseWriter = HealthCheckResponseWriter.WriteAsync
}).AllowAnonymous();
app.MapMetrics("/metrics");
app.MapHealthChecks("/health/ready", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready"),
ResponseWriter = HealthCheckResponseWriter.WriteAsync
}).AllowAnonymous();
app.MapMetrics("/metrics");
app.MapControllers();
app.Run();