feat: make SupersetClient retry on 502-504 (#34290)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Beto Dealmeida
2025-07-24 10:46:50 -04:00
committed by GitHub
parent c99843b13a
commit ab59b7e9b0
5 changed files with 55 additions and 2 deletions

View File

@@ -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,
};
}