-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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 RdsDbSensor to amazon provider package #26003
Add RdsDbSensor to amazon provider package #26003
Conversation
@@ -38,10 +38,10 @@ def __init__(self, *args, aws_conn_id: str = "aws_conn_id", hook_params: Optiona | |||
hook_params = hook_params or {} | |||
self.hook = RdsHook(aws_conn_id=aws_conn_id, **hook_params) | |||
self.target_statuses: List[str] = [] | |||
self.check_status_field = "Status" |
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.
Current sensors rely on the same botocore
response structure. The response to describe_db_instances
uses a different field name to describe the state of the requested resource. I chose to define the field name as an instance variable because..
- no need to update other sensor classes
- no need to modify method signatures
- minimal code changes
- no extra conditional statements
- it makes sense to define "sensor specific metadata" on the sensor class/instance
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 think this variable could be in _check_item
method.
Based on item_type
you could identify the status field
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.
You're right, but that requires adding an if-else
conditional statement. Is the current approach OK with you?
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 think it is OK to add one more if-else
.
Actually, I meant something like:
def _check_item(self, item_type: str, item_name: str) -> bool:
"""Get certain item from `_describe_item()` and check its status"""
if item_type == 'db_instance':
status_field = 'DBInstanceStatus'
else:
status_field = 'Status'
try:
items = self._describe_item(item_type, item_name)
except ClientError:
return False
else:
return bool(items) and any(
map(lambda status: items[0][status_field].lower() == status, self.target_statuses)
)
Seems only DBInstance
has this issue with the Status field.
WDYT?
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.
By adding if/else logic to the base class, we're making it "aware" of the details of the subclass. I think a better approach is to let the subclass tell us what it needs.
I checked the botocore
documentation and it looks like "DBInstanceStatus" and "Status" are the only 2 options, so I'll go ahead and make the change to finish up this PR.
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.
Changed in afefe36
:dedent: 4 | ||
:start-after: [START howto_sensor_rds_instance] | ||
:end-before: [END howto_sensor_rds_instance] | ||
|
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.
@o-nikolas @vincbeck @ferruzzi @potiuk |
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.
LGTM
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.
Left a couple comments; non-blocking.
My concerns have been addressed, thanks. LGTM |
@o-nikolas @vincbeck @ferruzzi @potiuk |
Unfortunately none of us tagged above have the powers to merge code except for @potiuk |
return bool(items) and any( | ||
map(lambda status: items[0][status_field].lower() == status, self.target_statuses) | ||
) |
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.
Also, the return
could be modified from map
to the generator if you wish.
return bool(items) and any( | |
map(lambda status: items[0][status_field].lower() == status, self.target_statuses) | |
) | |
return bool(items) and any(items[0][status_field].lower() == status for status in self.target_statuses) |
For me, both variants are well readable but maybe this one is better. WDYT?
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.
Thanks for the suggestions. I'd like to make these updates in a separate PR.
The formatting is the result of black (line too long)
else: | ||
raise AirflowException(f"Method for {item_type} is not implemented") | ||
|
||
def _check_item(self, item_type: str, item_name: str) -> bool: | ||
"""Get certain item from `_describe_item()` and check its status""" | ||
if item_type == "db_instance": |
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.
Update 2022/09/06
#26003 (comment)
…ehly/airflow into issue-25952-add-rds-instance-sensor
@o-nikolas @ferruzzi @vincbeck @kazanzhy I left comments where the code changed. |
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.
LGTM, thanks for the updates.
Related: #25952
Summary
This PR adds the
RdsDbSensor
to the amazon provider package. It waits for an RDS instance or cluster to reach one (or more) of the DB instance states described here.Todo
RdsDbSensor