-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Add glue session integrations (hook and operators) #38830
Add glue session integrations (hook and operators) #38830
Conversation
else: | ||
self.num_of_dpus = num_of_dpus | ||
|
||
kwargs["client_type"] = "glue" |
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.
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.
We have set a strange precedent here, if they're using the same client then the same hook class could cover them all. Or at least put them all in the same module?
But also we have the precedent now, so I'm not opposed to just following it again here.
session_id: str | None = None, | ||
desc: str | None = None, | ||
iam_role_name: str | None = None, | ||
iam_role_arn: str | None = None, | ||
num_of_dpus: int | None = None, | ||
create_session_kwargs: dict | None = None, | ||
session_poll_interval: int | float = 6, | ||
*args, | ||
**kwargs, |
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.
Are this parameters required into the constructor? And could be this hook are thin wrapper? And provide and validate parameters into the specific hook methods?
"""Process Glue Session state while polling; used by both sync and async methods.""" | ||
failed_states = ["FAILED", "STOPPED", "TIMEOUT"] | ||
ready_state = "READY" | ||
|
||
if state is ready_state: | ||
self.log.info("Session %s State: %s", session_id, state) | ||
return {"SessionState": state} | ||
if state in failed_states: | ||
session_error_message = f"Exiting Session {session_id} State: {state}" | ||
self.log.info(session_error_message) | ||
raise AirflowException(session_error_message) | ||
else: | ||
self.log.info( | ||
"Polling for AWS Glue Session %s current run state with status %s", | ||
session_id, | ||
state, | ||
) | ||
return None |
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.
Could this implemented as a botocore waiter?
from airflow.utils.context import Context | ||
|
||
|
||
class GlueCreateSessionOperator(BaseOperator): |
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.
Please consider to use airflow.providers.amazon.aws.operators.base_aws.AwsBaseOperator
Some examples:
- https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/operators/appflow.py
- https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/operators/athena.py
- https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/operators/bedrock.py
Issue for the reference: #35278
"iam_role_name", | ||
"iam_role_arn", | ||
) | ||
template_ext: Sequence[str] = () |
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.
template_ext: Sequence[str] = () |
|
||
operator_extra_links = () |
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.
operator_extra_links = () |
self.deferrable = deferrable | ||
|
||
@cached_property | ||
def glue_session_hook(self) -> GlueSessionHook: |
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.
The common name for the hooks in AWS operators/sensors is hook
def glue_session_hook(self) -> GlueSessionHook: | |
def hook(self) -> GlueSessionHook: |
If you use AwsBaseOperator
this will define automatically
def __init__( | ||
self, | ||
session_id: str, | ||
aws_conn_id: str | None, |
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.
There is also common hook settings exists: region_name
, verify
and botocore_config
?
hook = GlueSessionHook(aws_conn_id=self.aws_conn_id, session_poll_interval=self.session_poll_interval) | ||
await hook.async_session_readiness(self.session_id) | ||
yield TriggerEvent({"status": "ready", "message": "Session ready", "value": self.session_id}) |
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.
I guess in case of the error this trigger do not yield anything
4620399
to
787a8cf
Compare
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.
Would you be interested in adding/updating system tests for this? You can see inspiration in tests/system/providers/amazon/aws/
def __init__( | ||
self, | ||
*, | ||
session_id: str = "aws_glue_default_session", |
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.
I don't know much about glue sessions, should this be a unique uuid generated for each invocation of the operator?
else: | ||
self.num_of_dpus = num_of_dpus | ||
|
||
kwargs["client_type"] = "glue" |
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.
We have set a strange precedent here, if they're using the same client then the same hook class could cover them all. Or at least put them all in the same module?
But also we have the precedent now, so I'm not opposed to just following it again here.
elif worker_type_exists and not num_workers_exists: | ||
raise ValueError("Need to specify NumberOfWorkers when specifying custom WorkerType") | ||
elif num_of_dpus is None: | ||
self.num_of_dpus: int | float = 10 |
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.
Is this a common default? If not it might be work mentioning it in the :param: doc string for num_of_dpus
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.
This is the default value of the resource in aws
iam_role_arn: str | None = None, | ||
num_of_dpus: int | None = None, | ||
create_session_kwargs: dict | None = None, | ||
wait_for_readiness: bool = True, |
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.
We usually call this wait_for_completion
Also can you document this in the doc string?
787a8cf
to
54d4298
Compare
@mathiaHT are you still working on this PR? |
Hello, yes I will need these features at some point. But I currently have other priorities |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
GlueCreateSessionOperator and GlueDeleteSessionOperator to handle glue session in a dag. I tried to stick as much as possible to the GlueJobOperator implementation
When using dbt-glue, we need to handle when and how the session is created in order to customize it for specific jobs or task group