Lead gateway overview with readable fault context
This commit is contained in:
@@ -12,49 +12,56 @@ else
|
||||
<div class="dashboard-page-header">
|
||||
<div>
|
||||
<h1>Overview</h1>
|
||||
<div class="text-secondary">Generated @DashboardDisplay.DateTime(Snapshot.GeneratedAt)</div>
|
||||
<div class="text-secondary">Sampled @DashboardDisplay.DateTime(Snapshot.GeneratedAt)</div>
|
||||
</div>
|
||||
<StatusBadge Text="@Snapshot.GatewayStatus" />
|
||||
</div>
|
||||
|
||||
<section class="metric-grid">
|
||||
<MetricCard Label="Uptime" Value="@DashboardDisplay.Duration(Snapshot.GatewayUptime)" Detail="@Snapshot.GatewayVersion" />
|
||||
<MetricCard Label="Open Sessions" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.sessions.open"))" />
|
||||
<MetricCard Label="Workers Running" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.workers.running"))" />
|
||||
<MetricCard Label="Event Queue Depth" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.events.worker_queue.depth"))" />
|
||||
<MetricCard Label="Commands Failed" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.commands.failed"))" />
|
||||
<MetricCard Label="Events Received" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.events.received"))" />
|
||||
<MetricCard Label="Faults" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.faults"))" />
|
||||
<MetricCard Label="Queue Overflows" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.queues.overflows"))" />
|
||||
<section class="dashboard-section overview-faults" aria-labelledby="recent-faults-title">
|
||||
<div class="section-heading d-flex align-items-center gap-2 flex-wrap">
|
||||
<h2 id="recent-faults-title">Recent faults</h2>
|
||||
<NavLink class="ms-auto small" href="sessions">View sessions →</NavLink>
|
||||
</div>
|
||||
<FaultList Faults="@Snapshot.Faults" Compact="true" />
|
||||
</section>
|
||||
|
||||
<section class="dashboard-section">
|
||||
<div class="section-heading d-flex align-items-center gap-2">
|
||||
<h2>Galaxy Repository</h2>
|
||||
<StatusBadge Text="@Snapshot.Galaxy.Status.ToString()" />
|
||||
<NavLink class="ms-auto small" href="galaxy">View browse details →</NavLink>
|
||||
</div>
|
||||
<section class="metric-grid" aria-label="Session, worker and queue context">
|
||||
<MetricCard Label="Open sessions" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.sessions.open"))" />
|
||||
<MetricCard Label="Workers running" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.workers.running"))" />
|
||||
<MetricCard Label="Event queue depth" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.events.worker_queue.depth"))" />
|
||||
</section>
|
||||
|
||||
<details class="dashboard-section supporting-counters" data-testid="supporting-counters">
|
||||
<summary>Supporting counters and repository details</summary>
|
||||
<h2 class="h6 mt-3">Uptime and cumulative counters</h2>
|
||||
<div class="metric-grid compact">
|
||||
<MetricCard Label="Last Deploy" Value="@DashboardDisplay.DateTime(Snapshot.Galaxy.LastDeployTime)" />
|
||||
<MetricCard Label="Objects" Value="@DashboardDisplay.Count(Snapshot.Galaxy.ObjectCount)" Detail="@($"{Snapshot.Galaxy.AreaCount:N0} areas")" />
|
||||
<MetricCard Label="Attributes" Value="@DashboardDisplay.Count(Snapshot.Galaxy.AttributeCount)" />
|
||||
<MetricCard Label="Historized" Value="@DashboardDisplay.Count(Snapshot.Galaxy.HistorizedAttributeCount)" />
|
||||
<MetricCard Label="Alarms" Value="@DashboardDisplay.Count(Snapshot.Galaxy.AlarmAttributeCount)" />
|
||||
<MetricCard Label="Last Refresh" Value="@DashboardDisplay.DateTime(Snapshot.Galaxy.LastSuccessAt)" Detail="@GalaxyRefreshDetail()" />
|
||||
<MetricCard Label="Uptime" Value="@DashboardDisplay.Duration(Snapshot.GatewayUptime)" Detail="@Snapshot.GatewayVersion" />
|
||||
<MetricCard Label="Commands failed" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.commands.failed"))" />
|
||||
<MetricCard Label="Events received" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.events.received"))" />
|
||||
<MetricCard Label="Faults" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.faults"))" />
|
||||
<MetricCard Label="Queue overflows" Value="@DashboardDisplay.Count(DashboardDisplay.MetricValue(Snapshot, "mxgateway.queues.overflows"))" />
|
||||
</div>
|
||||
@if (!string.IsNullOrWhiteSpace(Snapshot.Galaxy.LastError))
|
||||
{
|
||||
@* Overview stays compact; the Galaxy page renders the error in full. *@
|
||||
<div class="empty-state mt-2" title="@Snapshot.Galaxy.LastError">@DashboardDisplay.Abbreviate(Snapshot.Galaxy.LastError, 160)</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="dashboard-section">
|
||||
<div class="section-heading">
|
||||
<h2>Recent Faults</h2>
|
||||
</div>
|
||||
<FaultList Faults="@Snapshot.Faults" />
|
||||
</section>
|
||||
<section class="mt-3">
|
||||
<div class="section-heading d-flex align-items-center gap-2 flex-wrap">
|
||||
<h2>Galaxy Repository</h2>
|
||||
<StatusBadge Text="@Snapshot.Galaxy.Status.ToString()" />
|
||||
<NavLink class="ms-auto small" href="galaxy">Repository status →</NavLink>
|
||||
<NavLink class="small" href="browse">Browse attributes →</NavLink>
|
||||
</div>
|
||||
<div class="metric-grid compact">
|
||||
<MetricCard Label="Last deploy" Value="@DashboardDisplay.DateTime(Snapshot.Galaxy.LastDeployTime)" />
|
||||
<MetricCard Label="Objects" Value="@DashboardDisplay.Count(Snapshot.Galaxy.ObjectCount)" Detail="@($"{Snapshot.Galaxy.AreaCount:N0} areas")" />
|
||||
<MetricCard Label="Attributes" Value="@DashboardDisplay.Count(Snapshot.Galaxy.AttributeCount)" />
|
||||
<MetricCard Label="Historized" Value="@DashboardDisplay.Count(Snapshot.Galaxy.HistorizedAttributeCount)" />
|
||||
<MetricCard Label="Alarms" Value="@DashboardDisplay.Count(Snapshot.Galaxy.AlarmAttributeCount)" />
|
||||
<MetricCard Label="Last refresh" Value="@DashboardDisplay.DateTime(Snapshot.Galaxy.LastSuccessAt)" Detail="@GalaxyRefreshDetail()" />
|
||||
</div>
|
||||
@if (!string.IsNullOrWhiteSpace(Snapshot.Galaxy.LastError))
|
||||
{
|
||||
<div class="empty-state mt-2">@DashboardDisplay.Abbreviate(Snapshot.Galaxy.LastError, 160) Open Repository status for complete diagnostics.</div>
|
||||
}
|
||||
</section>
|
||||
</details>
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
@@ -1,6 +1,34 @@
|
||||
@if (Faults.Count == 0)
|
||||
{
|
||||
<div class="empty-state">No faults recorded.</div>
|
||||
<div class="empty-state">No fault records in this snapshot.</div>
|
||||
}
|
||||
else if (Compact)
|
||||
{
|
||||
<div class="fault-summaries">
|
||||
@foreach (DashboardFaultSummary fault in Faults)
|
||||
{
|
||||
<article class="fault-summary">
|
||||
<div class="d-flex gap-2 flex-wrap align-items-center"><strong>@fault.Source</strong><StatusBadge Text="@fault.State" /></div>
|
||||
@if (fault.Message.Length > 160)
|
||||
{
|
||||
<details class="fault-diagnostic">
|
||||
<summary>@DashboardDisplay.Abbreviate(fault.Message)</summary>
|
||||
<pre tabindex="0" role="region" aria-label="@($"Full fault diagnostic for {fault.Source}, session {fault.SessionId ?? "unassigned"}")">@fault.Message</pre>
|
||||
</details>
|
||||
}
|
||||
else { <p class="mb-1">@fault.Message</p> }
|
||||
<div class="fault-context">
|
||||
<span>Observed @DashboardDisplay.DateTime(fault.ObservedAt)</span>
|
||||
<span>Session
|
||||
@if (!string.IsNullOrWhiteSpace(fault.SessionId))
|
||||
{ <a href="@($"sessions/{Uri.EscapeDataString(fault.SessionId)}")"><code>@fault.SessionId</code></a> }
|
||||
else { <code>@DashboardDisplay.Text(fault.SessionId)</code> }
|
||||
</span>
|
||||
<span>Worker @(fault.WorkerProcessId?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? "-")</span>
|
||||
</div>
|
||||
</article>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -22,10 +50,25 @@ else
|
||||
<tr>
|
||||
<td>@DashboardDisplay.DateTime(fault.ObservedAt)</td>
|
||||
<td>@fault.Source</td>
|
||||
<td><code>@DashboardDisplay.Text(fault.SessionId)</code></td>
|
||||
<td>
|
||||
@if (!string.IsNullOrWhiteSpace(fault.SessionId))
|
||||
{
|
||||
<a href="@($"sessions/{Uri.EscapeDataString(fault.SessionId)}")"><code>@fault.SessionId</code></a>
|
||||
}
|
||||
else { <code>@DashboardDisplay.Text(fault.SessionId)</code> }
|
||||
</td>
|
||||
<td>@(fault.WorkerProcessId?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? "-")</td>
|
||||
<td><StatusBadge Text="@fault.State" /></td>
|
||||
<td title="@fault.Message">@DashboardDisplay.Abbreviate(fault.Message)</td>
|
||||
<td>
|
||||
@if (fault.Message.Length > 160)
|
||||
{
|
||||
<details class="fault-diagnostic">
|
||||
<summary>@DashboardDisplay.Abbreviate(fault.Message)</summary>
|
||||
<pre tabindex="0" role="region" aria-label="@($"Full fault diagnostic for {fault.Source}, session {fault.SessionId ?? "unassigned"}")">@fault.Message</pre>
|
||||
</details>
|
||||
}
|
||||
else { @fault.Message }
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
@@ -34,6 +77,9 @@ else
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Compact { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<DashboardFaultSummary> Faults { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -566,3 +566,17 @@ code {
|
||||
@media (pointer: coarse) {
|
||||
.browse-layout button, .browse-search-controls .form-control { min-width: 44px; min-height: 44px; }
|
||||
}
|
||||
|
||||
.supporting-counters > summary, .fault-diagnostic > summary { cursor: pointer; }
|
||||
.fault-diagnostic pre {
|
||||
max-height: 16rem; overflow: auto; margin: .5rem 0 0; padding: .65rem;
|
||||
white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono);
|
||||
font-size: .78rem; color: var(--ink); background: var(--zebra-bg);
|
||||
border: 1px solid var(--rule); border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Fault messages lead on narrow screens; every snapshot field remains present. */
|
||||
.fault-summaries { display: grid; gap: 1rem; }
|
||||
.fault-summary { min-width: 0; overflow-wrap: anywhere; }
|
||||
.fault-summary + .fault-summary { border-top: 1px solid var(--rule); padding-top: 1rem; }
|
||||
.fault-context { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--ink-faint); font-size: .875rem; }
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard.Components.Pages;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Dashboard;
|
||||
|
||||
/// <summary>Snapshot composition contracts; no gateway workers or external services.</summary>
|
||||
public sealed class DashboardHomeRenderTests
|
||||
{
|
||||
/// <summary>Fault context precedes operational metrics and links the affected existing route.</summary>
|
||||
[Fact]
|
||||
public async Task FaultSnapshot_LeadsWithActionableFaultAndPreservesAllCounters()
|
||||
{
|
||||
string html = await RenderAsync(withFault: true);
|
||||
Assert.Contains("Fixture worker failed", html, StringComparison.Ordinal);
|
||||
Assert.Contains("href=\"sessions/fixture-session\"", html, StringComparison.Ordinal);
|
||||
Assert.True(html.IndexOf("Recent faults", StringComparison.OrdinalIgnoreCase) < html.IndexOf("Open sessions", StringComparison.OrdinalIgnoreCase));
|
||||
string supporting = Regex.Match(html, "<details[^>]*data-testid=\"supporting-counters\"[^>]*>(.*?)</details>", RegexOptions.Singleline).Groups[1].Value;
|
||||
Assert.NotEmpty(supporting);
|
||||
foreach (string label in new[] { "Uptime", "Commands failed", "Events received", "Faults", "Queue overflows", "Last deploy", "Objects", "Attributes", "Historized", "Alarms", "Last refresh" })
|
||||
Assert.Contains(label, supporting, StringComparison.OrdinalIgnoreCase);
|
||||
foreach (string value in new[] { "104", "105", "106", "107", "201", "202", "203", "204", "205" })
|
||||
Assert.Contains(value, supporting, StringComparison.Ordinal);
|
||||
Assert.Contains("Repository status", html, StringComparison.Ordinal);
|
||||
Assert.Contains("Browse attributes", html, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>A zero-session snapshot stays truthful; complete escaped diagnostics need no hover.</summary>
|
||||
[Fact]
|
||||
public async Task LongFault_HasKeyboardDisclosureAndEscapedCompleteDiagnostic()
|
||||
{
|
||||
string html = await RenderAsync(withFault: true, longFault: true);
|
||||
Assert.Contains("<details class=\"fault-diagnostic\"", html, StringComparison.Ordinal);
|
||||
Assert.Contains("<script>fixture</script>", html, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("<script>fixture</script>", html, StringComparison.Ordinal);
|
||||
Assert.Contains("role=\"region\"", html, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>No fault record is reported explicitly rather than synthesized from lifetime counters.</summary>
|
||||
[Fact]
|
||||
public async Task HealthySnapshot_ShowsNoRecordedFaultsAndRealZeroSessionCount()
|
||||
{
|
||||
string html = await RenderAsync(withFault: false);
|
||||
Assert.Contains("No fault records in this snapshot.", html, StringComparison.Ordinal);
|
||||
Assert.Contains("Open sessions", html, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("Healthy", html, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static async Task<string> RenderAsync(bool withFault, bool longFault = false)
|
||||
{
|
||||
DateTimeOffset at = new(2026, 11, 13, 20, 0, 0, TimeSpan.Zero);
|
||||
DashboardSnapshot snapshot = new(at, at.AddHours(-3), TimeSpan.FromHours(3), withFault ? "Degraded" : "Healthy", "fixture", withFault ? [new("fixture-session", "synthetic", ZB.MOM.WW.MxGateway.Contracts.Proto.SessionState.Faulted, null, null, null, at, at, null, 123, null, null, 0, "Fixture fault")] : [], [],
|
||||
[new("mxgateway.sessions.open", 0), new("mxgateway.workers.running", 102), new("mxgateway.events.worker_queue.depth", 103),
|
||||
new("mxgateway.commands.failed", 104), new("mxgateway.events.received", 105), new("mxgateway.faults", 106), new("mxgateway.queues.overflows", 107)],
|
||||
withFault ? [new("Worker", "fixture-session", 123, "Faulted", "Fixture worker failed" + (longFault ? new string('x', 300) + "<script>fixture</script>" : ""), at)] : [], [], null!,
|
||||
DashboardGalaxySummary.Unknown with { Status = DashboardGalaxyStatus.Healthy, LastDeployTime = at, LastSuccessAt = at, LastQueriedAt = at, ObjectCount = 201, AreaCount = 202, AttributeCount = 203, HistorizedAttributeCount = 204, AlarmAttributeCount = 205 });
|
||||
ServiceCollection services = new();services.AddLogging();
|
||||
services.AddSingleton<IDashboardSnapshotService>(new SnapshotService(snapshot));
|
||||
services.AddSingleton<IDashboardSnapshotFeed, IdleFeed>();
|
||||
services.AddSingleton<NavigationManager, FixtureNavigation>();
|
||||
await using ServiceProvider provider = services.BuildServiceProvider();
|
||||
await using HtmlRenderer renderer = new(provider, provider.GetRequiredService<ILoggerFactory>());
|
||||
return await renderer.Dispatcher.InvokeAsync(async () => (await renderer.RenderComponentAsync<DashboardHome>()).ToHtmlString());
|
||||
}
|
||||
private sealed class SnapshotService(DashboardSnapshot snapshot) : IDashboardSnapshotService
|
||||
{
|
||||
public DashboardSnapshot GetSnapshot() => snapshot;
|
||||
public IAsyncEnumerable<DashboardSnapshot> WatchSnapshotsAsync(CancellationToken cancellationToken) => new IdleFeed().WatchAsync(cancellationToken);
|
||||
}
|
||||
private sealed class IdleFeed : IDashboardSnapshotFeed
|
||||
{
|
||||
public async IAsyncEnumerable<DashboardSnapshot> WatchAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{ await Task.Delay(Timeout.Infinite, cancellationToken);yield break; }
|
||||
}
|
||||
private sealed class FixtureNavigation : NavigationManager
|
||||
{
|
||||
public FixtureNavigation() => Initialize("http://localhost/", "http://localhost/");
|
||||
protected override void NavigateToCore(string uri, bool forceLoad) => throw new NotSupportedException("Read-only renderer");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user