Add caching layer for edge gateway views, including payload storage, retrieval, sync, and invalidation

This commit is contained in:
Jeppe Bundgaard
2026-04-22 14:23:24 +02:00
parent 300942f1c8
commit f4952f16e6
9 changed files with 1083 additions and 24 deletions
@@ -89,3 +89,62 @@ it('summarizes fleet usage statistics for the dashboard landing view', function
'disk_usage_pct_avg' => 67,
]);
});
it('derives fleet usage directly from cached gateway row summaries', function (): void {
$summary = edge_gateway_manager::summarizeFleetUsageFromGatewayRows([
[
'id' => 701,
'department_id' => 1,
'status' => edge_gateway_manager::STATUS_ONLINE,
'version_drift' => ['is_drifted' => true],
'channel_status' => ['broker' => ['connected' => true]],
'active_operation' => ['id' => 91, 'type' => 'DISCOVERY'],
'recent_operations_summary' => ['pending' => 1, 'in_progress' => 1],
'backlog_depth' => ['operations' => 2, 'commands' => 3],
'metadata' => [
'system_metrics' => [
'latency_ms' => 184,
'cpu_usage_pct' => 27,
'memory_usage_pct' => 61,
'disk_usage_pct' => 58,
],
],
'inventory_summary' => ['total' => 2, 'online' => 1, 'offline' => 1],
'binding_summary' => ['total' => 3, 'fallback_overrides' => 2],
'fallback_summary' => ['cloud_only_relays' => 1, 'local_only_relays' => 1],
],
[
'id' => 702,
'department_id' => 2,
'status' => edge_gateway_manager::STATUS_OFFLINE,
'version_drift' => ['is_drifted' => false],
'channel_status' => ['broker' => ['connected' => false]],
'active_operation' => null,
'recent_operations_summary' => ['pending' => 0, 'in_progress' => 0],
'backlog_depth' => ['operations' => 0, 'commands' => 1],
'metadata' => [
'system_metrics' => [
'latency_ms' => 412,
'cpu_usage_pct' => 9,
'memory_usage_pct' => 42,
'disk_usage_pct' => 76,
],
],
'inventory_summary' => ['total' => 1, 'online' => 1, 'offline' => 0],
'binding_summary' => ['total' => 0, 'fallback_overrides' => 0],
'fallback_summary' => ['cloud_only_relays' => 0, 'local_only_relays' => 0],
],
]);
expect($summary['inventory'])->toBe([
'total' => 3,
'online' => 2,
'offline' => 1,
]);
expect($summary['bindings'])->toBe([
'total' => 3,
'fallback_overrides' => 2,
'cloud_only' => 1,
'local_only' => 1,
]);
});