mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
feat: make SupersetClient retry on 502-504 (#34290)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -31,12 +31,44 @@ function getDefaultConfiguration(): ClientConfig {
|
||||
bootstrapData.common.conf.JWT_ACCESS_CSRF_COOKIE_NAME;
|
||||
const cookieCSRFToken = parseCookie()[jwtAccessCsrfCookieName] || '';
|
||||
|
||||
// Configure retry behavior from backend settings
|
||||
const retryConfig = bootstrapData.common.conf;
|
||||
|
||||
// Create exponential backoff delay function with jitter
|
||||
const createRetryDelayFunction = () => {
|
||||
const baseDelay = retryConfig.SUPERSET_CLIENT_RETRY_DELAY || 1000;
|
||||
const multiplier =
|
||||
retryConfig.SUPERSET_CLIENT_RETRY_BACKOFF_MULTIPLIER || 2;
|
||||
const maxDelay = retryConfig.SUPERSET_CLIENT_RETRY_MAX_DELAY || 10000;
|
||||
|
||||
return (attempt: number) => {
|
||||
// Calculate exponential backoff: baseDelay * Math.pow(multiplier, attempt)
|
||||
const safeAttempt = Math.min(attempt, 10); // Limit attempt to prevent overflow
|
||||
const exponentialDelay = baseDelay * Math.pow(multiplier, safeAttempt);
|
||||
|
||||
// Apply max delay cap
|
||||
const cappedDelay = Math.min(exponentialDelay, maxDelay);
|
||||
|
||||
// Add random jitter to prevent thundering herd
|
||||
const jitter = Math.random() * cappedDelay;
|
||||
|
||||
return cappedDelay + jitter;
|
||||
};
|
||||
};
|
||||
|
||||
const fetchRetryOptions = {
|
||||
retries: retryConfig.SUPERSET_CLIENT_RETRY_ATTEMPTS || 3,
|
||||
retryDelay: createRetryDelayFunction(),
|
||||
retryOn: retryConfig.SUPERSET_CLIENT_RETRY_STATUS_CODES || [502, 503, 504],
|
||||
};
|
||||
|
||||
return {
|
||||
protocol: ['http:', 'https:'].includes(window?.location?.protocol)
|
||||
? (window?.location?.protocol as 'http:' | 'https:')
|
||||
: undefined,
|
||||
host: window.location?.host || '',
|
||||
csrfToken: csrfToken || cookieCSRFToken,
|
||||
fetchRetryOptions,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user