Skip to content
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
15 changes: 15 additions & 0 deletions .github/workflows/deploy-automator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
type: choice
options: [ml, genmedia]
default: ml
faq_probe:
description: 'Ask the live FAQ assistant one question with the Lambda URL/secret (no Slack posts) and require a 200 answer'
type: boolean
default: false
proof_keep_seconds:
description: 'Seconds to keep the verified question and reply visible before cleanup'
type: string
Expand Down Expand Up @@ -98,6 +102,17 @@ jobs:
--output text
echo "Automator Lambda function updated successfully"

- name: Probe the live FAQ assistant
if: github.event_name == 'workflow_dispatch' && inputs.faq_probe
run: |
umask 077
lambda_env=$(mktemp)
trap 'rm -f "$lambda_env"' EXIT
aws lambda get-function-configuration \
--function-name "$FUNCTION_NAME" --region "$AWS_REGION" \
--query 'Environment.Variables' --output json > "$lambda_env"
uv run python scripts/probe_faq_assistant.py < "$lambda_env"

- name: Verify real Slack question and answer
if: github.event_name == 'workflow_dispatch' && inputs.live_proof
env:
Expand Down
47 changes: 47 additions & 0 deletions automator/scripts/probe_faq_assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Ask the live FAQ assistant one question the way the automator does.

Reads the automator Lambda environment JSON (FAQ_ASSISTANT_URL and
FAQ_ASSISTANT_SHARED_SECRET) on stdin, POSTs a course-scoped question to /ask
and fails unless it gets HTTP 200 with a non-empty answer. Nothing is posted to
Slack. The secret is never printed.
"""

import json
import sys

import requests

QUESTION = 'How do I submit the homework?'
COURSE = 'ai-dev-tools-zoomcamp'


def main() -> int:
env = json.load(sys.stdin)
url = (env.get('FAQ_ASSISTANT_URL') or '').strip().rstrip('/')
secret = env.get('FAQ_ASSISTANT_SHARED_SECRET') or ''
if secret:
print(f'::add-mask::{secret}', flush=True) # GitHub Actions log masking
if not url:
print('FAQ_ASSISTANT_URL is not set on the automator Lambda')
return 1
endpoint = url if url.endswith('/ask') else f'{url}/ask'
headers = {'x-faq-assistant-secret': secret} if secret else {}
response = requests.post(
endpoint,
json={'question': QUESTION, 'scope': 'course', 'course': COURSE},
headers=headers,
timeout=60,
)
print(f'HTTP {response.status_code}')
if response.status_code != 200:
print(response.text[:500])
return 1
body = response.json()
answer = (body.get('answer') or '').strip()
print(f"found_answer={body.get('found_answer')} sources={len(body.get('sources') or [])}")
print(f'answer: {answer[:300]}')
return 0 if answer else 1


if __name__ == '__main__':
sys.exit(main())
11 changes: 8 additions & 3 deletions automator/src/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'The FAQ assistant is currently not available. '
'In the meantime, you can try to find the answer here:'
)
FAQ_ASSISTANT_UNAVAILABLE_MARKER = 'FAQ_ASSISTANT_UNAVAILABLE'
FAQ_ASSISTANT_GENERIC_RESOURCES = {
'docs': 'https://datatalks.club/docs/',
'faq': 'https://datatalks.club/faq/',
Expand Down Expand Up @@ -167,9 +168,13 @@ def post_faq_assistant_answer(channel, thread_ts, payload, student_user=None):
response = getattr(exc, 'response', None)
status = getattr(response, 'status_code', None)
body = getattr(response, 'text', '') if response is not None else ''
logger.info(
f"FAQ assistant request failed: status={status} "
f"error={exc} body={body[:500]}"
# FAQ_ASSISTANT_UNAVAILABLE is matched by a CloudWatch metric filter
# (aws-infra main/automator) that alarms to operator-alerts; keep the
# token stable.
logger.error(
f"{FAQ_ASSISTANT_UNAVAILABLE_MARKER} FAQ assistant request failed: "
f"status={status} course={payload.get('course', '')} "
f"channel={channel} error={exc} body={body[:500]}"
)
slack.post_message_to_thread(
channel, thread_ts, format_faq_assistant_error_message(payload)
Expand Down
10 changes: 9 additions & 1 deletion automator/tests/test_automator_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,10 @@ def test_handle_app_mention_appends_sources(self, mock_call, mock_slack):
self.assertIn('*Sources:*', posted)
self.assertIn('<https://datatalks.club/faq/llm-zoomcamp.html#abc|Joining>', posted)

@patch('automator_lambda_function.logger')
@patch('automator_lambda_function.slack')
@patch('automator_lambda_function.call_faq_assistant')
def test_faq_assistant_failure_posts_error_without_raising(self, mock_call, mock_slack):
def test_faq_assistant_failure_posts_error_without_raising(self, mock_call, mock_slack, mock_logger):
response = MagicMock()
response.status_code = 500
response.text = 'upstream exploded'
Expand All @@ -1238,6 +1239,13 @@ def test_faq_assistant_failure_posts_error_without_raising(self, mock_call, mock
)

mock_slack.github_to_slack_markdown.assert_not_called()
alert_lines = [
call.args[0] for call in mock_logger.error.call_args_list
if call.args[0].startswith('FAQ_ASSISTANT_UNAVAILABLE ')
]
self.assertEqual(len(alert_lines), 1)
self.assertIn('status=500', alert_lines[0])
self.assertIn('course=llm-zoomcamp', alert_lines[0])
posted = mock_slack.post_message_to_thread.call_args[0][2]
self.assertIn('The FAQ assistant is currently not available.', posted)
self.assertIn('In the meantime, you can try to find the answer here:', posted)
Expand Down
22 changes: 22 additions & 0 deletions docs/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,25 @@ On Windows with Git Bash, paths like `/aws/lambda/...` get converted to Windows
1. Go to CloudWatch Logs in AWS Console
2. Navigate to `/aws/lambda/automator-process-reaction`
3. View logs in real-time or search

## FAQ assistant unavailable alert

When the FAQ assistant call fails, the bot still replies in the thread with the
"The FAQ assistant is currently not available" fallback, and logs one line
starting with `FAQ_ASSISTANT_UNAVAILABLE` (status, course, channel, error, body).

The CloudWatch metric filter `automator-faq-assistant-unavailable` (Terraform:
`aws-infra/main/automator/alerts.tf`) counts those lines into
`Automator/FaqAssistantUnavailable`. The alarm with the same name fires on any
occurrence in 5 minutes and notifies the `operator-alerts` SNS topic, which
emails dev@dtcdev.click (the oncall mailbox). Keep the marker token stable.

```bash
aws logs filter-log-events --log-group-name /aws/lambda/automator-process-reaction \
--filter-pattern FAQ_ASSISTANT_UNAVAILABLE --start-time <ms>
```

To check the live FAQ assistant without posting to Slack, run the deploy
workflow with `faq_probe=true` (`gh workflow run deploy-automator.yml -f faq_probe=true`):
it reads the URL and shared secret from the Lambda config and requires a 200
answer from `/ask`.