-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
71 lines (59 loc) · 2.56 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
using Libplanet.RocksDBStore;
using Libplanet.Store.Remote.Executable;
using Libplanet.Store.Remote.Server;
using Libplanet.Store.Trie;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
using ConsoleAppFramework;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Metrics;
using Serilog;
public static class Program
{
public static async Task Main(string[] args)
{
await ConsoleApp.RunAsync(args, Run);
}
/// <summary>
/// Run server with given arguments and options.
/// </summary>
/// <param name="path">Path to key-value store. (e.g., /path/to/snapshot/states)</param>
/// <param name="port">Port number to listen gRPC (HTTP 2) requests.</param>
/// <param name="httpPort">Port number to listen HTTP 1 requests.</param>
private static async Task Run(
[Argument] string path, CancellationToken cancellationToken, int port = 5000, int httpPort = 5001)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var builder = WebApplication.CreateBuilder();
// Add services to the container.
builder.Services.AddGrpc();
// If use `RocksDBStore`, try this:
builder.Services.AddSingleton<IKeyValueStore>(_ => new RocksDBKeyValueStore(path, RocksDBInstanceType.Secondary));
builder.Services.AddSingleton<Serilog.ILogger>(
new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Warning()
.CreateLogger());
builder.Services.AddHealthChecks();
builder.Services.AddHostedService<RocksDbSynchronizer>();
builder.Services.AddOpenTelemetry()
.WithMetrics(b =>
b.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddPrometheusExporter());
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(port, listenOptions => { listenOptions.Protocols = HttpProtocols.Http2; });
options.ListenAnyIP(httpPort, listenOptions => { listenOptions.Protocols = HttpProtocols.Http1; });
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapGrpcService<RemoteKeyValueService>();
app.MapHealthChecks("/health");
app.UseOpenTelemetryPrometheusScrapingEndpoint();
await app.RunAsync(cancellationToken);
}
}