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

Handle throttling #169

Merged
2 commits merged into from Dec 15, 2022
Merged

Handle throttling #169

2 commits merged into from Dec 15, 2022

Conversation

ghost
Copy link

@ghost ghost commented Oct 31, 2022

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:

  • squashed commits
  • includes documentation
  • adds unit tests

@ghost ghost requested review from outscale-hmi and outscale-mdr November 3, 2022 09:20
@ghost
Copy link
Author

ghost commented Nov 4, 2022

@outscale-mdr
Copy link
Contributor

outscale-mdr commented Nov 4, 2022

Frieza should not have to destroy resources, the tests should

Comment on lines 56 to 65
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)
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment on lines 220 to 221
clusterScope.Info("Find body", "httpResBody", httpResBody)
clusterScope.Info("Find httpResCode", "httpResCode", httpRes.StatusCode)
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

if httpRes != nil {
fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@ghost
Copy link
Author

ghost commented Nov 9, 2022

Closes #3

@ghost ghost requested a review from outscale-mdr November 15, 2022 14:00
@ghost
Copy link
Author

ghost commented Nov 15, 2022

@outscale-mdr @outscale-hmi are you ok with latest changes ?

allowedErrors) {
return false, nil
}
return false, fmt.Errorf("coulld not read image in Osc: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
requestStr := fmt.Sprintf("%v", readImageRequest)
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Contributor

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

Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
requestStr := fmt.Sprintf("%v", readImageRequest)
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same refactorisation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
requestStr := fmt.Sprintf("%v", readImageRequest)
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same refactorisation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
requestStr := fmt.Sprintf("%v", vmOpt)
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same refactorisation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

if httpRes != nil {
fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same refactorisation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDenied": 503}
requestStr := fmt.Sprintf("Name")
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

allowedErrors) {
return false, nil
}
return false, fmt.Errorf("could not read vm in Osc:: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDennied": 503}
requestStr := fmt.Sprintf("OscK8sNodeName")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve the requestStr

Copy link
Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok0

@ghost ghost requested a review from outscale-mdr November 17, 2022 17:47
_, httpRes, err = oscApiClient.InternetServiceApi.LinkInternetService(oscAuthClient).LinkInternetServiceRequest(linkInternetServiceRequest).Execute()
if err != nil {
if httpRes != nil {
fmt.Printf("Error ith http result %s", httpRes.Status)
Copy link
Author

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check

allowedErrors) {
return false, nil
}
return false, fmt.Errorf("could noot create net in Osc: %v", err)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check

allowedErrors) {
return false, nil
}
return false, fmt.Errorf("couldd not create volume in OSC: %v", err)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check

Comment on lines 220 to 221
clusterScope.Info("Find body", "httpResBody", httpResBody)
clusterScope.Info("Find httpResCode", "httpResCode", httpRes.StatusCode)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

if httpRes != nil {
fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDenied": 503}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDenied": 503}
requestStr := fmt.Sprintf("Name")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

allowedErrors) {
return false, nil
}
return false, fmt.Errorf("could not read vm in Osc:: %v", err)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

fmt.Printf("Error with http result %s", httpRes.Status)
}
allowedErrors := map[string]int{"AccessDennied": 503}
requestStr := fmt.Sprintf("OscK8sNodeName")
Copy link
Author

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok0

Comment on lines 54 to 76
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
}
Copy link
Contributor

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 !

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok done

@@ -25,10 +29,60 @@ const (
DefaultMappingTimeout = 60 * time.Second
)

var AllowedErrors = []int{429, 503}
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok done

@ghost ghost requested a review from outscale-mdr November 21, 2022 18:06
@ghost ghost assigned outscale-hmi Nov 24, 2022
@ghost ghost removed the request for review from outscale-mdr December 2, 2022 13:19
@ghost ghost added the kind/feature Feature resolution label Dec 7, 2022
@ghost ghost requested review from outscale-mdr and removed request for outscale-mdr December 14, 2022 17:28
leaseDuration := 40 * time.Second
leaseDuration := 60 * time.Second
Copy link
Contributor

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 ?

Copy link
Author

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.

@ghost ghost merged commit 7875256 into outscale:main Dec 15, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Feature resolution
Development

Successfully merging this pull request may close these issues.

Be resilient to throttling errors
3 participants