You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Lee-W (via GitHub)" <gi...@apache.org> on 2023/12/25 10:20:58 UTC
[PR] Check cluster state before defer to triggerer [airflow]
Lee-W opened a new pull request, #36416:
URL: https://github.com/apache/airflow/pull/36416
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #36416:
URL: https://github.com/apache/airflow/pull/36416#discussion_r1437323931
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -624,25 +637,36 @@ def execute(self, context: Context):
else:
raise error
if self.deferrable:
- self.defer(
- trigger=RedshiftPauseClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- )
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "paused":
+ self.log.info("Paused cluster successfully")
+ elif cluster_state == "deleting":
+ raise AirflowException(
+ f"Unable to pause cluster since cluster is currently in status: {cluster_state}"
+ )
+ else:
Review Comment:
same above
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -714,26 +738,41 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise
+
if self.deferrable:
- self.defer(
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- trigger=RedshiftDeleteClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- )
+ cluster_state = self.redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "cluster_not_found":
+ self.log.info("Cluster deleted successfully")
+ elif cluster_state in ("creating", "modifying"):
+ raise AirflowException(
+ f"Unable to delete cluster since cluster is currently in status: {cluster_state}"
+ )
+ else:
Review Comment:
same above
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -535,19 +535,29 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise error
+
if self.deferrable:
- self.defer(
- trigger=RedshiftResumeClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- )
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "available":
+ self.log.info("Resumed cluster successfully")
+ elif cluster_state == "deleting":
+ raise AirflowException(
+ "Unable to resume cluster since cluster is currently in status: %s", cluster_state
+ )
+ else:
Review Comment:
I think that's something done in https://github.com/apache/airflow/blob/d1e50b48bf57c2c3cffd14cc92ce1f0ecf284a03/airflow/providers/amazon/aws/operators/redshift_cluster.py#L526. What we should do here is not to check whether it's **resumable**, but whether it's finished and that's basically what we do in the waiter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #36416:
URL: https://github.com/apache/airflow/pull/36416
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "pankajkoti (via GitHub)" <gi...@apache.org>.
pankajkoti commented on code in PR #36416:
URL: https://github.com/apache/airflow/pull/36416#discussion_r1436423823
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -714,26 +738,41 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise
+
if self.deferrable:
- self.defer(
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- trigger=RedshiftDeleteClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- )
+ cluster_state = self.redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "cluster_not_found":
+ self.log.info("Cluster deleted successfully")
+ elif cluster_state in ("creating", "modifying"):
+ raise AirflowException(
+ f"Unable to delete cluster since cluster is currently in status: {cluster_state}"
+ )
+ else:
Review Comment:
similar comment as above. The else clause could be a broader else to raise an exception for all other states.
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -535,19 +535,29 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise error
+
if self.deferrable:
- self.defer(
- trigger=RedshiftResumeClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- )
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "available":
+ self.log.info("Resumed cluster successfully")
+ elif cluster_state == "deleting":
+ raise AirflowException(
+ "Unable to resume cluster since cluster is currently in status: %s", cluster_state
+ )
+ else:
Review Comment:
Since there are so many cluster states possible as per https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html#rs-mgmt-cluster-status, we should explicitly have an elif check here (probably on `paused`) to check the cluster is in resumable state and have a broader else clause to raise an exception instead
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -624,25 +637,36 @@ def execute(self, context: Context):
else:
raise error
if self.deferrable:
- self.defer(
- trigger=RedshiftPauseClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- )
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "paused":
+ self.log.info("Paused cluster successfully")
+ elif cluster_state == "deleting":
+ raise AirflowException(
+ f"Unable to pause cluster since cluster is currently in status: {cluster_state}"
+ )
+ else:
Review Comment:
similar comment as above. The else clause could be a broader else to raise an exception for all other states.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #36416:
URL: https://github.com/apache/airflow/pull/36416#issuecomment-1874797410
> Same comment as #36523, I am not sure we want to do that
Replied in https://github.com/apache/airflow/pull/36523#issuecomment-1874715083
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "pankajkoti (via GitHub)" <gi...@apache.org>.
pankajkoti commented on code in PR #36416:
URL: https://github.com/apache/airflow/pull/36416#discussion_r1436303356
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -535,19 +535,27 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise error
+
if self.deferrable:
- self.defer(
- trigger=RedshiftResumeClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "paused":
+ self.defer(
+ trigger=RedshiftResumeClusterTrigger(
+ cluster_identifier=self.cluster_identifier,
+ waiter_delay=self.poll_interval,
+ waiter_max_attempts=self.max_attempts,
+ aws_conn_id=self.aws_conn_id,
+ ),
+ method_name="execute_complete",
+ # timeout is set to ensure that if a trigger dies, the timeout does not restart
+ # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
+ timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
+ )
+
+ self.log.warning(
Review Comment:
Should we raise an exception here instead? The user is intending to resume cluster but if the state is not what the user is expecting to be shouldn't we alert the user? Otherwise, this would silently succeed.
I see we're raising an AirflowException in the RedshiftDeleteClusterOperator when the state is not as expected.
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -624,25 +635,34 @@ def execute(self, context: Context):
else:
raise error
if self.deferrable:
- self.defer(
- trigger=RedshiftPauseClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "available":
+ self.defer(
+ trigger=RedshiftPauseClusterTrigger(
+ cluster_identifier=self.cluster_identifier,
+ waiter_delay=self.poll_interval,
+ waiter_max_attempts=self.max_attempts,
+ aws_conn_id=self.aws_conn_id,
+ ),
+ method_name="execute_complete",
+ # timeout is set to ensure that if a trigger dies, the timeout does not restart
+ # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
+ timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
+ )
+
+ self.log.warning(
Review Comment:
Same question here about raising an exception.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on PR #36416:
URL: https://github.com/apache/airflow/pull/36416#issuecomment-1874432619
Same comment as #36523, I am not sure we want to do that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #36416:
URL: https://github.com/apache/airflow/pull/36416#issuecomment-1879521457
@pankajkoti Please let me know if there's any other concern on this PR when you're available. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #36416:
URL: https://github.com/apache/airflow/pull/36416#discussion_r1436405148
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -535,19 +535,27 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise error
+
if self.deferrable:
- self.defer(
- trigger=RedshiftResumeClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "paused":
+ self.defer(
+ trigger=RedshiftResumeClusterTrigger(
+ cluster_identifier=self.cluster_identifier,
+ waiter_delay=self.poll_interval,
+ waiter_max_attempts=self.max_attempts,
+ aws_conn_id=self.aws_conn_id,
+ ),
+ method_name="execute_complete",
+ # timeout is set to ensure that if a trigger dies, the timeout does not restart
+ # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
+ timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
+ )
+
+ self.log.warning(
Review Comment:
Yep, we should do something similar. I revised this logic a bit to keep it in sync with the waiters in my latest change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Check redshift cluster state before deferring to triggerer [airflow]
Posted by "pankajkoti (via GitHub)" <gi...@apache.org>.
pankajkoti commented on code in PR #36416:
URL: https://github.com/apache/airflow/pull/36416#discussion_r1436423521
##########
airflow/providers/amazon/aws/operators/redshift_cluster.py:
##########
@@ -535,19 +535,29 @@ def execute(self, context: Context):
time.sleep(self._attempt_interval)
else:
raise error
+
if self.deferrable:
- self.defer(
- trigger=RedshiftResumeClusterTrigger(
- cluster_identifier=self.cluster_identifier,
- waiter_delay=self.poll_interval,
- waiter_max_attempts=self.max_attempts,
- aws_conn_id=self.aws_conn_id,
- ),
- method_name="execute_complete",
- # timeout is set to ensure that if a trigger dies, the timeout does not restart
- # 60 seconds is added to allow the trigger to exit gracefully (i.e. yield TriggerEvent)
- timeout=timedelta(seconds=self.max_attempts * self.poll_interval + 60),
- )
+ cluster_state = redshift_hook.cluster_status(cluster_identifier=self.cluster_identifier)
+ if cluster_state == "available":
+ self.log.info("Resumed cluster successfully")
+ elif cluster_state == "deleting":
+ raise AirflowException(
+ "Unable to resume cluster since cluster is currently in status: %s", cluster_state
+ )
+ else:
Review Comment:
Since there are so many cluster states possible as per https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html#rs-mgmt-cluster-status, I think we could explicitly have an elif check here (probably on `paused`) to check the cluster is in resumable state and have a broader else clause to raise an exception instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org