-
Notifications
You must be signed in to change notification settings - Fork 10
Connection test to service should retry on 429 and 503 #209
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
Open
tdewanNvidia
wants to merge
1
commit into
main
Choose a base branch
from
tdewan/connection_test_to_service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,10 +37,15 @@ class URLTestConfig(pydantic.BaseModel): | |
| method: str = pydantic.Field(default='GET', description='HTTP method to use') | ||
| timeout: int = pydantic.Field( | ||
| default=30, description='Timeout in seconds for the connection test') | ||
| expected_status_code: int = pydantic.Field( | ||
| default=200, description='Expected HTTP status code') | ||
| expected_status_code: Optional[int] = pydantic.Field( | ||
| default=None, description='Expected HTTP status code (None means any non-5xx is success)') | ||
| condition_name: Optional[str] = pydantic.Field( | ||
| default='ServiceConnectionTestFailure', description='Custom condition name for this URL') | ||
| retriable_status_codes: List[int] = pydantic.Field( | ||
| default=[429, 503], description='Status codes that should trigger retry') | ||
| failure_status_codes: List[int] = pydantic.Field( | ||
| default=[500, 501, 502, 504, 505, 506, 507, 508, 510, 511], | ||
| description='Status codes indicating actual service failure (5xx except retriable)') | ||
|
|
||
|
|
||
| class ConnectionTestConfig(test_base.NodeTestConfig): | ||
|
|
@@ -119,6 +124,13 @@ def _connection_test(self, url_config: URLTestConfig) -> test_base.NodeCondition | |
|
|
||
| Returns: | ||
| NodeCondition on success, None on failure (to trigger retry/backoff). | ||
|
|
||
| Status code handling: | ||
| - If expected_status_code is set, only that code is considered success | ||
| - If expected_status_code is None (default): | ||
| - Retriable codes (429, 503) trigger retry | ||
| - Failure codes (5xx except retriable) indicate service is down | ||
| - All other codes (2xx, 3xx, 4xx) indicate service is reachable | ||
| """ | ||
| try: | ||
| logging.info('Testing URL: %s', url_config.url) | ||
|
|
@@ -128,21 +140,50 @@ def _connection_test(self, url_config: URLTestConfig) -> test_base.NodeCondition | |
| timeout=url_config.timeout, | ||
| ) | ||
|
|
||
| if response.status_code != url_config.expected_status_code: | ||
| logging.error( | ||
| 'Unexpected status code from %s: %s != %s', | ||
| status_code = response.status_code | ||
|
|
||
| # If expected_status_code is explicitly set, use strict matching | ||
| if url_config.expected_status_code is not None: | ||
| if status_code != url_config.expected_status_code: | ||
| logging.error( | ||
| 'Unexpected status code from %s: %s != %s', | ||
| url_config.url, | ||
| status_code, | ||
| url_config.expected_status_code, | ||
| ) | ||
| return None | ||
| else: | ||
| # Check if status code is retriable (e.g., 429 rate limiting, 503 unavailable) | ||
| if status_code in url_config.retriable_status_codes: | ||
| logging.warning( | ||
| 'Retriable status code from %s: %s, will retry', | ||
| url_config.url, | ||
| status_code, | ||
| ) | ||
| return None | ||
|
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. How is the behavior different between this and failure_status_codes since they both return None. How do we differentiate between the two to retry with this one but not with the one below? |
||
|
|
||
| # Check if status code indicates actual service failure (5xx errors) | ||
| if status_code in url_config.failure_status_codes or status_code >= 500: | ||
| logging.error( | ||
| 'Service failure status code from %s: %s', | ||
| url_config.url, | ||
| status_code, | ||
| ) | ||
| return None | ||
|
|
||
| # Any other status code (2xx, 3xx, 4xx) means service is reachable | ||
| logging.info( | ||
| 'Service reachable at %s with status code %s', | ||
| url_config.url, | ||
| response.status_code, | ||
| url_config.expected_status_code, | ||
| status_code, | ||
| ) | ||
| return None | ||
|
|
||
| logging.info('URL test passed: %s (%s)', url_config.url, url_config.condition_name) | ||
| return test_base.NodeCondition( | ||
| type=url_config.condition_name or self.config.condition_name, | ||
| status='False', | ||
| reason='ServiceConnectionSuccess', | ||
| message=f'Connection test passed: {url_config.url}', | ||
| message=f'Connection test passed: {url_config.url} (status: {status_code})', | ||
| ) | ||
| except requests.RequestException as e: | ||
| logging.error('Connection test failed for %s: %s', url_config.url, str(e)) | ||
|
|
||
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.
Seems kind of odd that by default this is full of 500 status codes, but down below we have
This might as well default to an empty list if we always check all 500 status codes.