Uh oh!
There was an error while loading. Please reload this page.
Add RdsDbSensor to amazon provider package - #26003
Conversation
| 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.
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.
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.
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.
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.
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.
| :dedent: 4 | ||
| :start-after: [START howto_sensor_rds_instance] | ||
| :end-before: [END howto_sensor_rds_instance] | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hankehly
commented
Aug 27, 2022
@o-nikolas@vincbeck@ferruzzi@potiuk |
ferruzzi
left a comment
There was a problem hiding this comment.
Left a couple comments; non-blocking.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ferruzzi
commented
Aug 30, 2022
My concerns have been addressed, thanks. LGTM |
hankehly
commented
Sep 1, 2022
@o-nikolas@vincbeck@ferruzzi@potiuk |
o-nikolas
commented
Sep 2, 2022
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.
Also, the return could be modified from map to the generator if you wish.
| returnbool(items) andany( | |
| map(lambdastatus: items[0][status_field].lower() ==status, self.target_statuses) | |
| ) | |
| returnbool(items) andany(items[0][status_field].lower() ==statusforstatusinself.target_statuses) |
For me, both variants are well readable but maybe this one is better. WDYT?
There was a problem hiding this comment.
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)
| 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": |
…ehly/airflow into issue-25952-add-rds-instance-sensor
hankehly
commented
Sep 6, 2022
@o-nikolas@ferruzzi@vincbeck@kazanzhy I left comments where the code changed. |
ferruzzi
left a comment
There was a problem hiding this comment.
LGTM, thanks for the updates.


Related: #25952
Summary
This PR adds the
RdsDbSensorto 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