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:
@@ -5,9 +5,25 @@
|
||||
* via the Kubernetes API proxy.
|
||||
*/
|
||||
|
||||
import { AsyncResult, Err, PEMCertificate, PluginConfig, tryCatchAsync } from '../types';
|
||||
import { AsyncResult, Err, Ok, PEMCertificate, PluginConfig, tryCatchAsync } from '../types';
|
||||
import { retryWithBackoff } from './retry';
|
||||
|
||||
/**
|
||||
* Controller health status information
|
||||
*/
|
||||
export interface ControllerHealthStatus {
|
||||
/** Whether the controller is healthy and responding */
|
||||
healthy: boolean;
|
||||
/** Whether the controller is reachable */
|
||||
reachable: boolean;
|
||||
/** Controller version if available */
|
||||
version?: string;
|
||||
/** Response latency in milliseconds */
|
||||
latencyMs?: number;
|
||||
/** Error message if not healthy */
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the controller proxy URL
|
||||
*/
|
||||
@@ -156,3 +172,68 @@ export function getPluginConfig(): PluginConfig {
|
||||
export function savePluginConfig(config: PluginConfig): void {
|
||||
localStorage.setItem('sealed-secrets-plugin-config', JSON.stringify(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check controller health and reachability
|
||||
*
|
||||
* Attempts to reach the controller's health endpoint (/healthz) with a 5-second timeout.
|
||||
* Returns health status including latency and version information if available.
|
||||
*
|
||||
* @param config Plugin configuration
|
||||
* @returns Result containing health status (never fails - returns status even if unreachable)
|
||||
*/
|
||||
export async function checkControllerHealth(
|
||||
config: PluginConfig
|
||||
): AsyncResult<ControllerHealthStatus, string> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
const url = getControllerProxyURL(config, '/healthz');
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5s timeout
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
const latencyMs = Date.now() - startTime;
|
||||
|
||||
if (!response.ok) {
|
||||
return Ok({
|
||||
healthy: false,
|
||||
reachable: true,
|
||||
latencyMs,
|
||||
error: `HTTP ${response.status}: ${response.statusText}`,
|
||||
});
|
||||
}
|
||||
|
||||
// Try to get version from headers
|
||||
const version = response.headers.get('X-Controller-Version') || undefined;
|
||||
|
||||
return Ok({
|
||||
healthy: true,
|
||||
reachable: true,
|
||||
version,
|
||||
latencyMs,
|
||||
});
|
||||
} catch (error: any) {
|
||||
const latencyMs = Date.now() - startTime;
|
||||
|
||||
// Determine error type
|
||||
let errorMessage = 'Controller unreachable';
|
||||
if (error.name === 'AbortError') {
|
||||
errorMessage = 'Request timed out after 5 seconds';
|
||||
} else if (error.message) {
|
||||
errorMessage = error.message;
|
||||
}
|
||||
|
||||
return Ok({
|
||||
healthy: false,
|
||||
reachable: false,
|
||||
latencyMs,
|
||||
error: errorMessage,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user