Bird
Raised Fist0
Apache Airflowdevops~20 mins

Integration with PagerDuty and Slack in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PagerDuty and Slack Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Airflow task notifying PagerDuty
Given this Airflow PythonOperator task code snippet that triggers a PagerDuty incident notification, what will be the output in the Airflow logs if the PagerDuty API key is invalid?
Apache Airflow
def notify_pagerduty():
    import requests
    url = 'https://events.pagerduty.com/v2/enqueue'
    payload = {
        "routing_key": "INVALID_API_KEY",
        "event_action": "trigger",
        "payload": {
            "summary": "Test incident",
            "source": "airflow",
            "severity": "error"
        }
    }
    response = requests.post(url, json=payload)
    print(response.status_code)
    print(response.json())
A
400
{'status': 'error', 'message': 'Invalid routing key', 'errors': ['Routing key is invalid']}
B
200
{'status': 'success', 'message': 'Event processed', 'dedup_key': 'abc123'}
C
500
{'status': 'error', 'message': 'Internal server error'}
D
401
{'status': 'error', 'message': 'Unauthorized', 'errors': ['Invalid API key']}
Attempts:
2 left
💡 Hint
Think about what HTTP status code PagerDuty returns for invalid keys.
❓ Configuration
intermediate
1:30remaining
Correct Slack webhook URL format in Airflow Variable
Which of the following is the correct format to store a Slack Incoming Webhook URL in an Airflow Variable for use in a Slack notification task?
Aslack://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Bhooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Chttp://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Dhttps://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
Attempts:
2 left
💡 Hint
Slack webhooks use HTTPS URLs starting with https://
🔀 Workflow
advanced
2:30remaining
Order of steps to integrate Airflow with PagerDuty and Slack
Arrange the steps in the correct order to integrate Airflow with PagerDuty and Slack for alert notifications.
A1,2,3,4
B2,1,3,4
C3,1,2,4
D1,3,2,4
Attempts:
2 left
💡 Hint
Think about what credentials you need before storing and using them.
❓ Troubleshoot
advanced
2:00remaining
Identifying cause of Slack notification failure in Airflow
An Airflow task that sends Slack notifications fails with this error: "requests.exceptions.ConnectionError: HTTPSConnectionPool(host='hooks.slack.com', port=443): Max retries exceeded". What is the most likely cause?
AThe Slack webhook URL is incorrect or malformed
BThe Slack API token has expired
CThe Airflow worker has no internet access or network issues
DThe Airflow DAG code has a syntax error
Attempts:
2 left
💡 Hint
Connection errors usually relate to network problems.
✅ Best Practice
expert
3:00remaining
Best practice for secure storage of PagerDuty and Slack credentials in Airflow
Which is the best practice for securely managing PagerDuty routing keys and Slack webhook URLs in Airflow for production use?
AStore keys in environment variables on Airflow workers only
BUse Airflow's built-in Secret Backend to store and retrieve keys securely
CStore keys as plain text in Airflow Variables with no encryption
DHardcode keys directly in DAG Python code for easy access
Attempts:
2 left
💡 Hint
Think about how to keep secrets safe and avoid exposure in code or UI.

Practice

(1/5)
1. What is the main purpose of integrating Airflow with PagerDuty and Slack?
easy
A. To store Airflow logs in PagerDuty and Slack
B. To schedule Airflow DAGs automatically
C. To replace Airflow's scheduler with PagerDuty
D. To receive fast alerts and notifications about workflow issues

Solution

  1. Step 1: Understand the role of PagerDuty and Slack in Airflow

    PagerDuty and Slack are used to send alerts and notifications when Airflow workflows have issues or important events.
  2. Step 2: Identify the main benefit of integration

    The integration helps teams respond quickly by notifying them immediately about failures or important status updates.
  3. Final Answer:

    To receive fast alerts and notifications about workflow issues -> Option D
  4. Quick Check:

    Alerts and notifications = C [OK]
Hint: Think: Why notify teams fast? Alerts! [OK]
Common Mistakes:
  • Confusing scheduling with alerting
  • Thinking logs are stored in PagerDuty or Slack
  • Assuming PagerDuty replaces Airflow scheduler
2. Which Airflow operator is used to send alerts to PagerDuty within a DAG?
easy
A. PagerDutyIncidentOperator
B. SlackAPIPostOperator
C. EmailOperator
D. HttpSensor

