This repository was archived by the owner on Aug 20, 2024. It is now read-only.
generated from petabridge/Petabridge.App.Web
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
72 lines (61 loc) · 2.67 KB
/
Program.cs
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
64
65
66
67
68
69
70
71
72
using System;
using Akka.Actor;
using Akka.Cluster.Hosting;
using Akka.Cluster.Sharding;
using Akka.Event;
using Akka.Hosting;
using AkkaDotNet.BackEnd.Actors;
using AkkaDotNet.Infrastructure;
using AkkaDotNet.Infrastructure.Actors;
using AkkaDotNet.Infrastructure.Configuration;
using AkkaDotNet.Infrastructure.Logging;
using AkkaDotNet.Infrastructure.OpenTelemetry;
using AkkaDotNet.Infrastructure.Sharding;
using AkkaDotNet.Messages;
using Serilog;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
builder.Logging.ClearProviders().AddConsole().AddSerilog().AddFilter(null, LogLevel.Warning);
var akkaConfiguration = builder.Configuration.GetRequiredSection(nameof(StressOptions)).Get<StressOptions>();
builder.Services.AddAkka(ActorSystemConstants.ActorSystemName, configurationBuilder =>
{
configurationBuilder.ConfigureLoggers(configBuilder =>
{
configBuilder.LogLevel = Akka.Event.LogLevel.DebugLevel;
});
configurationBuilder.WithClusterBootstrap(akkaConfiguration,
new[] { ActorSystemConstants.BackendRole, ActorSystemConstants.DistributedPubSubRole });
configurationBuilder.WithSerilog(akkaConfiguration.SerilogOptions);
configurationBuilder.WithReadyCheckActors();
if (akkaConfiguration.ShardingOptions.Enabled)
{
configurationBuilder.WithShardRegion<IWithItem>("items", s => ItemActor.PropsFor(s, akkaConfiguration.DistributedPubSubOptions.Enabled), new ItemShardExtractor(),
new ShardOptions()
{
RememberEntities = akkaConfiguration.ShardingOptions.RememberEntities,
Role = ActorSystemConstants.BackendRole,
StateStoreMode = akkaConfiguration.ShardingOptions.UseDData ? StateStoreMode.DData : StateStoreMode.Persistence
})
.WithItemMessagingActor();
}
//configurationBuilder.AddHoconFile("sharding-upgrade.conf");
});
builder.Services.AddOpenTelemetry();
var app = builder.Build();
// per https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.Prometheus/README.md
app.UseRouting();
app.UseOpenTelemetryPrometheusScrapingEndpoint();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapGet("/ready", async (ActorRegistry registry) =>
{
var readyCheck = registry.Get<ReadyCheckActor>();
var checkResult = await readyCheck.Ask<ReadyResult>(ReadyCheck.Instance, TimeSpan.FromSeconds(3));
//if (checkResult.IsReady)
return Results.StatusCode(200);
return Results.StatusCode(500);
});
});
await app.RunAsync();