Skip to content

Commit

Permalink
Fix airflow connections (#3805)
Browse files Browse the repository at this point in the history
* Only reformat slack airflow connections

* Use the connection URI instead of host

* Add more helpful logs to slack utilities

* Add missing space

Co-authored-by: Madison Swain-Bowden <[email protected]>

---------

Co-authored-by: Madison Swain-Bowden <[email protected]>
  • Loading branch information
stacimc and AetherUnbound authored Feb 20, 2024
1 parent c14a9d7 commit 1cf6c6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 10 additions & 2 deletions catalog/dags/common/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,23 @@ def should_send_message(

# Exit early if this DAG is configured to skip Slack messaging
if should_silence_message(text, username, dag_id, task_id):
log.info(f"Skipping Slack notification for {dag_id}::{task_id}.")
log.info(f"Skipping silenced Slack notification for {dag_id}::{task_id}.")
return False

# Exit early if we aren't on production or if force alert is not set
environment = Variable.get("ENVIRONMENT", default_var="dev")
force_message = Variable.get(
"SLACK_MESSAGE_OVERRIDE", default_var=False, deserialize_json=True
)
return environment == "prod" or force_message
if not (environment == "prod" or force_message):
log.info(
f"Skipping Slack notification for {dag_id}:{task_id} in"
f" `{environment}` environment. To send the notification, enable"
" the `SLACK_MESSAGE_OVERRIDE` variable."
)
return False

return True


def send_message(
Expand Down
2 changes: 1 addition & 1 deletion catalog/dags/elasticsearch_cluster/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
@task
def get_es_host(environment: Environment) -> XComArg:
conn = Connection.get_connection_from_secrets(f"elasticsearch_http_{environment}")
return conn.host
return conn.get_uri()
7 changes: 4 additions & 3 deletions catalog/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function header() {
if [ "$1" == help ] || [ "$1" == --help ]; then help_text && exit 0; fi
sleep 0.1 # The $COLUMNS variable takes a moment to populate

# Reformat Airflow connections that use https
# Reformat Slack Airflow connections
header "MODIFYING ENVIRONMENT"
# Loop through environment variables, relying on naming conventions.
# Bash loops with pipes occur in a subprocess, so we need to do some special
Expand All @@ -57,7 +57,8 @@ while read -r var_string; do
echo " New Value: $new_value"
# set the environment variable
export "$var_name"="$new_value"
# only include airflow connections with http somewhere in the string
done < <(env | grep "^AIRFLOW_CONN[A-Z_]\+=http.*$")

# only include Slack airflow connections
done < <(env | grep "^AIRFLOW_CONN_SLACK*")

exec /entrypoint "$@"

0 comments on commit 1cf6c6a

Please sign in to comment.