Repository navigation
feature: alert-relay — alertas de dgb.ops.alerts no Telegram da equipe - #214
Merged
Merged
Conversation
Contrato do worker genérico de alertas operacionais:
- formata incidentes do Cloud Monitoring (aberto/resolvido), mensagens
{"text","title","severity","source"} e texto cru, com HTML escapado e limite
de 4096 caracteres; marca [TESTE] (atributo test=true ou "test": true);
- envia com chat_id e message_thread_id opcional; 400 tenta de novo sem
parse_mode;
- 200 quando o Telegram aceita; 503 em 429/5xx/rede/401/403/404 e secret
indisponível; ACK em 400 persistente e envelope inválido;
- secrets lidos em runtime com cache; o token nunca aparece em log/resposta.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Worker genérico (Cloud Run, push do tópico dgb.ops.alerts) que entrega no canal
do Telegram da equipe:
- formatter: incidentes do Cloud Monitoring (notification channel pubsub,
aberto/resolvido, com link e documentação), mensagens {"text","title",
"severity","source"} de qualquer job e texto cru; HTML escapado, limite do
Telegram e marca 🧪 [TESTE];
- telegram: sendMessage com message_thread_id opcional; 400 tenta de novo sem
parse_mode; erro de rede vira só o nome da exceção (a URL tem o token);
- secrets: token e chat id lidos do Secret Manager em runtime, cache de 5 min e
último valor conhecido em falha (o serviço sobe antes de o valor existir);
- app: /health async; /process responde 200 (entregue ou sem conserto), 503
para reentregar (429/5xx/rede/401/403/404, secret indisponível); linha
estável alert_relay_sent status=… ok=… kind=… state=… test=… policy=…;
- docker/alert-relay e alert-relay-deploy.yaml (cloud-run-deploy reutilizável,
serviço destaquesgovbr-alert-relay criado no infra, ops-alerts.tf).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objetivo
Entregar os alertas operacionais no canal do Telegram da equipe, o mesmo da skill
enviar-telegram. A infraestrutura veio no destaquesgovbr/infra#220, já aplicado: tópicodgb.ops.alerts, notification channel Pub/Sub do Cloud Monitoring, alert policyenrichment-worker: instância morta pelo liveness, Cloud Rundestaquesgovbr-alert-relay(placeholder) e secrets. Este PR traz o código do relay e o deploy.Worker
workers/alert_relay(genérico)formatter.py: formata em HTML escapado, respeitando o limite de 4096 caracteres do Telegram. Testes (atributotest=trueou"test": true) saem com 🧪 [TESTE]. Entradas aceitas:{"incident": {...}, "version": "1.2"}): 🔴 ALERTA ou ✅ RESOLVIDO, com resumo, condição, recurso, início/fim, documentação e link;{"text", "title"?, "severity"?, "source"?};telegram.py:sendMessagecomchat_idemessage_thread_idopcional.parse_mode.secrets.py: lê o token e o chat id do Secret Manager em runtime (REST egoogle-auth), com cache de 5 min.app.py:/healthé async./processlê o envelope e roda o envio no threadpool.alert_relay_sent status=<http> ok=<bool> kind=<incident|text|raw> state=… test=… policy=… message_id=….docker/alert-relay/Dockerfile, no padrão dos outros workers, e.github/workflows/alert-relay-deploy.yamlcom ocloud-run-deployreutilizável, que só troca a imagem.Testes
test: … (red)e depoisfeature:.tests/unit/workers/alert_relay/test_alert_relay.pytem 32 testes: formatter, telegram (thread, retentáveis, 400 com fallback, erro de rede sem vazar o token), secrets (cache, fallback, valor vazio) e app (200, 503, ACK, token fora dos logs e da resposta).tests/unit/test_alert_relay_deploy_workflow.pyconfere que o workflow aponta para os recursos do infra.pytest tests/unit/ --cov=data_platform: 1340 passed, cobertura de 82,6%.Depois do merge
dgb.ops.alerts.Follow-up (fora deste PR)
O
monitor_scraping_health(scraper) hoje só loga, por falta de webhook. Ele pode publicar{"text": ...}emdgb.ops.alerts.🤖 Generated with Claude Code