-
Notifications
You must be signed in to change notification settings - Fork 14
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
Handle throttling #169
Handle throttling #169
Conversation
Frieza should not have to destroy resources, the tests should |
util/reconciler/defaults.go
Outdated
buffer := new(strings.Builder) | ||
_, err := io.Copy(buffer, httpRes.Body) | ||
httpResBody := buffer.String() | ||
httpResBodyData := []byte(httpResBody) | ||
httpResBodyParsed, err := gabs.ParseJSON(httpResBodyData) | ||
if err != nil { | ||
return true | ||
} | ||
httpResCode := strings.Replace(strings.Replace(fmt.Sprintf("%v", httpResBodyParsed.Path("Errors.Code").Data()), "[", "", 1), "]", "", 1) | ||
httpResType := strings.Replace(strings.Replace(fmt.Sprintf("%v", httpResBodyParsed.Path("Errors.Type").Data()), "[", "", 1), "]", "", 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this instead of reading the body manually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
clusterScope.Info("Find body", "httpResBody", httpResBody) | ||
clusterScope.Info("Find httpResCode", "httpResCode", httpRes.StatusCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep logging as concise as possible. One line for logging, not multiple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have these info when you have the debug activated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/storage/volume.go
Outdated
if httpRes != nil { | ||
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throttling error should be a constant so that we can modify later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Closes #3 |
@outscale-mdr @outscale-hmi are you ok with latest changes ? |
cloud/services/compute/image.go
Outdated
allowedErrors) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("coulld not read image in Osc: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/image.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
requestStr := fmt.Sprintf("%v", readImageRequest) | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"AccessDenied": 503
should be refactorize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the "429" for throttling (in case of changes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/image.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
requestStr := fmt.Sprintf("%v", readImageRequest) | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same refactorisation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/image.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
requestStr := fmt.Sprintf("%v", readImageRequest) | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same refactorisation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
requestStr := fmt.Sprintf("%v", vmOpt) | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same refactorisation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
if httpRes != nil { | ||
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same refactorisation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDenied": 503} | ||
requestStr := fmt.Sprintf("Name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it ? Your message will be
Retry even if got (%v) error type with code error (%v) on request Name
You should show the request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
allowedErrors) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("could not read vm in Osc:: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDennied": 503} | ||
requestStr := fmt.Sprintf("OscK8sNodeName") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve the requestStr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
_, httpRes, err = oscApiClient.InternetServiceApi.UnlinkInternetService(oscAuthClient).UnlinkInternetServiceRequest(unlinkInternetServiceRequest).Execute() | ||
if err != nil { | ||
if httpRes != nil { | ||
fmt.Printf("Error with http resul %s", httpRes.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok0
_, httpRes, err = oscApiClient.InternetServiceApi.LinkInternetService(oscAuthClient).LinkInternetServiceRequest(linkInternetServiceRequest).Execute() | ||
if err != nil { | ||
if httpRes != nil { | ||
fmt.Printf("Error ith http result %s", httpRes.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check
_, httpRes, err = oscApiClient.InternetServiceApi.UnlinkInternetService(oscAuthClient).UnlinkInternetServiceRequest(unlinkInternetServiceRequest).Execute() | ||
if err != nil { | ||
if httpRes != nil { | ||
fmt.Printf("Error with http resul %s", httpRes.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check
cloud/services/net/net.go
Outdated
allowedErrors) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("could noot create net in Osc: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
cloud/services/storage/volume.go
Outdated
allowedErrors) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("couldd not create volume in OSC: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
clusterScope.Info("Find body", "httpResBody", httpResBody) | ||
clusterScope.Info("Find httpResCode", "httpResCode", httpRes.StatusCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
if httpRes != nil { | ||
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDenied": 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDenied": 503} | ||
requestStr := fmt.Sprintf("Name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
allowedErrors) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("could not read vm in Osc:: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
cloud/services/compute/vm.go
Outdated
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
allowedErrors := map[string]int{"AccessDennied": 503} | ||
requestStr := fmt.Sprintf("OscK8sNodeName") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
_, httpRes, err = oscApiClient.InternetServiceApi.UnlinkInternetService(oscAuthClient).UnlinkInternetServiceRequest(unlinkInternetServiceRequest).Execute() | ||
if err != nil { | ||
if httpRes != nil { | ||
fmt.Printf("Error with http resul %s", httpRes.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok0
cloud/services/net/net.go
Outdated
err = tag.AddTag("Name", netName, resourceIds, oscApiClient, oscAuthClient) | ||
if err != nil { | ||
fmt.Printf("Error with http result %s", httpRes.Status) | ||
return nil, err | ||
netTag := osc.ResourceTag{ | ||
Key: "Name", | ||
Value: netName, | ||
} | ||
err = tag.AddTag("OscK8sClusterID/"+clusterName, "owned", resourceIds, oscApiClient, oscAuthClient) | ||
if err != nil { | ||
fmt.Printf("Error with http result %s", httpRes.Status) | ||
netTagRequest := osc.CreateTagsRequest{ | ||
ResourceIds: resourceIds, | ||
Tags: []osc.ResourceTag{netTag}, | ||
} | ||
|
||
addTagNameCallBack := func() (bool, error) { | ||
err, httpRes := tag.AddTag(netTagRequest, resourceIds, oscApiClient, oscAuthClient) | ||
if err != nil { | ||
if httpRes != nil { | ||
fmt.Printf("Error with http result %s", httpRes.Status) | ||
} | ||
requestStr := fmt.Sprintf("%v", netTagRequest) | ||
if reconciler.KeepRetryWithError( | ||
requestStr, | ||
httpRes.StatusCode, | ||
reconciler.AllowedErrors) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("%w failed to add Name tag", err) | ||
} | ||
return true, err | ||
} | ||
waitErr = wait.ExponentialBackoff(backoff, addTagNameCallBack) | ||
if waitErr != nil { | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did see during the first review but the retry should be done when you make the call API.
Here the retry should be done inside the tag.AddTag
.
With you current changes, we have a lot of duplicate codes !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok done
util/reconciler/defaults.go
Outdated
@@ -25,10 +29,60 @@ const ( | |||
DefaultMappingTimeout = 60 * time.Second | |||
) | |||
|
|||
var AllowedErrors = []int{429, 503} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to ThrottlingErrors or add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok done
leaseDuration := 40 * time.Second | ||
leaseDuration := 60 * time.Second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for the PR right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is good thanks.
What type of PR is this?
/kind feature
What this PR does / why we need it:
To handle throttling
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #3
Special notes for your reviewer:
It handle code error and code type.
No Mock.
First version that will be changes when throttling will have more restrict rules.
TODOs: