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

TT-7248 Added backoff algorithm to pull the plugin bundles. #4513

Merged

Conversation

sredxny
Copy link
Contributor

@sredxny sredxny commented Dec 8, 2022

Description

Currently if the gateway cannot pull a plugin bundle then it just throw error and continue processing the next api definition. In this PR was introduced a new behavior, the gateway will attempt to download the bundle, of it fails then it will try until 4 more times, the timeframe between one attempt and the other is defined by an exponential backoff described here

Now when an API will load a bundle, it's processed async so the loading of the other apis is not blocked by this one.

Related Issue

https://tyktech.atlassian.net/browse/TT-7248

Motivation and Context

Provide a better response when downloading the bundles fails for external causes

How This Has Been Tested

  • Added unit test for backoff algorithm
  • in Dash+GW setup: created apis, one of them with bundle plugin...finally check that all the apis are reachable

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 8, 2022

API tests result: success
Branch used: refs/pull/4513/merge
Commit:
Triggered by: pull_request (@sredxny)
Execution page

@TykTechnologies TykTechnologies deleted a comment from github-actions bot Dec 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

💥 CI tests failed 🙈

git-state

all ok

Please look at the run or in the Checks tab.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 12, 2022

API tests result: success
Branch used: refs/pull/4513/merge
Commit: 2cb5736
Triggered by: pull_request (@sredxny)
Execution page

@sredxny sredxny changed the title WIP added backoff algorithm to pull the plugin bundles. Added backoff algorithm to pull the plugin bundles. Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from Tyk-ITS Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from Tyk-ITS Dec 12, 2022
@TykTechnologies TykTechnologies deleted a comment from Tyk-ITS Dec 12, 2022
@github-actions
Copy link
Contributor

💥 CI tests failed 🙈

git-state

