diff --git a/.github/workflows/dbt_docs_update.yml b/.github/workflows/dbt_docs_update.yml index 8e00261..dc261d9 100644 --- a/.github/workflows/dbt_docs_update.yml +++ b/.github/workflows/dbt_docs_update.yml @@ -69,4 +69,11 @@ jobs: git commit -am "Auto-update docs" - name: push changes to docs run: | - git push -f --set-upstream origin docs \ No newline at end of file + git push -f --set-upstream origin docs + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_daily.yml b/.github/workflows/dbt_run_daily.yml index 10a416c..ffd7316 100644 --- a/.github/workflows/dbt_run_daily.yml +++ b/.github/workflows/dbt_run_daily.yml @@ -45,4 +45,11 @@ jobs: dbt deps - name: Run DBT Jobs run: | - dbt run -s "osmosis_models,tag:daily" \ No newline at end of file + dbt run -s "osmosis_models,tag:daily" + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_incremental_core.yml b/.github/workflows/dbt_run_incremental_core.yml index f842859..8afaae2 100644 --- a/.github/workflows/dbt_run_incremental_core.yml +++ b/.github/workflows/dbt_run_incremental_core.yml @@ -45,4 +45,11 @@ jobs: dbt deps - name: Run DBT Jobs run: | - dbt run -s "osmosis_models,tag:core" \ No newline at end of file + dbt run -s "osmosis_models,tag:core" + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_incremental_non_core.yml b/.github/workflows/dbt_run_incremental_non_core.yml index 33cc11d..e5b7ca6 100644 --- a/.github/workflows/dbt_run_incremental_non_core.yml +++ b/.github/workflows/dbt_run_incremental_non_core.yml @@ -45,4 +45,11 @@ jobs: dbt deps - name: Run DBT Jobs run: | - dbt run -s "osmosis_models,tag:noncore" \ No newline at end of file + dbt run -s "osmosis_models,tag:noncore" + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_observability.yml b/.github/workflows/dbt_run_observability.yml index 343fd5f..733ae4e 100644 --- a/.github/workflows/dbt_run_observability.yml +++ b/.github/workflows/dbt_run_observability.yml @@ -47,3 +47,9 @@ jobs: run: | dbt run -m models/silver/_observability/silver_observability* + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_observability_monthly.yml b/.github/workflows/dbt_run_observability_monthly.yml index 3b316ab..644d7fb 100644 --- a/.github/workflows/dbt_run_observability_monthly.yml +++ b/.github/workflows/dbt_run_observability_monthly.yml @@ -47,3 +47,9 @@ jobs: run: | dbt run -m models/silver/_observability/silver_observability* --vars "OBSERV_FULL_TEST: true" + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_streamline_balances.yml b/.github/workflows/dbt_run_streamline_balances.yml index 1887dae..0305001 100644 --- a/.github/workflows/dbt_run_streamline_balances.yml +++ b/.github/workflows/dbt_run_streamline_balances.yml @@ -46,3 +46,10 @@ jobs: - name: Run DBT Jobs run: | dbt run --vars '{"STREAMLINE_INVOKE_STREAMS":True}' -m 1+models/streamline/silver/core/realtime/streamline__pool_balances_realtime.sql -t prod + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_streamline_blocks_txcount_realtime.yml b/.github/workflows/dbt_run_streamline_blocks_txcount_realtime.yml index 28bb213..ff5212c 100644 --- a/.github/workflows/dbt_run_streamline_blocks_txcount_realtime.yml +++ b/.github/workflows/dbt_run_streamline_blocks_txcount_realtime.yml @@ -46,3 +46,10 @@ jobs: - name: Run DBT Jobs run: | dbt run --vars '{"STREAMLINE_INVOKE_STREAMS":True}' -m 2+models/streamline/silver/core/realtime/streamline__blocks_realtime.sql 1+models/streamline/silver/core/realtime/streamline__tx_counts_realtime.sql -t prod + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_streamline_transactions_realtime.yml b/.github/workflows/dbt_run_streamline_transactions_realtime.yml index bef5d3f..5595eea 100644 --- a/.github/workflows/dbt_run_streamline_transactions_realtime.yml +++ b/.github/workflows/dbt_run_streamline_transactions_realtime.yml @@ -45,4 +45,11 @@ jobs: dbt deps - name: Run DBT Jobs run: | - dbt run --vars '{"STREAMLINE_INVOKE_STREAMS":True}' -m 1+models/streamline/silver/core/realtime/streamline__transactions_realtime.sql -t prod \ No newline at end of file + dbt run --vars '{"STREAMLINE_INVOKE_STREAMS":True}' -m 1+models/streamline/silver/core/realtime/streamline__transactions_realtime.sql -t prod + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/dbt_run_udf_blockchain.yml b/.github/workflows/dbt_run_udf_blockchain.yml index c62e088..d9ffbe1 100644 --- a/.github/workflows/dbt_run_udf_blockchain.yml +++ b/.github/workflows/dbt_run_udf_blockchain.yml @@ -75,3 +75,10 @@ jobs: dbt run -m models/silver/core/silver__blockchain.sql dbt run-operation get_blockchain_api dbt run -m models/silver/core/silver__blockchain.sql + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_test.yml b/.github/workflows/dbt_test.yml index eead734..dd2735a 100644 --- a/.github/workflows/dbt_test.yml +++ b/.github/workflows/dbt_test.yml @@ -45,4 +45,11 @@ jobs: dbt deps - name: Run DBT Jobs run: | - dbt test -m "osmosis_models,./models" \ No newline at end of file + dbt test -m "osmosis_models,./models" + + notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.github/workflows/slack_notify.yml b/.github/workflows/slack_notify.yml new file mode 100644 index 0000000..1866ba2 --- /dev/null +++ b/.github/workflows/slack_notify.yml @@ -0,0 +1,27 @@ +name: Slack Notification +on: + workflow_call: + secrets: + SLACK_WEBHOOK_URL: + required: true + +jobs: + notify: + runs-on: ubuntu-latest + environment: workflow_prod + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: pip install requests + + - name: Send Slack notification + run: python python/slack_alert.py + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/package-lock.yml b/package-lock.yml index 4617dd5..09d5cf4 100644 --- a/package-lock.yml +++ b/package-lock.yml @@ -1,16 +1,16 @@ packages: -- package: dbt-labs/dbt_utils - version: 1.0.0 -- package: calogica/dbt_expectations - version: 0.8.5 -- package: dbt-labs/dbt_external_tables - version: 0.8.0 -- git: https://github.com/FlipsideCrypto/fsc-utils.git - revision: eb33ac727af26ebc8a8cc9711d4a6ebc3790a107 -- package: get-select/dbt_snowflake_query_tags - version: 2.5.0 -- package: calogica/dbt_date - version: 0.7.2 -- git: https://github.com/FlipsideCrypto/livequery-models.git - revision: b024188be4e9c6bc00ed77797ebdc92d351d620e -sha1_hash: 65a2accc60e77d91a09c5b3181f6c96efa77ca03 + - package: dbt-labs/dbt_utils + version: 1.0.0 + - package: calogica/dbt_expectations + version: 0.8.5 + - package: dbt-labs/dbt_external_tables + version: 0.8.0 + - git: https://github.com/FlipsideCrypto/fsc-utils.git + revision: d3cf679e079f0cf06142de9386f215e55fe26b3b + - package: get-select/dbt_snowflake_query_tags + version: 2.5.0 + - package: calogica/dbt_date + version: 0.7.2 + - git: https://github.com/FlipsideCrypto/livequery-models.git + revision: b024188be4e9c6bc00ed77797ebdc92d351d620e +sha1_hash: 9f194e4eda88013d3a55e223ec7fedbdfaee38a9 diff --git a/python/slack_alert.py b/python/slack_alert.py new file mode 100644 index 0000000..4e624f7 --- /dev/null +++ b/python/slack_alert.py @@ -0,0 +1,74 @@ +import requests +import os +import sys + +def create_message(): + """Creates a simple failure notification message with repo, workflow name, and URL""" + + # Get GitHub environment variables + repository = os.environ.get('GITHUB_REPOSITORY', 'Unknown repository') + repo_name = repository.split('/')[-1] if '/' in repository else repository + workflow_name = os.environ.get('GITHUB_WORKFLOW', 'Unknown workflow') + run_id = os.environ.get('GITHUB_RUN_ID', '') + server_url = os.environ.get('GITHUB_SERVER_URL', 'https://github.com') + + # Build the workflow URL + workflow_url = f"{server_url}/{repository}/actions/runs/{run_id}" + + message_body = { + "text": f"Failure in {repo_name}", + "attachments": [ + { + "color": "#f44336", # Red color for failures + "fields": [ + { + "title": "Repository", + "value": repository, + "short": True + }, + { + "title": "Workflow", + "value": workflow_name, + "short": True + } + ], + "actions": [ + { + "type": "button", + "text": "View Workflow Run", + "style": "primary", + "url": workflow_url + } + ], + "footer": "GitHub Actions" + } + ] + } + + return message_body + +def send_alert(webhook_url): + """Sends a failure notification to Slack""" + + message = create_message() + + try: + response = requests.post(webhook_url, json=message) + + if response.status_code == 200: + print("Successfully sent Slack notification") + else: + print(f"Failed to send Slack notification: {response.status_code} {response.text}") + sys.exit(1) + except Exception as e: + print(f"Error sending Slack notification: {str(e)}") + sys.exit(1) + +if __name__ == '__main__': + webhook_url = os.environ.get("SLACK_WEBHOOK_URL") + + if not webhook_url: + print("ERROR: SLACK_WEBHOOK_URL environment variable is required") + sys.exit(1) + + send_alert(webhook_url) \ No newline at end of file