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

feat: add backoff mechanism with logging #8

Open
wants to merge 4 commits into
base: release/holocron
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dbt/adapters/glue/gluedbapi/commons.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from waiter import wait
from dbt.events import AdapterLogger

logger = AdapterLogger("Glue")

import backoff
from botocore.exceptions import ClientError, EndpointConnectionError
from datetime import datetime

class GlueStatement:
WAITING = "WAITING"
Expand Down Expand Up @@ -29,6 +36,17 @@ def _get_statement(self):
Id=self._statement_id
)

def log_backoff(details):
logger.info(f"Timestamp: {datetime.now().isoformat()}, Backing off: {details['wait']} seconds, Tries: {details['tries']}, Elapsed: {details['elapsed']} seconds")


@backoff.on_exception(
backoff.expo,
(ClientError, EndpointConnectionError),
max_tries=5,
jitter=backoff.full_jitter,
on_backoff=log_backoff
)
def execute(self):
self._run_statement()
for elasped in wait(1):
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/glue/gluedbapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GlueSessionState:
@dataclass
class GlueConnection:
_boto3_client_lock = threading.Lock()
_create_session_config = None
_create_session_config = {}

def __init__(self, credentials: GlueCredentials, session_id_suffix: str = None, session_config_overrides = {}):
self.credentials = credentials
Expand Down Expand Up @@ -148,7 +148,7 @@ def session_id(self):
def client(self):
config = Config(
retries={
'max_attempts': 50,
'max_attempts': 10,
'mode': 'adaptive'
}
)
Expand Down
3 changes: 2 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pytest-csv
flaky
dbt-tests-adapter==1.5.2
mypy==1.4.1
black==23.3.0
black==23.3.0
backoff==2.2.1