Repository navigation
Expand file tree
/
Copy pathAppHostConfiguration.cs
More file actions
33 lines (30 loc) · 1.77 KB
/
Copy pathAppHostConfiguration.cs
File metadata and controls
33 lines (30 loc) · 1.77 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
using KeyLoad.AppHost.Hosting;
internal sealed record AppHostConfiguration(bool BenchmarkMode, string BenchmarkProfile, string BenchmarkRoot,
string DataRoot, bool Ephemeral)
{
internal const string GeneralBenchmarkProfile = "general";
internal const string TimeSeriesBenchmarkProfile = "timeseries";
private const string DefaultBenchmarkRoot = "../../artifacts/comparisons";
private const string DefaultDataRoot = "../../data/cluster";
private const string BenchmarkClusterDirectory = "cluster";
private const string GuidFormat = "N";
internal const string AdminParameter = "admin-key";
internal static AppHostConfiguration Read(IDistributedApplicationBuilder builder)
{
const string MessageText = "The configured benchmark profile is not supported.";
var options = AppHostOptionsRegistration.Get(builder).Startup.Value;
var benchmark = options.BenchmarkMode;
var benchmarkProfile = options.BenchmarkProfile.Trim();
if (benchmark && !string.Equals(benchmarkProfile, GeneralBenchmarkProfile, StringComparison.OrdinalIgnoreCase)
&& !string.Equals(benchmarkProfile, TimeSeriesBenchmarkProfile, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(MessageText);
}
var benchmarkRoot = Path.GetFullPath(options.BenchmarkRoot
?? Path.Combine(builder.AppHostDirectory, DefaultBenchmarkRoot, Guid.NewGuid().ToString(GuidFormat)));
var dataRoot = Path.GetFullPath(options.DataRoot ?? (benchmark
? Path.Combine(benchmarkRoot, BenchmarkClusterDirectory) : Path.Combine(builder.AppHostDirectory, DefaultDataRoot)));
return new(benchmark, benchmarkProfile, benchmarkRoot, dataRoot,
options.Ephemeral ?? benchmark);
}
}