feat: implement controller health checks (Phase 2.2)

Add comprehensive controller health monitoring functionality with
real-time visual indicators and auto-refresh capabilities.

Features:
- Health check API with 5-second timeout
- Latency tracking and version detection
- ControllerStatus component with color-coded indicators
- Auto-refresh with configurable intervals
- Integration with SettingsPage and SealingKeysView

Technical details:
- AbortController for proper timeout handling
- Never-fail API (always returns status)
- Three states: Healthy (green), Unhealthy (yellow), Unreachable (red)
- Detailed tooltips with error messages
- Response time display in milliseconds
- Version information from X-Controller-Version header

Files:
- src/lib/controller.ts: Add checkControllerHealth() (+58 lines)
- src/components/ControllerStatus.tsx: NEW component (+117 lines)
- src/components/SettingsPage.tsx: Add status display
- src/components/SealingKeysView.tsx: Add status to header
- PHASE_2.2_COMPLETE.md: Implementation documentation

Bundle size: 346.65 kB (95.49 kB gzipped), +2.7 kB (+0.8%)
Build time: 3.94s (improved!)
Zero TypeScript/lint errors

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
2026-02-11 21:41:09 -05:00
parent cc08e15f6a
commit d17e2485fb
5 changed files with 595 additions and 2 deletions
@@ -0,0 +1,114 @@
/**
* Controller Status Indicator
*
* Displays the health status of the sealed-secrets controller,
* including reachability, response time, and version information.
*/
import { CheckCircle, Error as ErrorIcon, Warning } from '@mui/icons-material';
import { Box, Chip, CircularProgress, Tooltip, Typography } from '@mui/material';
import React from 'react';
import { checkControllerHealth, ControllerHealthStatus, getPluginConfig } from '../lib/controller';
interface ControllerStatusProps {
/** Whether to auto-refresh the status */
autoRefresh?: boolean;
/** Refresh interval in milliseconds (default: 30000 = 30s) */
refreshIntervalMs?: number;
/** Show detailed info (latency, version) */
showDetails?: boolean;
}
/**
* Controller status indicator component
*/
export function ControllerStatus({
autoRefresh = false,
refreshIntervalMs = 30000,
showDetails = true,
}: ControllerStatusProps) {
const [status, setStatus] = React.useState<ControllerHealthStatus | null>(null);
const [loading, setLoading] = React.useState(true);
const fetchStatus = React.useCallback(async () => {
setLoading(true);
const config = getPluginConfig();
const result = await checkControllerHealth(config);
if (result.ok) {
setStatus(result.value);
}
setLoading(false);
}, []);
// Initial fetch
React.useEffect(() => {
fetchStatus();
}, [fetchStatus]);
// Auto-refresh
React.useEffect(() => {
if (!autoRefresh) return;
const interval = setInterval(fetchStatus, refreshIntervalMs);
return () => clearInterval(interval);
}, [autoRefresh, refreshIntervalMs, fetchStatus]);
if (loading || !status) {
return (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<CircularProgress size={16} />
<Typography variant="body2" color="text.secondary">
Checking controller...
</Typography>
</Box>
);
}
// Build status message and icon
let statusColor: 'success' | 'error' | 'warning' = 'error';
let StatusIcon = ErrorIcon;
let statusLabel = 'Unreachable';
let tooltipText = status.error || 'Controller is unreachable';
if (status.healthy) {
statusColor = 'success';
StatusIcon = CheckCircle;
statusLabel = 'Healthy';
tooltipText = `Controller is healthy${status.version ? ` (${status.version})` : ''}`;
} else if (status.reachable) {
statusColor = 'warning';
StatusIcon = Warning;
statusLabel = 'Unhealthy';
tooltipText = status.error || 'Controller responded but is not healthy';
}
return (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
<Tooltip title={tooltipText}>
<Chip
icon={<StatusIcon />}
label={statusLabel}
color={statusColor}
size="small"
variant="outlined"
/>
</Tooltip>
{showDetails && status.healthy && (
<>
{status.latencyMs !== undefined && (
<Typography variant="caption" color="text.secondary">
{status.latencyMs}ms
</Typography>
)}
{status.version && (
<Typography variant="caption" color="text.secondary">
v{status.version}
</Typography>
)}
</>
)}
</Box>
);
}
@@ -12,6 +12,7 @@ import React from 'react';
import { fetchPublicCertificate, getPluginConfig } from '../lib/controller';
import { isCertificateExpiringSoon, parseCertificateInfo } from '../lib/crypto';
import { CertificateInfo, PEMCertificate } from '../types';
import { ControllerStatus } from './ControllerStatus';
interface SealingKey {
name: string;
@@ -96,6 +97,7 @@ export function SealingKeysView() {
title="Sealing Keys"
headerProps={{
actions: [
<ControllerStatus key="status" autoRefresh refreshIntervalMs={60000} showDetails />,
<Button key="download" variant="contained" onClick={handleDownloadCert}>
Download Public Certificate
</Button>,
@@ -5,11 +5,12 @@
*/
import { SectionBox } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import { Box, Button, TextField, Typography } from '@mui/material';
import { Box, Button, Divider, TextField, Typography } from '@mui/material';
import { useSnackbar } from 'notistack';
import React from 'react';
import { getPluginConfig, savePluginConfig } from '../lib/controller';
import { PluginConfig } from '../types';
import { ControllerStatus } from './ControllerStatus';
/**
* Settings page component
@@ -42,6 +43,16 @@ export function SettingsPage() {
your browser's local storage.
</Typography>
{/* Controller Health Status */}
<Box mb={3} p={2} bgcolor="background.paper" borderRadius={1} border={1} borderColor="divider">
<Typography variant="subtitle2" gutterBottom>
Controller Status
</Typography>
<ControllerStatus autoRefresh showDetails />
</Box>
<Divider sx={{ mb: 3 }} />
<TextField
fullWidth
label="Controller Name"