-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (51 loc) · 1.93 KB
/
Program.cs
File metadata and controls
63 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Microsoft.EntityFrameworkCore;
using Microsoft.FeatureManagement;
using OpenTelemetry.Metrics;
using WebAPI.Controllers;
using WebAPI.Persistence;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHealthChecks()
.AddCheck<HealthCheckDb>("Database Health Check");
builder.Services.AddDbContext<TodoDbContext>(opt =>
{
opt.UseNpgsql($"User ID={Environment.GetEnvironmentVariable("POSTGRES_USER")};" +
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD")};" +
$"Host=postgres;" +
$"Port=5432;" +
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB")};" +
$"Pooling=true;" +
$"Minimum Pool Size=0;" +
$"Maximum Pool Size=100;" +
$"Connection Lifetime=0;");
});
builder.Services.AddFeatureManagement();
builder.Services.AddOpenTelemetry()
.WithMetrics(telemetryBuilder =>
{
telemetryBuilder.AddPrometheusExporter();
telemetryBuilder.AddMeter("Microsoft.AspNetCore.Hosting", "Microsoft.AspNetCore.Server.Kestrel");
telemetryBuilder.AddView("http.server.request.duration",
new ExplicitBucketHistogramConfiguration
{
Boundaries = [0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10]
});
});
var app = builder.Build();
//Ensure DB is created
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<TodoDbContext>();
dbContext.Database.Migrate();
}
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
app.UseAuthorization();
app.MapControllers();
app.MapHealthChecks("/health");
app.MapPrometheusScrapingEndpoint();
app.Run();