Enhance Node health column (#1023)

* Make sure we are talking to a `Pelican Wings` instance

* Enforce matching `token_id`

* Refactor `NodeSystemInformation`
This commit is contained in:
MartinOscar 2025-02-22 21:44:49 +01:00 committed by GitHub
parent 7d68da41f4
commit d03366cf3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 29 deletions

View File

@ -27,7 +27,7 @@ class ListNodes extends ListRecords
->label('UUID') ->label('UUID')
->searchable() ->searchable()
->hidden(), ->hidden(),
NodeHealthColumn::make('health')->label(trans('admin/node.table.health')), NodeHealthColumn::make('health'),
TextColumn::make('name') TextColumn::make('name')
->label(trans('admin/node.table.name')) ->label(trans('admin/node.table.name'))
->icon('tabler-server-2') ->icon('tabler-server-2')

View File

@ -12,6 +12,8 @@ class NodeHealthColumn extends IconColumn
{ {
parent::setUp(); parent::setUp();
$this->label(trans('admin/node.table.health'));
$this->alignCenter(); $this->alignCenter();
} }
} }

View File

@ -17,7 +17,22 @@ class DaemonConfigurationRepository extends DaemonRepository
{ {
return $this->getHttpClient() return $this->getHttpClient()
->connectTimeout(3) ->connectTimeout(3)
->get('/api/system')->throw()->json(); ->get('/api/system')
->throwIf(function ($result) {
$header = $result->header('User-Agent');
if (
filled($header) &&
preg_match('/^Pelican Wings\/v(?:\d+\.\d+\.\d+|develop) \(id:(\w*)\)$/', $header, $matches) &&
array_get($matches, 1, '') !== $this->node->daemon_token_id
) {
throw new ConnectionException($result->effectiveUri()->__toString() . ' does not match node token_id !');
}
if (!$result->collect()->has(['architecture', 'cpu_count', 'kernel_version', 'os', 'version'])) {
throw new ConnectionException($result->effectiveUri()->__toString() . ' is not Pelican Wings !');
}
return true;
})->json();
} }
/** /**

View File

@ -1,33 +1,31 @@
<div wire:poll.10s> <div wire:poll.10s>
@switch($node->systemInformation()['version'] ?? 'false') @php
@case('false') $exception = $node->systemInformation()['exception'] ?? null;
<x-filament::icon $version = $node->systemInformation()['version'] ?? null;
x-tooltip="{ $content = $exception ? 'Error connecting to node!<br>Check browser console for details.' : $version;
content: 'Error connecting to node!<br>Check browser console for details.', $icon = 'tabler-heart' . ($exception ? '-off' : 'beat');
theme: $store.theme, $animated = $exception ? '' : 'animate-pulse';
allowHTML: true, $condition = $exception ? 'danger' : 'success';
placement: 'bottom', $class = ['fi-ta-icon-item', $sizeClasses, 'fi-color-custom text-custom-500 dark:text-custom-400', 'fi-color-'.$condition, $animated];
}" $style = [Filament\Support\get_color_css_variables($condition, shades: [400, 500], alias: 'tables::columns.icon-column.item')];
:icon="'tabler-heart-off'" @endphp
@class(['fi-ta-icon-item', $sizeClasses, 'fi-color-custom text-custom-500 dark:text-custom-400', 'fi-color-danger']) <x-filament::icon
@style([\Filament\Support\get_color_css_variables('danger', shades: [400, 500], alias: 'tables::columns.icon-column.item') => true]) x-tooltip="{
/> content: '{{ $content }}',
theme: $store.theme,
allowHTML: true,
placement: 'bottom',
}"
:icon='$icon'
@class($class)
@style($style)
/>
@if($exception)
@script @script
<script> <script>
console.error(@json($node->systemInformation())); // TODO Make Purdy console.error('{{ $exception }} ');
</script> </script>
@endscript @endscript
@break @endif
@default </div>
<x-filament::icon
x-tooltip="{
content: '{{ $node->systemInformation()['version'] }}',
theme: $store.theme,
placement: 'bottom',
}"
:icon="'tabler-heartbeat'"
@class(['fi-ta-icon-item', $sizeClasses, 'fi-color-custom text-custom-500 dark:text-custom-400', 'fi-color-success' => true])
@style([\Filament\Support\get_color_css_variables('success', shades: [400, 500], alias: 'tables::columns.icon-column.item') => true])
/>
@endswitch
</div> </div>