Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: improve hightouch sync status readability #1592

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions airflow/dags/mattermost_dags/general/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta

from mattermost.operators.mattermost_operator import MattermostOperator
from tabulate import tabulate

task_logger = logging.getLogger('airflow.task')

Expand Down Expand Up @@ -99,13 +100,11 @@ def hightouch_check_syncs(response):
status = fail or warning, fail
"""
syncs = json.loads(''.join(response))
failed_syncs = {}
failed_syncs = []
try:
if ('data' not in syncs) or len(syncs) == 0:
raise HightouchApiException('Invalid response from syncs api')
failed_syncs = {
sync['slug']: sync['status'] for sync in syncs.get('data') if sync['status'] not in ('success', 'disabled')
}
failed_syncs = [sync for sync in syncs.get('data') if sync['status'] not in ('success', 'disabled')]
except KeyError as e:
task_logger.error('Error in check syncs ...', exc_info=True)
raise e
Expand All @@ -129,7 +128,16 @@ def resolve_hightouch(ti=None, **kwargs):
task_logger.info('There are no failed syncs')
else:
status = ':red_circle:'
message = f"**HIGHTOUCH**: {status}\nFailed syncs: {failed_syncs}"
msg = tabulate(
[
(f"[{sync['slug']}](https://app.hightouch.com/mattermost-com/syncs/{sync['id']})", sync['status'])
for sync in failed_syncs
],
headers=['Sync', 'Status'],
tablefmt='github',
)

message = f"**HIGHTOUCH**: {status}\n\n{msg}"
MattermostOperator(mattermost_conn_id='mattermost', text=message, task_id='resolve_hightouch_message').execute(
None
)
Expand Down
9 changes: 7 additions & 2 deletions airflow/tests/general/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ def test_hightouch_check_syncs_pass(load_data):
response = load_data('monitoring/syncs_pass.json')
failed_syncs = hightouch_check_syncs(response)
# Expected to return empty dict as no loads failed
assert failed_syncs == {}
assert failed_syncs == []


def test_hightouch_check_syncs_fail(load_data):
response = load_data('monitoring/syncs_fail.json')
failed_syncs = hightouch_check_syncs(response)
# Expected to return dict containing failed loads
assert failed_syncs == {'test_sync_1': 'warning'}
assert failed_syncs == [{
"id": 99999,
"slug": "test_sync_1",
"status": "warning",
"updatedAt": "2022-12-07T12:59:20Z"
}]


def test_hightouch_check_syncs_error(load_data):
Expand Down
Loading