-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Retry backoff upstream #43787
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
Merged
kamalq97
merged 5 commits into
demisto:contrib/cyble-dev_Retry_backoff_upstream
from
cyble-dev:Retry_backoff_upstream
Apr 20, 2026
+161
−28
Merged
Retry backoff upstream #43787
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fb4f12c
added retry at 5,10,20,20,20 secs
cyble-dev 8a64663
CybleEventsV2: bump pack to 1.1.7 and add release notes for fetch ret…
cyble-dev 0fcf884
CybleEventsV2: limit changes to fetch-incidents API retry backoff
cyble-dev 2a09f57
fix(CybleEventsV2): resolve RET503 and add Client retry tests for cov…
cyble-dev c5e8e67
fix(CybleEventsV2): address PR review for retries, tests, and release…
cyble-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| set_request, | ||
| DEFAULT_TAKE_LIMIT, | ||
| ensure_aware, | ||
| FETCH_INCIDENT_RETRY_BACKOFF_SECONDS, | ||
| ) | ||
| from CommonServerPython import GetModifiedRemoteDataResponse | ||
| from CybleEventsV2 import check_response | ||
|
|
@@ -1731,6 +1732,98 @@ def test_get_data_success(self, mock_demisto, mock_get_alert_payload): | |
| mock_make_request.assert_called_once_with(self.test_url, self.test_api_key, "POST", json.dumps({"dummy": "payload"})) | ||
| assert mock_demisto.debug.called | ||
|
|
||
| @patch("CybleEventsV2.get_alert_payload", return_value={"dummy": "payload"}) | ||
| def test_get_data_raises_when_missing_url_or_api_key(self, _mock_get_alert_payload): | ||
| with pytest.raises(ValueError, match="Missing required URL or API key"): | ||
| self.client.get_data(self.test_service, {"api_key": self.test_api_key}) | ||
| with pytest.raises(ValueError, match="Missing required URL or API key"): | ||
| self.client.get_data(self.test_service, {"url": self.test_url}) | ||
|
|
||
| @patch("CybleEventsV2.get_alert_payload", return_value={"dummy": "payload"}) | ||
| @patch("CybleEventsV2.demisto") | ||
| def test_get_data_retries_on_non_200_then_success(self, mock_demisto, _mock_get_alert_payload): | ||
| input_params = {"url": self.test_url, "api_key": self.test_api_key} | ||
| fail_resp = Mock() | ||
| fail_resp.status_code = 503 | ||
| fail_resp.text = "unavailable" | ||
| ok_resp = Mock() | ||
| ok_resp.status_code = 200 | ||
| ok_resp.json.return_value = {"recovered": True} | ||
|
|
||
| with ( | ||
| patch.object(self.client, "make_request", side_effect=[fail_resp, ok_resp]) as mock_make, | ||
| patch("CybleEventsV2.time.sleep") as mock_sleep, | ||
| ): | ||
| result = self.client.get_data(self.test_service, input_params) | ||
|
|
||
| assert result == {"recovered": True} | ||
| assert mock_make.call_count == 2 | ||
| mock_sleep.assert_called() | ||
|
|
||
| @patch("CybleEventsV2.get_alert_payload", return_value={"dummy": "payload"}) | ||
| @patch("CybleEventsV2.demisto") | ||
| def test_get_data_retries_on_invalid_json_then_success(self, mock_demisto, _mock_get_alert_payload): | ||
| input_params = {"url": self.test_url, "api_key": self.test_api_key} | ||
| bad_json = Mock() | ||
| bad_json.status_code = 200 | ||
| bad_json.json.side_effect = ValueError("not json") | ||
| good_json = Mock() | ||
| good_json.status_code = 200 | ||
| good_json.json.return_value = {"parsed": True} | ||
|
|
||
| with ( | ||
| patch.object(self.client, "make_request", side_effect=[bad_json, good_json]), | ||
| patch("CybleEventsV2.time.sleep") as mock_sleep, | ||
| ): | ||
| result = self.client.get_data(self.test_service, input_params) | ||
|
|
||
| assert result == {"parsed": True} | ||
| mock_sleep.assert_called_once() | ||
| assert mock_sleep.call_args[0][0] == FETCH_INCIDENT_RETRY_BACKOFF_SECONDS[0] | ||
|
|
||
| @patch("CybleEventsV2.demisto") | ||
| def test_get_all_services_retries_on_request_error_then_success(self, mock_demisto): | ||
| fail_resp = Mock() | ||
| fail_resp.status_code = 200 | ||
| fail_resp.json.return_value = {"data": ["a"]} | ||
| with ( | ||
| patch.object(self.client, "make_request", side_effect=[ConnectionError("reset"), fail_resp]), | ||
| patch("CybleEventsV2.time.sleep") as mock_sleep, | ||
| ): | ||
| result = self.client.get_all_services(self.test_api_key, self.test_url) | ||
| assert result == ["a"] | ||
| mock_sleep.assert_called() | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a test case that exhausts all retries to ensure the final exception is raised correctly. |
||
| @patch("CybleEventsV2.demisto") | ||
| def test_get_all_services_exhausts_retries_raises(self, mock_demisto): | ||
| """After 1 initial try + len(backoffs) retries, the last request error is raised.""" | ||
| attempts = len(FETCH_INCIDENT_RETRY_BACKOFF_SECONDS) + 1 | ||
| with ( | ||
| patch.object(self.client, "make_request", side_effect=[ConnectionError("reset")] * attempts), | ||
| patch("CybleEventsV2.time.sleep") as mock_sleep, | ||
| pytest.raises(Exception, match="Failed to get services: reset"), | ||
| ): | ||
| self.client.get_all_services(self.test_api_key, self.test_url) | ||
|
|
||
| assert mock_sleep.call_count == len(FETCH_INCIDENT_RETRY_BACKOFF_SECONDS) | ||
|
|
||
| @patch("CybleEventsV2.demisto") | ||
| def test_get_all_services_wrong_format_raises_without_backoff(self, mock_demisto): | ||
| """Wrong response shape after 200 + valid JSON must not use retry backoff.""" | ||
| mock_response = Mock() | ||
| mock_response.status_code = 200 | ||
| mock_response.json.return_value = {"wrong_key": []} | ||
|
|
||
| with ( | ||
| patch.object(self.client, "make_request", return_value=mock_response) as mock_make, | ||
| patch("CybleEventsV2.time.sleep") as mock_sleep, | ||
| pytest.raises(Exception, match="Failed to get services: Wrong Format for services response"), | ||
| ): | ||
| self.client.get_all_services(self.test_api_key, self.test_url) | ||
|
|
||
| mock_make.assert_called_once() | ||
| mock_sleep.assert_not_called() | ||
|
|
||
| def test_insert_data_in_cortex_successful_processing(self): | ||
| test_input_params = {"limit": "10", "hce": False} | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #### Integrations | ||
|
|
||
| ##### CybleEvents v2 | ||
|
|
||
| - Improved implementation of `fetch-incidents` by adding retry with backoff when calls to the services or alerts API fail (initial attempt plus retries with delays of 5, 10, 20, 20, and 20 seconds). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
Verify that the retry backoff was triggered.