af95c3795c
Phase 1 — Structural overhaul: - Move all source from headlamp-sealed-secrets/ subdirectory to repo root - Delete 23 AI-generated docs, 8 pre-built tarballs, release snapshots dir - Remove all working-directory refs from CI/release workflows - Update install-plugin.sh and typedoc.json paths Phase 2 — Config standardization: - Create .eslintrc.js and .prettierrc.js (standard Headlamp configs) - Remove inline eslintConfig/prettier from package.json (drop jsx-a11y, prettier extends) - Rewrite tsconfig.json (package name extend, add compilerOptions.types) - Create vitest.config.mts and vitest.setup.ts (standard from polaris) - Replace headlamp-plugin CLI scripts with direct tool invocation - Rewrite .gitignore with standard baseline Phase 3 — MCP & Claude settings: - Create .mcp.json with github/kubernetes/flux/playwright servers - Create .claude/settings.local.json - Remove 7 specialized agents, keep 3 meta-orchestration agents Phase 4 — Documentation: - Rewrite CLAUDE.md (remove subdirectory refs, standard format) - Add ArtifactHub badge, Architecture section, standardized install methods to README.md - Create CONTRIBUTING.md and SECURITY.md - Fix pre-existing test bugs in validators.test.ts (isValidNamespace returns boolean, not ValidationResult; error message string mismatches) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
/**
|
|
* Custom Hook for Controller Health Monitoring
|
|
*
|
|
* Provides controller health status with automatic refresh capability.
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { checkControllerHealth, ControllerHealthStatus, getPluginConfig } from '../lib/controller';
|
|
|
|
/**
|
|
* Custom hook for monitoring controller health
|
|
*
|
|
* Automatically checks controller health on mount and can optionally
|
|
* refresh at a specified interval.
|
|
*
|
|
* @param autoRefresh Whether to automatically refresh health status
|
|
* @param refreshIntervalMs Refresh interval in milliseconds (default: 30000ms = 30s)
|
|
* @returns Object with health status, loading state, and manual refresh function
|
|
*
|
|
* @example
|
|
* // Manual refresh only
|
|
* const { health, loading, refresh } = useControllerHealth();
|
|
*
|
|
* // Auto-refresh every 30 seconds
|
|
* const { health, loading } = useControllerHealth(true, 30000);
|
|
*
|
|
* // Auto-refresh every 10 seconds
|
|
* const { health, loading } = useControllerHealth(true, 10000);
|
|
*/
|
|
export function useControllerHealth(autoRefresh = false, refreshIntervalMs = 30000) {
|
|
const [health, setHealth] = React.useState<ControllerHealthStatus | null>(null);
|
|
const [loading, setLoading] = React.useState(true);
|
|
|
|
const fetchHealth = React.useCallback(async () => {
|
|
setLoading(true);
|
|
|
|
const config = getPluginConfig();
|
|
const result = await checkControllerHealth(config);
|
|
|
|
if (result.ok) {
|
|
setHealth(result.value);
|
|
} else if (result.ok === false) {
|
|
// Even on error, checkControllerHealth returns a status
|
|
// This shouldn't happen, but handle gracefully
|
|
setHealth({
|
|
healthy: false,
|
|
reachable: false,
|
|
error: result.error,
|
|
});
|
|
}
|
|
|
|
setLoading(false);
|
|
}, []);
|
|
|
|
// Initial fetch and auto-refresh setup
|
|
React.useEffect(() => {
|
|
fetchHealth();
|
|
|
|
if (autoRefresh) {
|
|
const interval = setInterval(fetchHealth, refreshIntervalMs);
|
|
return () => clearInterval(interval);
|
|
}
|
|
}, [autoRefresh, refreshIntervalMs, fetchHealth]);
|
|
|
|
return {
|
|
health,
|
|
loading,
|
|
refresh: fetchHealth,
|
|
};
|
|
}
|