diff --git a/gateway/coprocess_bundle_test.go b/gateway/coprocess_bundle_test.go
index 53f65df..a82dfe1 100644
--- a/gateway/coprocess_bundle_test.go
+++ b/gateway/coprocess_bundle_test.go
@@ -11,9 +11,10 @@ import (
 	"runtime"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
+
 	"github.com/TykTechnologies/tyk/config"
 	"github.com/TykTechnologies/tyk/test"
-	"github.com/stretchr/testify/assert"
 )
 
 var (

Please look at the run or in the Checks tab.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 12, 2022

API tests result: success
Branch used: refs/pull/4513/merge
Commit: 811c79b
Triggered by: pull_request (@sredxny)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 12, 2022

API tests result: success
Branch used: refs/pull/4513/merge
Commit: f44181f
Triggered by: pull_request (@sredxny)
Execution page

@github-actions
Copy link
Contributor

💥 CI tests failed 🙈

git-state

diff --git a/gateway/coprocess_bundle_test.go b/gateway/coprocess_bundle_test.go
index 53f65df..a82dfe1 100644
--- a/gateway/coprocess_bundle_test.go
+++ b/gateway/coprocess_bundle_test.go
@@ -11,9 +11,10 @@ import (
 	"runtime"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
+
 	"github.com/TykTechnologies/tyk/config"
 	"github.com/TykTechnologies/tyk/test"
-	"github.com/stretchr/testify/assert"
 )
 
 var (

Please look at the run or in the Checks tab.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 12, 2022

API tests result: success
Branch used: refs/pull/4513/merge
Commit: 2ab7e10
Triggered by: pull_request (@sredxny)
Execution page

Comment on lines 628 to 629
if def.CustomMiddlewareBundle != "" {
wg.Add(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lonelycode do you think we need this or just handle all the apis in the same way? The reason to do it in this way is to avoid the gateway to spawn a lot of goroutines, and instead only create an async job when the api to be loaded need to pull a bundle

func (a APIDefinitionLoader) prepareSpecs(apiDefs []nestedApiDefinition) []*APISpec {
var specs []*APISpec

var wg sync.WaitGroup
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@buger I have something against waitgroups and it's that it can generate a lot of jobs at the same time without a limit. What about if we use a pool of workers? in this case, how many of them we should have? or it's too complex for this problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@titpetric awesome, that leads me to the questions: how many should load at the same time?

@sredxny sredxny changed the title Added backoff algorithm to pull the plugin bundles. TT-7248 Added backoff algorithm to pull the plugin bundles. Dec 12, 2022
@sredxny sredxny requested review from buger and mativm02 December 12, 2022 17:40
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 13, 2022

API tests result: success
Branch used: refs/pull/4513/merge
Commit: 0812e44
Triggered by: pull_request (@sredxny)
Execution page

@sredxny sredxny merged commit 2230b14 into master Dec 13, 2022
@sredxny sredxny deleted the feature/TT-7248-implement-backoff-for-plugin-bundle-retry branch December 13, 2022 17:08
@sredxny
Copy link
Contributor Author

sredxny commented Dec 13, 2022

/release to release-4

@tykbot
Copy link

tykbot bot commented Dec 13, 2022

Working on it! Note that it can take a few minutes.

@tykbot
Copy link

tykbot bot commented Dec 13, 2022

@sredxny Succesfully merged PR

tykbot bot pushed a commit that referenced this pull request Dec 13, 2022
<!-- Provide a general summary of your changes in the Title above -->

## Description

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described
[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

## Related Issue

https://tyktech.atlassian.net/browse/TT-7248

## Motivation and Context

Provide a better response when downloading the bundles fails for
external causes

## How This Has Been Tested

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

(cherry picked from commit 2230b14)
@sredxny
Copy link
Contributor Author

sredxny commented Dec 13, 2022

/release to release-4-lts

@tykbot
Copy link

tykbot bot commented Dec 13, 2022

Working on it! Note that it can take a few minutes.

tykbot bot pushed a commit that referenced this pull request Dec 13, 2022
<!-- Provide a general summary of your changes in the Title above -->

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described
[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

https://tyktech.atlassian.net/browse/TT-7248

Provide a better response when downloading the bundles fails for
external causes

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

(cherry picked from commit 2230b14)
@tykbot
Copy link

tykbot bot commented Dec 13, 2022

@sredxny Succesfully merged PR

@sredxny
Copy link
Contributor Author

sredxny commented Dec 13, 2022

/release to release-4.3

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Dec 13, 2022

API tests result: success
Branch used: refs/heads/master
Commit: 2230b14 TT-7248 Added backoff algorithm to pull the plugin bundles. (#4513)

Description

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described
here

Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.

Related Issue

https://tyktech.atlassian.net/browse/TT-7248

Motivation and Context

Provide a better response when downloading the bundles fails for
external causes

How This Has Been Tested

  • Added unit test for backoff algorithm
  • in Dash+GW setup: created apis, one of them with bundle
    plugin...finally check that all the apis are reachable

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to change)
  • Refactoring or add test (improvements in base code or adds test
    coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning
    why it's required
  • I would like a code coverage CI quality gate exception and have
    explained why
    Triggered by: push (@sredxny)
    Execution page

@sredxny
Copy link
Contributor Author

sredxny commented Dec 13, 2022

/release to release-4.3

@tykbot
Copy link

tykbot bot commented Dec 13, 2022

Working on it! Note that it can take a few minutes.

@tykbot
Copy link

tykbot bot commented Dec 13, 2022

@sredxny Succesfully merged PR

tykbot bot pushed a commit that referenced this pull request Dec 13, 2022
<!-- Provide a general summary of your changes in the Title above -->

## Description

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described
[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

## Related Issue

https://tyktech.atlassian.net/browse/TT-7248

## Motivation and Context

Provide a better response when downloading the bundles fails for
external causes

## How This Has Been Tested

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

(cherry picked from commit 2230b14)
sredxny added a commit that referenced this pull request Dec 13, 2022
…lugin bundles. (#4513) (#4531)

TT-7248 Added backoff algorithm to pull the plugin bundles.  (#4513)

<!-- Provide a general summary of your changes in the Title above -->

## Description

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described

[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

## Related Issue

https://tyktech.atlassian.net/browse/TT-7248

## Motivation and Context

Provide a better response when downloading the bundles fails for
external causes

## How This Has Been Tested

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

Co-authored-by: Sredny M <sredny.buitrago@gmail.com>
sredxny added a commit that referenced this pull request Dec 13, 2022
…gin bundles. (#4513) (#4529)

TT-7248 Added backoff algorithm to pull the plugin bundles.  (#4513)

<!-- Provide a general summary of your changes in the Title above -->

## Description

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described

[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

## Related Issue

https://tyktech.atlassian.net/browse/TT-7248

## Motivation and Context

Provide a better response when downloading the bundles fails for
external causes

## How This Has Been Tested

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

Co-authored-by: Sredny M <sredny.buitrago@gmail.com>
@sredxny
Copy link
Contributor Author

sredxny commented Dec 14, 2022

/release to release-4-lts

@tykbot
Copy link

tykbot bot commented Dec 14, 2022

Working on it! Note that it can take a few minutes.

tykbot bot pushed a commit that referenced this pull request Dec 14, 2022
<!-- Provide a general summary of your changes in the Title above -->

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described
[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

https://tyktech.atlassian.net/browse/TT-7248

Provide a better response when downloading the bundles fails for
external causes

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

(cherry picked from commit 2230b14)
@tykbot
Copy link

tykbot bot commented Dec 14, 2022

@sredxny Succesfully merged PR

sredxny added a commit that referenced this pull request Dec 14, 2022
… plugin bundles. (#4513) (#4537)

TT-7248 Added backoff algorithm to pull the plugin bundles.  (#4513)

<!-- Provide a general summary of your changes in the Title above -->

## Description

Currently if the gateway cannot pull a plugin bundle then it just throw
error and continue processing the next api definition. In this PR was
introduced a new behavior, the gateway will attempt to download the
bundle, of it fails then it will try until 4 more times, the timeframe
between one attempt and the other is defined by an exponential backoff
described

[here](https://pkg.go.dev/github.com/cenkalti/backoff#NewExponentialBackOff)

~~Now when an API will load a bundle, it's processed async so the
loading of the other apis is not blocked by this one.~~

## Related Issue

https://tyktech.atlassian.net/browse/TT-7248

## Motivation and Context

Provide a better response when downloading the bundles fails for
external causes

## How This Has Been Tested

- Added unit test for backoff algorithm
- in Dash+GW setup: created apis, one of them with bundle
plugin...finally check that all the apis are reachable

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

Co-authored-by: Sredny M <sredny.buitrago@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants