add/slack-alerts (#112)

This commit is contained in:
drethereum 2025-04-23 13:18:02 -06:00 committed by GitHub
parent a8e94b1418
commit 6c069aac3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 164 additions and 56 deletions

View File

@ -67,4 +67,11 @@ jobs:
git commit -am "Auto-update docs"
- name: push changes to docs
run: |
git push -f --set-upstream origin docs
git push -f --set-upstream origin docs
notify-failure:
needs: [scheduled_run]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -65,4 +65,11 @@ jobs:
dbt deps
- name: Run DBT Jobs
run: |
${{ inputs.dbt_command }}
${{ inputs.dbt_command }}
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -44,4 +44,11 @@ jobs:
dbt deps
- name: Run DBT Jobs
run: |
dbt run -m tag:snapshot tag:flashbots
dbt run -m tag:snapshot tag:flashbots
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -44,4 +44,11 @@ jobs:
dbt deps
- name: Run DBT Jobs
run: |
dbt run -m external_models,tag:defillama external_models,tag:deepnftvalue external_models,tag:core external_models,tag:blast external_models,tag:polymarket external_models,tag:bitquery external_models,tag:oklink external_models,tag:artemis --exclude models/defillama/bronze/bronze__defillama_stablecoin_supply.sql+
dbt run -m external_models,tag:defillama external_models,tag:deepnftvalue external_models,tag:core external_models,tag:blast external_models,tag:polymarket external_models,tag:bitquery external_models,tag:oklink external_models,tag:artemis --exclude models/defillama/bronze/bronze__defillama_stablecoin_supply.sql+
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -1,48 +0,0 @@
name: dbt_run_deployment
run-name: dbt_run_deployment
on:
workflow_dispatch:
branches:
- "main"
inputs:
warehouse:
type: choice
description: Snowflake warehouse
required: true
options:
- DBT
- DBT_CLOUD
- DBT_EMERGENCY
default: DBT
dbt_command:
type: string
description: 'DBT Run Command'
required: true
env:
DBT_PROFILES_DIR: ./
DBT_VERSION: "${{ vars.DBT_VERSION }}"
ACCOUNT: "${{ vars.ACCOUNT }}"
ROLE: "${{ vars.ROLE }}"
USER: "${{ vars.USER }}"
PASSWORD: "${{ secrets.PASSWORD }}"
REGION: "${{ vars.REGION }}"
DATABASE: "${{ vars.DATABASE }}"
WAREHOUSE: "${{ inputs.WAREHOUSE }}"
SCHEMA: "${{ vars.SCHEMA }}"
concurrency:
group: ${{ github.workflow }}
jobs:
called_workflow_template:
uses: FlipsideCrypto/analytics-workflow-templates/.github/workflows/dbt_run_deployment_template.yml@main
with:
dbt_command: |
${{ inputs.dbt_command }}
environment: workflow_prod
warehouse: ${{ inputs.WAREHOUSE }}
secrets: inherit

View File

@ -44,4 +44,11 @@ jobs:
dbt deps
- name: Run DBT Jobs
run: |
dbt run-operation run_sp_create_prod_clone
dbt run-operation run_sp_create_prod_clone
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -44,4 +44,11 @@ jobs:
dbt deps
- name: Run DBT Jobs
run: |
dbt run --vars '{"STREAMLINE_INVOKE_STREAMS":True}' -m 1+models/bitquery/streamline/streamline__bitquery_realtime.sql 1+models/oklink/streamline/streamline__oklink_realtime.sql 1+models/artemis/streamline/streamline__artemis_realtime.sql
dbt run --vars '{"STREAMLINE_INVOKE_STREAMS":True}' -m 1+models/bitquery/streamline/streamline__bitquery_realtime.sql 1+models/oklink/streamline/streamline__oklink_realtime.sql 1+models/artemis/streamline/streamline__artemis_realtime.sql
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -44,4 +44,11 @@ jobs:
dbt deps
- name: Run DBT Jobs
run: |
dbt run -m tag:tokenflow tag:tokenlists
dbt run -m tag:tokenflow tag:tokenlists
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -47,4 +47,10 @@ jobs:
- name: Run DBT Jobs
run: |
dbt test -m "external_models,models/"
notify-failure:
needs: [run_dbt_jobs]
if: failure()
uses: ./.github/workflows/slack_notify.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

27
.github/workflows/slack_notify.yml vendored Normal file
View File

@ -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 macros/python/slack_alert.py
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@ -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)