Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fallback strategy in tier balancer #588

Closed
astsiapanay opened this issue Nov 26, 2024 · 0 comments
Closed

Implement fallback strategy in tier balancer #588

astsiapanay opened this issue Nov 26, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@astsiapanay
Copy link
Collaborator

Note. The field used has http request scope.

 // there are no available upstream at the moment
   // fallback: we want to make one more try for an upstream with the min retry time       
   
   // the flag `used` is needed to mark an upstream not to use in the next fallback iteration
   // it's reset when upstream returns succeeded code 200(OK) 

   var candidate = upstreams
        .filter(upstream -> isHttpCode5xx(upstream.statusCode) && upstream.retryAfterSource == CORE && !upstream.used)
        .min(upstream -> upstream.retryAfter)
   if (candidate != null) {
        candidate.used = true
        return candidate
   }
          
   candidate = upstreams
        .filter(upstream -> isHttpCode5xx(upstream.statusCode) && upstream.retryAfterSource == UPSTREAM && !upstream.used)
        .min(upstream -> upstream.retryAfter)
   if (candidate != null) {
        candidate.used = true
        return candidate
   }
        
   candidate = upstreams
        .filter(upstream -> upstream.statusCode == 429 && upstream.retryAfterSource == CORE && !upstream.used)
        .min(upstream -> upstream.retryAfter)    
   if (candidate != null) {
        candidate.used = true
        return candidate
   }      
   
   candidate = upstreams
        .filter(upstream -> upstream.statusCode == 429 && upstream.retryAfterSource == UPSTREAM && !upstream.used)
        .min(upstream -> upstream.retryAfter)
   candidate.used = true
   
   return candidate                             
   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

1 participant