Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Standardize Airflow Variable names to uppercase #801

Merged
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
4 changes: 2 additions & 2 deletions DAGs.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ Checks for DAGs that have silenced Slack alerts which may need to be turned back
on.

When a DAG has known failures, it can be ommitted from Slack error reporting by adding
an entry to the `silenced_slack_notifications` Airflow variable. This is a dictionary
an entry to the `SILENCED_SLACK_NOTIFICATIONS` Airflow variable. This is a dictionary
where thekey is the `dag_id` of the affected DAG, and the value is a list of
SilencedSlackNotifications (which map silenced notifications to GitHub URLs) for that
DAG.

The `check_silenced_dags` DAG iterates over the entries in the
`silenced_slack_notifications` configuration and verifies that the associated GitHub
`SILENCED_SLACK_NOTIFICATIONS` configuration and verifies that the associated GitHub
issues are still open. If an issue has been closed, it is assumed that the DAG should
have Slack reporting reenabled, and an alert is sent to prompt manual update of the
configuration. This prevents developers from forgetting to reenable Slack reporting
Expand Down
12 changes: 6 additions & 6 deletions openverse_catalog/dags/common/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

Messages or alerts sent using `send_message` or `on_failure_callback` will only
send if a Slack connection is defined and we are running in production. You can
manually override this for testing purposes by setting the `slack_message_override`
manually override this for testing purposes by setting the `SLACK_MESSAGE_OVERRIDE`
variable to `true` in the Airflow UI.

## Send multiple messages - payload is reset after sending
Expand Down Expand Up @@ -230,15 +230,15 @@ def send(self, notification_text: str = "Airflow notification") -> Response:

def should_silence_message(text, username, dag_id):
"""
Checks the `silenced_slack_notifications` Airflow variable to see if the message
Checks the `SILENCED_SLACK_NOTIFICATIONS` Airflow variable to see if the message
should be silenced for this DAG.
"""
# Match on message text and username
message = username + text

# Get the configuration for silenced messages for this DAG
silenced_notifications: list[SilencedSlackNotification] = Variable.get(
"silenced_slack_notifications", default_var={}, deserialize_json=True
"SILENCED_SLACK_NOTIFICATIONS", default_var={}, deserialize_json=True
).get(dag_id, [])

return bool(silenced_notifications) and any(
Expand Down Expand Up @@ -269,9 +269,9 @@ def should_send_message(
return False

# Exit early if we aren't on production or if force alert is not set
environment = Variable.get("environment", default_var="dev")
environment = Variable.get("ENVIRONMENT", default_var="dev")
force_message = Variable.get(
"slack_message_override", default_var=False, deserialize_json=True
"SLACK_MESSAGE_OVERRIDE", default_var=False, deserialize_json=True
)
return environment == "prod" or force_message

Expand All @@ -291,7 +291,7 @@ def send_message(
if not should_send_message(text, username, dag_id, http_conn_id):
return

environment = Variable.get("environment", default_var="dev")
environment = Variable.get("ENVIRONMENT", default_var="dev")
s = SlackMessage(
f"{username} | {environment}",
icon_emoji,
Expand Down
6 changes: 3 additions & 3 deletions openverse_catalog/dags/maintenance/check_silenced_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
on.

When a DAG has known failures, it can be ommitted from Slack error reporting by adding
an entry to the `silenced_slack_notifications` Airflow variable. This is a dictionary
an entry to the `SILENCED_SLACK_NOTIFICATIONS` Airflow variable. This is a dictionary
where thekey is the `dag_id` of the affected DAG, and the value is a list of
SilencedSlackNotifications (which map silenced notifications to GitHub URLs) for that
DAG.

The `check_silenced_dags` DAG iterates over the entries in the
`silenced_slack_notifications` configuration and verifies that the associated GitHub
`SILENCED_SLACK_NOTIFICATIONS` configuration and verifies that the associated GitHub
issues are still open. If an issue has been closed, it is assumed that the DAG should
have Slack reporting reenabled, and an alert is sent to prompt manual update of the
configuration. This prevents developers from forgetting to reenable Slack reporting
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_dags_with_closed_issues(

def check_configuration(github_pat: str):
silenced_dags = Variable.get(
"silenced_slack_notifications", default_var={}, deserialize_json=True
"SILENCED_SLACK_NOTIFICATIONS", default_var={}, deserialize_json=True
)
dags_to_reenable = get_dags_with_closed_issues(github_pat, silenced_dags)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, conf: dict = None, date: str = None):
# processes some data but still returns quickly.
# When set to 0, no limit is imposed.
self.limit = Variable.get(
"ingestion_limit", deserialize_json=True, default_var=0
"INGESTION_LIMIT", deserialize_json=True, default_var=0
)

# If a test limit is imposed, ensure that the `batch_limit` does not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WikimediaCommonsDataIngester(ProviderDataIngester):

# The batch_limit applies to the number of pages received by the API, rather
# than the number of individual records. This means that for Wikimedia Commons
# setting a global `ingestion_limit` will still limit the number of records, but
# setting a global `INGESTION_LIMIT` will still limit the number of records, but
# the exact limit may not be respected.
batch_limit = 250

Expand Down
6 changes: 3 additions & 3 deletions tests/dags/common/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ def test_on_failure_callback(
"dag": mock.Mock(),
}
env_vars = {
"environment": environment,
"slack_message_override": slack_message_override,
"silenced_slack_notifications": {},
"ENVIRONMENT": environment,
"SLACK_MESSAGE_OVERRIDE": slack_message_override,
"SILENCED_SLACK_NOTIFICATIONS": {},
}

# Mock env variables
Expand Down