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')
->searchable()
->hidden(),
NodeHealthColumn::make('health')->label(trans('admin/node.table.health')),
NodeHealthColumn::make('health'),
TextColumn::make('name')
->label(trans('admin/node.table.name'))
->icon('tabler-server-2')

View File

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

View File

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