88 lines
4.2 KiB
C#
88 lines
4.2 KiB
C#
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using ZB.MOM.WW.Overview.Components;
|
|
using ZB.MOM.WW.Overview.Polling;
|
|
|
|
// Actual Overview App/Routes/layout/cards, synthetic immutable snapshots only.
|
|
// No polling, HTTP client, authentication or fleet service is registered.
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.WebHost.UseStaticWebAssets();
|
|
builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider();
|
|
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
|
var clock = new FixtureClock();
|
|
var store = new OverviewSnapshotStore();
|
|
store.Publish(Scenes.Create("mixed", clock.GetUtcNow()));
|
|
builder.Services.AddSingleton(store);
|
|
builder.Services.AddSingleton<TimeProvider>(clock);
|
|
var app = builder.Build();
|
|
var sourceRoot = builder.Configuration["Canary:OverviewRoot"] ?? Path.GetFullPath(Path.Combine(
|
|
builder.Environment.ContentRootPath, "../../../../../../ZB.MOM.WW.Overview/src/ZB.MOM.WW.Overview"));
|
|
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(sourceRoot, "wwwroot")) });
|
|
app.UseStaticFiles();
|
|
app.UseAntiforgery();
|
|
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
|
app.MapGet("/canary-provenance", () => new
|
|
{
|
|
purpose = "Actual Overview components with synthetic frozen snapshots; no production registry or probes",
|
|
themeAssembly = typeof(ZB.MOM.WW.Theme.ThemeShell).Assembly.GetName().Version?.ToString(),
|
|
generatedUtc = clock.GetUtcNow(),
|
|
sourceRoot,
|
|
});
|
|
app.MapPost("/canary/scene/{scene}", (string scene) =>
|
|
{
|
|
if (scene is not ("mixed" or "empty" or "stale" or "long-error")) return Results.NotFound();
|
|
store.Publish(Scenes.Create(scene, clock.GetUtcNow()));
|
|
return Results.Ok(new { scene, fixtureOnly = true });
|
|
});
|
|
app.Run();
|
|
|
|
internal sealed class FixtureClock : TimeProvider
|
|
{
|
|
private readonly DateTimeOffset _now = new(2026, 11, 13, 20, 0, 0, TimeSpan.Zero);
|
|
public override DateTimeOffset GetUtcNow() => _now;
|
|
}
|
|
|
|
internal static class Scenes
|
|
{
|
|
public static OverviewSnapshot Create(string scene, DateTimeOffset now)
|
|
{
|
|
if (scene == "empty") return OverviewSnapshot.Empty;
|
|
var rows = scene switch
|
|
{
|
|
"stale" => new[] { Row("Five-minute stale healthy", InstanceStatus.Up, now.AddMinutes(-5)) },
|
|
"long-error" => new[] { Row("Unreachable long diagnostic", InstanceStatus.Unreachable, now,
|
|
"Synthetic probe failure: " + new string('x', 2000) + " diagnostic end") },
|
|
_ => new[]
|
|
{
|
|
Row("Healthy fixture", InstanceStatus.Up, now),
|
|
Row("Degraded fixture", InstanceStatus.Degraded, now),
|
|
Row("Down fixture", InstanceStatus.Down, now),
|
|
Row("Unreachable fixture", InstanceStatus.Unreachable, now, "Synthetic loopback probe failure"),
|
|
Row("Five-minute stale healthy", InstanceStatus.Up, now.AddMinutes(-5)),
|
|
Row("Five-minute stale unreachable", InstanceStatus.Unreachable, now.AddMinutes(-5)),
|
|
Row("Pending fixture", null, null),
|
|
},
|
|
};
|
|
return new OverviewSnapshot(now, new[]
|
|
{
|
|
new ApplicationSnapshot("Synthetic local SCADA", rows, LeaderResolver.Resolve(rows)),
|
|
});
|
|
}
|
|
|
|
private static InstanceSnapshot Row(string name, InstanceStatus? status, DateTimeOffset? at, string? error = null) => new()
|
|
{
|
|
Application = "Synthetic local SCADA", Instance = name,
|
|
Group = "Local fixtures", BaseUrl = "http://127.0.0.1:5200",
|
|
Status = status, LastPolledUtc = at, LastReachableUtc = at,
|
|
Latency = TimeSpan.FromMilliseconds(12), StaleAfter = TimeSpan.FromSeconds(45), Error = error,
|
|
Report = status == InstanceStatus.Unreachable || status is null ? null : new ZbHealthReport
|
|
{
|
|
Status = status == InstanceStatus.Up ? "Healthy" : status == InstanceStatus.Degraded ? "Degraded" : "Unhealthy",
|
|
Entries = new Dictionary<string, ZbHealthEntry>
|
|
{
|
|
["synthetic-check"] = new() { Status = status == InstanceStatus.Up ? "Healthy" : "Degraded", Description = "Local fixture observation" },
|
|
},
|
|
},
|
|
};
|
|
}
|