Skip to content

Commit

Permalink
Merge pull request #1117 from CrowleyRajapakse/newmaster2
Browse files Browse the repository at this point in the history
Adding retry to ratelimit initial policy fetcher
  • Loading branch information
CrowleyRajapakse authored Mar 31, 2024
2 parents b897621 + 6578f14 commit 9ac97ab
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions apim-apk-agent/internal/synchronizer/ratelimit_policy_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/wso2/product-apim-tooling/apim-apk-agent/config"
k8sclient "github.com/wso2/product-apim-tooling/apim-apk-agent/internal/k8sClient"
Expand Down Expand Up @@ -113,15 +114,15 @@ func FetchRateLimitPoliciesOnEvent(ratelimitName string, organization string, c
var errorMsg string
if err != nil {
errorMsg = "Error occurred while calling the REST API: " + policiesEndpoint
go retryFetchData(conf, errorMsg, err, c)
go retryRLPFetchData(conf, errorMsg, err, c)
return
}
responseBytes, err := ioutil.ReadAll(resp.Body)
logger.LoggerSynchronizer.Debugf("Response String received for Policies: %v", string(responseBytes))

if err != nil {
errorMsg = "Error occurred while reading the response received for: " + policiesEndpoint
go retryFetchData(conf, errorMsg, err, c)
go retryRLPFetchData(conf, errorMsg, err, c)
return
}

Expand Down Expand Up @@ -151,6 +152,18 @@ func FetchRateLimitPoliciesOnEvent(ratelimitName string, organization string, c
} else {
errorMsg = "Failed to fetch data! " + policiesEndpoint + " responded with " +
strconv.Itoa(resp.StatusCode)
go retryFetchData(conf, errorMsg, err, c)
go retryRLPFetchData(conf, errorMsg, err, c)
}
}

func retryRLPFetchData(conf *config.Config, errorMessage string, err error, c client.Client) {
logger.LoggerSynchronizer.Debugf("Time Duration for retrying: %v",
conf.ControlPlane.RetryInterval*time.Second)
time.Sleep(conf.ControlPlane.RetryInterval * time.Second)
FetchRateLimitPoliciesOnEvent("", "", c)
retryAttempt++
if retryAttempt >= retryCount {
logger.LoggerSynchronizer.Errorf(errorMessage, err)
return
}
}

0 comments on commit 9ac97ab

Please sign in to comment.