fix(services): cap live journal at 200 rows in a scrollable, auto-sticking box

feat/v1-foundation
boban 2026-06-14 20:58:48 +02:00
parent e9a6a6c083
commit a8616809f1
4 changed files with 10 additions and 5 deletions

View File

@ -16,7 +16,7 @@ class Index extends Component
use WithFleetContext;
/** Cap on retained journal rows so the live poll never grows the payload unbounded. */
private const JOURNAL_MAX = 300;
private const JOURNAL_MAX = 200;
/** Active server name (from fleet context). */
public string $server = '—';

View File

@ -358,7 +358,7 @@ class FleetService
*
* @return array{journal:array<int,array>,cursor:?string}
*/
public function journalSince(Server $server, ?string $cursor, int $tail = 300): array
public function journalSince(Server $server, ?string $cursor, int $tail = 200): array
{
// Journald cursors are `key=hex` segments joined by `;` — reject anything else
// before it reaches the shell, then single-quote it.

View File

@ -93,7 +93,12 @@
<x-badge tone="cyan">{{ __('services.journal_live') }}</x-badge>
</x-slot:actions>
<div @if ($ready && $connected) wire:poll.5s="pollJournal" @endif class="overflow-x-auto">
<div @if ($ready && $connected) wire:poll.5s="pollJournal" @endif
x-data="{ stick() { this.$refs.log && (this.$refs.log.scrollTop = this.$refs.log.scrollHeight) } }"
x-init="$nextTick(() => stick())"
x-on:livewire:updated="$nextTick(() => stick())"
x-ref="log"
class="max-h-80 overflow-y-auto overflow-x-auto">
<div class="min-w-[640px] divide-y divide-line-soft font-mono text-[11px] leading-relaxed sm:min-w-0">
@foreach ($journal as $line)
<div class="flex items-start gap-3 px-4 py-1.5 sm:px-5">

View File

@ -42,7 +42,7 @@ class ServicesJournalPollTest extends TestCase
$fleet = Mockery::mock(FleetService::class);
$fleet->shouldReceive('journalSince')
->once()
->with(Mockery::type(Server::class), 'cur-0', 300)
->with(Mockery::type(Server::class), 'cur-0', 200)
->andReturn([
'journal' => [['time' => '10:00:05', 'unit' => 'nginx', 'level' => 'info', 'text' => 'new line']],
'cursor' => 'cur-1',
@ -83,7 +83,7 @@ class ServicesJournalPollTest extends TestCase
->call('pollJournal');
$journal = $component->get('journal');
$this->assertCount(300, $journal);
$this->assertCount(200, $journal);
// The oldest row is evicted; the newest survives.
$this->assertSame('n350', end($journal)['text']);
$this->assertNotSame('oldest', $journal[0]['text']);