Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 17a9aa165a | |||
| 3e306b70f8 | |||
| 3aa9c15e80 | |||
| 957cf144a7 | |||
| 52b1429ba0 | |||
| 66575982af | |||
| 66932958b1 | |||
| 0d5f65176b | |||
| 5670c008e1 | |||
| f9325772bd |
@@ -66,7 +66,7 @@ test.describe('Intel GPU plugin smoke tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await page.goto('/c/main/intel-gpu/nodes');
|
await page.goto('/c/main/intel-gpu/nodes');
|
||||||
await expect(page.getByRole('heading', { name: /node/i })).toBeVisible({ timeout: 15_000 });
|
await expect(page.getByRole('heading', { name: /intel gpu.*nodes/i })).toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
await page.goto('/c/main/intel-gpu/pods');
|
await page.goto('/c/main/intel-gpu/pods');
|
||||||
await expect(page.getByRole('heading', { name: /pod/i })).toBeVisible({ timeout: 15_000 });
|
await expect(page.getByRole('heading', { name: /pod/i })).toBeVisible({ timeout: 15_000 });
|
||||||
|
|||||||
@@ -151,4 +151,27 @@ describe('IntelGpuDataProvider', () => {
|
|||||||
expect(callCountAfter).toBeGreaterThan(callCountBefore);
|
expect(callCountAfter).toBeGreaterThan(callCountBefore);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats a hanging CRD request as unavailable after 2s timeout', async () => {
|
||||||
|
vi.useFakeTimers();
|
||||||
|
const nodeWrapper = { jsonData: {} };
|
||||||
|
vi.mocked(K8s.ResourceClasses.Node.useList).mockReturnValue([[nodeWrapper], null] as any);
|
||||||
|
vi.mocked(K8s.ResourceClasses.Pod.useList).mockReturnValue([[nodeWrapper], null] as any);
|
||||||
|
vi.mocked(ApiProxy.request)
|
||||||
|
.mockReturnValueOnce(new Promise(() => {}))
|
||||||
|
.mockResolvedValueOnce({ items: [] })
|
||||||
|
.mockResolvedValueOnce({ items: [] })
|
||||||
|
.mockResolvedValueOnce({ items: [] });
|
||||||
|
|
||||||
|
const { result } = renderHook(() => useIntelGpuContext(), { wrapper: Wrapper });
|
||||||
|
|
||||||
|
expect(result.current.loading).toBe(true);
|
||||||
|
|
||||||
|
vi.advanceTimersByTime(2000);
|
||||||
|
await act(async () => {});
|
||||||
|
expect(result.current.crdAvailable).toBe(false);
|
||||||
|
expect(result.current.loading).toBe(false);
|
||||||
|
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -69,6 +69,18 @@ export function useIntelGpuContext(): IntelGpuContextValue {
|
|||||||
// Helpers
|
// Helpers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const DEFAULT_REQUEST_TIMEOUT_MS = 2_000;
|
||||||
|
|
||||||
|
/** Wraps a promise with a timeout, rejecting if it doesn't settle within ms. */
|
||||||
|
function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
|
||||||
|
return Promise.race([
|
||||||
|
promise,
|
||||||
|
new Promise<T>((_, reject) =>
|
||||||
|
setTimeout(() => reject(new Error(`Request timed out after ${ms}ms`)), ms)
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/** Extract raw Kubernetes JSON from Headlamp KubeObject wrappers. */
|
/** Extract raw Kubernetes JSON from Headlamp KubeObject wrappers. */
|
||||||
const extractJsonData = (items: unknown[]): unknown[] =>
|
const extractJsonData = (items: unknown[]): unknown[] =>
|
||||||
items.map(item =>
|
items.map(item =>
|
||||||
@@ -108,8 +120,11 @@ export function IntelGpuDataProvider({ children }: { children: React.ReactNode }
|
|||||||
try {
|
try {
|
||||||
// GpuDevicePlugin CRDs — graceful degradation if CRD not installed
|
// GpuDevicePlugin CRDs — graceful degradation if CRD not installed
|
||||||
try {
|
try {
|
||||||
const pluginList = await ApiProxy.request(
|
const pluginList = await withTimeout(
|
||||||
`/apis/${INTEL_DEVICE_PLUGIN_API_GROUP}/${INTEL_DEVICE_PLUGIN_API_VERSION}/gpudeviceplugins`
|
ApiProxy.request(
|
||||||
|
`/apis/${INTEL_DEVICE_PLUGIN_API_GROUP}/${INTEL_DEVICE_PLUGIN_API_VERSION}/gpudeviceplugins`
|
||||||
|
),
|
||||||
|
DEFAULT_REQUEST_TIMEOUT_MS
|
||||||
);
|
);
|
||||||
if (!cancelled && isKubeList(pluginList)) {
|
if (!cancelled && isKubeList(pluginList)) {
|
||||||
setCrdAvailable(true);
|
setCrdAvailable(true);
|
||||||
@@ -139,7 +154,7 @@ export function IntelGpuDataProvider({ children }: { children: React.ReactNode }
|
|||||||
|
|
||||||
for (const url of pluginPodSelectors) {
|
for (const url of pluginPodSelectors) {
|
||||||
try {
|
try {
|
||||||
const list = await ApiProxy.request(url);
|
const list = await withTimeout(ApiProxy.request(url), DEFAULT_REQUEST_TIMEOUT_MS);
|
||||||
if (!cancelled && isKubeList(list)) {
|
if (!cancelled && isKubeList(list)) {
|
||||||
const gpuPluginPods = filterIntelGpuPluginPods(list.items);
|
const gpuPluginPods = filterIntelGpuPluginPods(list.items);
|
||||||
foundPluginPods.push(...gpuPluginPods);
|
foundPluginPods.push(...gpuPluginPods);
|
||||||
|
|||||||
@@ -106,13 +106,11 @@ describe('MetricsPage', () => {
|
|||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows loader when ctxLoading=true but heading is visible immediately', () => {
|
it('shows loader when ctxLoading=true', () => {
|
||||||
vi.mocked(useIntelGpuContext).mockReturnValue(makeContext({ loading: true }));
|
vi.mocked(useIntelGpuContext).mockReturnValue(makeContext({ loading: true }));
|
||||||
// fetchGpuMetrics should never be called in loading state
|
// fetchGpuMetrics should never be called in loading state
|
||||||
vi.mocked(fetchGpuMetrics).mockResolvedValue(null);
|
vi.mocked(fetchGpuMetrics).mockResolvedValue(null);
|
||||||
render(<MetricsPage />);
|
render(<MetricsPage />);
|
||||||
// Heading renders immediately, loader appears below it while waiting for context
|
|
||||||
expect(screen.getByText('Intel GPU — Metrics')).toBeInTheDocument();
|
|
||||||
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Intel GPU data...');
|
expect(screen.getByTestId('loader')).toHaveTextContent('Loading Intel GPU data...');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -230,6 +230,10 @@ export default function MetricsPage() {
|
|||||||
};
|
};
|
||||||
}, [ctxLoading, fetchSeq]);
|
}, [ctxLoading, fetchSeq]);
|
||||||
|
|
||||||
|
if (ctxLoading) {
|
||||||
|
return <Loader title="Loading Intel GPU data..." />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -243,7 +247,7 @@ export default function MetricsPage() {
|
|||||||
<SectionHeader title="Intel GPU — Metrics" />
|
<SectionHeader title="Intel GPU — Metrics" />
|
||||||
<button
|
<button
|
||||||
onClick={() => void doFetch()}
|
onClick={() => void doFetch()}
|
||||||
disabled={fetching || ctxLoading}
|
disabled={fetching}
|
||||||
aria-label="Refresh metrics"
|
aria-label="Refresh metrics"
|
||||||
style={{
|
style={{
|
||||||
padding: '6px 16px',
|
padding: '6px 16px',
|
||||||
@@ -251,18 +255,15 @@ export default function MetricsPage() {
|
|||||||
color: 'var(--mui-palette-primary-main, #0071c5)',
|
color: 'var(--mui-palette-primary-main, #0071c5)',
|
||||||
border: '1px solid var(--mui-palette-primary-main, #0071c5)',
|
border: '1px solid var(--mui-palette-primary-main, #0071c5)',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
cursor: fetching || ctxLoading ? 'not-allowed' : 'pointer',
|
cursor: 'pointer',
|
||||||
fontSize: '13px',
|
fontSize: '13px',
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
opacity: fetching || ctxLoading ? 0.6 : 1,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{fetching ? 'Refreshing…' : 'Refresh'}
|
{fetching ? 'Refreshing…' : 'Refresh'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{ctxLoading && <Loader title="Loading Intel GPU data..." />}
|
|
||||||
|
|
||||||
<MetricRequirements />
|
<MetricRequirements />
|
||||||
|
|
||||||
{fetching && !metrics && <Loader title="Querying Prometheus for GPU metrics..." />}
|
{fetching && !metrics && <Loader title="Querying Prometheus for GPU metrics..." />}
|
||||||
|
|||||||
Reference in New Issue
Block a user