Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Standardize Airflow Variable names to uppercase (#801)
Davidb13390fda17e
diff --git a/DAGs.md b/DAGs.mdindex e369f82a0..929f72188 100644--- a/DAGs.md+++ b/DAGs.md@@ -199,13 +199,13 @@ Checks for DAGs that have silenced Slack alerts which may need to be turned backon.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 dictionarywhere thekey is the `dag_id` of the affected DAG, and the value is a list ofSilencedSlackNotifications (which map silenced notifications to GitHub URLs) for thatDAG.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 GitHubissues are still open. If an issue has been closed, it is assumed that the DAG shouldhave Slack reporting reenabled, and an alert is sent to prompt manual update of theconfiguration. This prevents developers from forgetting to reenable Slack reportingdiff --git a/openverse_catalog/dags/common/slack.py b/openverse_catalog/dags/common/slack.pyindex 8a3544cc8..664783858 100644--- a/openverse_catalog/dags/common/slack.py+++ b/openverse_catalog/dags/common/slack.py@@ -12,7 +12,7 @@ More information can be found here: https://app.slack.com/block-kit-builder.Messages or alerts sent using `send_message` or `on_failure_callback` will onlysend 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@@ -230,7 +230,7 @@ class SlackMessage: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 messageshould be silenced for this DAG."""# Match on message text and username@@ -238,7 +238,7 @@ def should_silence_message(text, username, dag_id):# Get the configuration for silenced messages for this DAGsilenced_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(@@ -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@@ -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,diff --git a/openverse_catalog/dags/maintenance/check_silenced_dags.py b/openverse_catalog/dags/maintenance/check_silenced_dags.pyindex 60fab330a..dc1b6aa33 100644--- a/openverse_catalog/dags/maintenance/check_silenced_dags.py+++ b/openverse_catalog/dags/maintenance/check_silenced_dags.py@@ -3,13 +3,13 @@ Checks for DAGs that have silenced Slack alerts which may need to be turned backon.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 dictionarywhere thekey is the `dag_id` of the affected DAG, and the value is a list ofSilencedSlackNotifications (which map silenced notifications to GitHub URLs) for thatDAG.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 GitHubissues are still open. If an issue has been closed, it is assumed that the DAG shouldhave Slack reporting reenabled, and an alert is sent to prompt manual update of theconfiguration. This prevents developers from forgetting to reenable Slack reporting@@ -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)diff --git a/openverse_catalog/dags/providers/provider_api_scripts/provider_data_ingester.py b/openverse_catalog/dags/providers/provider_api_scripts/provider_data_ingester.pyindex 65bcb9c0e..6992665df 100644--- a/openverse_catalog/dags/providers/provider_api_scripts/provider_data_ingester.py+++ b/openverse_catalog/dags/providers/provider_api_scripts/provider_data_ingester.py@@ -93,7 +93,7 @@ class ProviderDataIngester(ABC):# 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 notdiff --git a/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py b/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.pyindex d73c9f289..68b5345ef 100644--- a/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py+++ b/openverse_catalog/dags/providers/provider_api_scripts/wikimedia_commons.py@@ -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 = 250diff --git a/tests/dags/common/test_slack.py b/tests/dags/common/test_slack.pyindex 8b0c91879..757ea5cdc 100644--- a/tests/dags/common/test_slack.py+++ b/tests/dags/common/test_slack.py@@ -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