Skip to content

Commit dd75f96

Browse files
committed
feat: unset query timeouts so they are defined in the backend
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
1 parent d5a89cb commit dd75f96

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

web/src/components/Incidents/api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
import { getPrometheusBasePath, buildPrometheusUrl } from '../utils';
99
import { PROMETHEUS_QUERY_INTERVAL_SECONDS } from './utils';
1010

11+
// Disable client-side timeout (-1) to let the backend control query timeouts
12+
const NO_TIMEOUT = -1;
13+
1114
const MAX_URL_LENGTH = 2048;
1215

1316
/**
@@ -136,7 +139,7 @@ export const fetchDataForIncidentsAndAlerts = async (
136139
} as PrometheusResponse);
137140
}
138141

139-
return consoleFetchJSON(url);
142+
return consoleFetchJSON(url, 'GET', {}, NO_TIMEOUT);
140143
});
141144

142145
const responses = await Promise.all(promises);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { useEffect, useRef } from 'react';
22
import { consoleFetchJSON } from '@openshift-console/dynamic-plugin-sdk';
33

4+
// Disable client-side timeout (-1) to let the backend control query timeouts
5+
const NO_TIMEOUT = -1;
6+
47
export const useSafeFetch = () => {
58
const controller = useRef<AbortController>();
69
useEffect(() => {
@@ -9,5 +12,5 @@ export const useSafeFetch = () => {
912
}, []);
1013

1114
return <T>(url: string): Promise<T> =>
12-
consoleFetchJSON(url, 'get', { signal: controller.current.signal as AbortSignal });
15+
consoleFetchJSON(url, 'GET', { signal: controller.current.signal as AbortSignal }, NO_TIMEOUT);
1316
};

web/src/components/fetch-alerts.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { consoleFetchJSON, PrometheusRulesResponse } from '@openshift-console/dynamic-plugin-sdk';
22

3+
// Disable client-side timeout (-1) to let the backend control query timeouts
4+
const NO_TIMEOUT = -1;
5+
36
// Merges Prometheus monitoring alerts with external sources
47
export const fetchAlerts = async (
58
prometheusURL: string,
@@ -10,7 +13,7 @@ export const fetchAlerts = async (
1013
namespace?: string,
1114
): Promise<PrometheusRulesResponse> => {
1215
if (!externalAlertsFetch || externalAlertsFetch.length === 0) {
13-
return consoleFetchJSON(prometheusURL);
16+
return consoleFetchJSON(prometheusURL, 'GET', {}, NO_TIMEOUT);
1417
}
1518

1619
const resolvedExternalAlertsSources = externalAlertsFetch.map((extensionProperties) => ({
@@ -22,7 +25,7 @@ export const fetchAlerts = async (
2225

2326
try {
2427
const groups = await Promise.allSettled([
25-
consoleFetchJSON(prometheusURL),
28+
consoleFetchJSON(prometheusURL, 'GET', {}, NO_TIMEOUT),
2629
...resolvedExternalAlertsSources.map((source) => source.fetch(namespace)),
2730
]).then((results) =>
2831
results
@@ -39,6 +42,6 @@ export const fetchAlerts = async (
3942

4043
return { data: { groups }, status: 'success' };
4144
} catch {
42-
return consoleFetchJSON(prometheusURL);
45+
return consoleFetchJSON(prometheusURL, 'GET', {}, NO_TIMEOUT);
4346
}
4447
};

web/src/components/proxied-fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const proxiedFetch = <T>(url: string, init?: RequestInitWithTimeout): Pro
4343
return response.json();
4444
});
4545

46-
const timeout = init?.timeout ?? 30 * 1000;
46+
// Disable client-side timeout by default (-1) to let the backend control query timeouts
47+
const timeout = init?.timeout ?? -1;
4748

4849
if (timeout <= 0) {
4950
return fetchPromise;

0 commit comments

Comments
 (0)