Solution

  1. Step 1: Identify operators for PagerDuty and Slack

    SlackAPIPostOperator sends messages to Slack, PagerDutyIncidentOperator sends incidents to PagerDuty.
  2. Step 2: Match operator to PagerDuty alerts

    PagerDutyIncidentOperator is designed specifically for PagerDuty integration.
  3. Final Answer:

    PagerDutyIncidentOperator -> Option A
  4. Quick Check:

    PagerDuty alerts = PagerDutyIncidentOperator A [OK]
Hint: PagerDuty operator name includes 'PagerDuty' [OK]
Common Mistakes:
  • Choosing SlackAPIPostOperator for PagerDuty alerts
  • Confusing EmailOperator with PagerDuty integration
  • Selecting HttpSensor which is unrelated
3. Given this Airflow DAG snippet, what will be the output when the task notify_slack runs successfully?
notify_slack = SlackAPIPostOperator(
    task_id='notify_slack',
    token='xoxb-1234',
    channel='#alerts',
    text='DAG completed successfully!'
)
medium
A. No message is sent because the channel name is incorrect
B. An error occurs because the token is invalid
C. A message 'DAG completed successfully!' is posted to the #alerts Slack channel
D. The DAG fails to run because SlackAPIPostOperator is deprecated

Solution

  1. Step 1: Understand SlackAPIPostOperator parameters

    The operator sends a message to the specified Slack channel using the provided token and text.
  2. Step 2: Analyze the given snippet

    The token and channel are set, and the text is 'DAG completed successfully!'. If the token is valid, the message posts successfully.
  3. Final Answer:

    A message 'DAG completed successfully!' is posted to the #alerts Slack channel -> Option C
  4. Quick Check:

    Slack message sent = D [OK]
Hint: SlackAPIPostOperator posts text to channel if token valid [OK]
Common Mistakes:
  • Assuming token is invalid without evidence
  • Thinking SlackAPIPostOperator is deprecated
  • Confusing channel name format
4. You wrote this task to send a PagerDuty alert but it fails with an authentication error:
pagerduty_alert = PagerDutyIncidentOperator(
    task_id='pagerduty_alert',
    routing_key='invalid_key',
    title='Airflow failure',
    severity='critical'
)
What is the most likely cause of the failure?
medium
A. The routing_key is incorrect or invalid
B. The severity value must be 'low' instead of 'critical'
C. PagerDutyIncidentOperator does not support the title parameter
D. The task_id must be 'pagerduty_incident' exactly

Solution

  1. Step 1: Check the routing_key parameter

    The routing_key is a secret token that must be valid for PagerDuty API authentication.
  2. Step 2: Understand authentication errors

    An invalid routing_key causes authentication failure, blocking alert creation.
  3. Final Answer:

    The routing_key is incorrect or invalid -> Option A
  4. Quick Check:

    Authentication error = invalid routing_key A [OK]
Hint: Authentication errors usually mean bad keys or tokens [OK]
Common Mistakes:
  • Changing severity to fix authentication
  • Removing title parameter incorrectly
  • Changing task_id unnecessarily
5. You want to create an Airflow DAG that sends a Slack message only if a PagerDuty incident is triggered. Which approach correctly integrates both operators to achieve this?
hard
A. Use PagerDutyIncidentOperator first, then SlackAPIPostOperator with a trigger rule 'all_done' to send Slack message regardless of PagerDuty success
B. Use PagerDutyIncidentOperator first, then SlackAPIPostOperator with trigger rule 'all_success' to send Slack message only if PagerDuty alert succeeds
C. Use SlackAPIPostOperator first, then PagerDutyIncidentOperator with trigger rule 'one_failed' to send PagerDuty alert only if Slack fails
D. Use both operators in parallel without dependencies to send alerts simultaneously

Solution

  1. Step 1: Define the desired workflow

    Slack message should be sent only if PagerDuty incident is successfully triggered.
  2. Step 2: Set operator order and trigger rules

    Run PagerDutyIncidentOperator first. Set SlackAPIPostOperator to run after it with trigger_rule='all_success' to ensure Slack message only sends if PagerDuty alert succeeds.
  3. Final Answer:

    Use PagerDutyIncidentOperator first, then SlackAPIPostOperator with trigger rule 'all_success' to send Slack message only if PagerDuty alert succeeds -> Option B
  4. Quick Check:

    Slack after PagerDuty success = B [OK]
Hint: Slack depends on PagerDuty success with 'all_success' trigger [OK]
Common Mistakes:
  • Sending Slack message regardless of PagerDuty result
  • Reversing operator order
  • Running both operators in parallel without dependency
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard