mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(dashboard): stop unreachable servers from blocking metrics charts
Closes #11629
This commit is contained in:
@@ -4,14 +4,23 @@ namespace App\Livewire\Dashboard;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Attributes\Isolate;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Each chart sends its own request, so one slow server does not delay the charts of the other servers.
|
||||
*/
|
||||
#[Isolate]
|
||||
class ServerMetricsChart extends Component
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
public function loadData(): void
|
||||
{
|
||||
if (! $this->server->isFunctional()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dispatch("dashboard-server-metrics-{$this->server->uuid}", [
|
||||
'cpu' => $this->server->getCpuMetrics(10),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Livewire\Dashboard;
|
||||
use App\Livewire\Dashboard\ServerMetricsChart;
|
||||
use App\Livewire\Server\Index as ServerIndex;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\PrivateKey;
|
||||
@@ -8,12 +9,14 @@ use App\Models\Server;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
Server::flushIdentityMap();
|
||||
Queue::fake();
|
||||
InstanceSettings::unguarded(fn () => InstanceSettings::query()->create(['id' => 0]));
|
||||
|
||||
@@ -63,3 +66,41 @@ it('renders dashboard metrics charts on the server index grid', function () {
|
||||
->assertSeeHtml("dashboard-server-metrics-{$enabledServer->uuid}")
|
||||
->assertDontSeeHtml("dashboard-server-metrics-{$disabledServer->uuid}");
|
||||
});
|
||||
|
||||
it('does not run SSH for an unreachable server when loading dashboard metrics', function () {
|
||||
Process::fake();
|
||||
|
||||
$server = Server::factory()->create([
|
||||
'team_id' => $this->team->id,
|
||||
'private_key_id' => $this->privateKey->id,
|
||||
]);
|
||||
$server->settings->update(['is_metrics_enabled' => true, 'is_reachable' => false]);
|
||||
|
||||
Livewire::test(ServerMetricsChart::class, ['server' => $server->fresh()])
|
||||
->call('loadData')
|
||||
->assertNotDispatched("dashboard-server-metrics-{$server->uuid}");
|
||||
|
||||
Process::assertNothingRan();
|
||||
});
|
||||
|
||||
it('loads dashboard metrics over SSH for a reachable server', function () {
|
||||
Process::fake(['*' => Process::result(output: '[{"time":1700000000000,"percent":12.5,"usedPercent":40}]')]);
|
||||
|
||||
$server = Server::factory()->create([
|
||||
'team_id' => $this->team->id,
|
||||
'private_key_id' => $this->privateKey->id,
|
||||
]);
|
||||
$server->settings->update(['is_metrics_enabled' => true, 'is_reachable' => true, 'is_usable' => true]);
|
||||
|
||||
Livewire::test(ServerMetricsChart::class, ['server' => $server->fresh()])
|
||||
->call('loadData')
|
||||
->assertDispatched(
|
||||
"dashboard-server-metrics-{$server->uuid}",
|
||||
fn (string $name, array $params) => $params[0] == [
|
||||
'cpu' => [[1700000000000, 12.5]],
|
||||
'memory' => [[1700000000000, 40]],
|
||||
],
|
||||
);
|
||||
|
||||
Process::assertRan(fn ($process) => str_contains($process->command, 'coolify-sentinel'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user