Skip to content

אישור שליחת הודעת אדמין - #3071

Open
amirbiron wants to merge 6 commits into
mainfrom
cursor/-bc-d5a28deb-cde3-4bc4-94a2-4ede2ef23595-07f5
Open

אישור שליחת הודעת אדמין#3071
amirbiron wants to merge 6 commits into
mainfrom
cursor/-bc-d5a28deb-cde3-4bc4-94a2-4ede2ef23595-07f5

Conversation

@amirbiron

Copy link
Copy Markdown
Owner

✨ תיאור קצר

פקודת /admin בבוט הטלגרם תאשר למשתמש שהדיווח נשלח רק לאחר קבלת אישור הצלחה (HTTP 2xx) מ-Alertmanager. במקרה של כשל ב-Alertmanager, הבוט ינסה לשלוח את הדיווח ישירות לאדמינים ויעדכן את המשתמש בהתאם, או יודיע על כשל מוחלט.

📦 שינויים עיקריים

  • קוד (Backend)
  • בוט טלגרם
  • מסד נתונים/מיגרציות
  • תיעוד (docs/)
  • DevOps/CI/CD

פירוט נקודות:

  • לוגיקת הטיפול בפקודת /admin ב-main.py שונתה כך שהיא ממתינה לתשובת הצלחה מ-Alertmanager.
  • נוספה פונקציה _send_admin_report_via_alertmanager שמבצעת קריאת HTTP POST ל-Alertmanager ומחזירה True רק על קבלת סטטוס 2xx.
  • נוספה פונקציה _get_alertmanager_api_alerts_url לבניית URL של Alertmanager מתוך משתני סביבה.
  • במקרה של כשל ב-Alertmanager, הבוט מנסה לשלוח את הדיווח ישירות לאדמינים באמצעות _send_direct_admins.
  • הודעות שונות נשלחות למשתמש בהתאם לתוצאת השליחה (הצלחה ב-AM, הצלחה ישירה, או כשל מוחלט).
  • נוספו משתני סביבה חדשים: ALERTMANAGER_API_URL, ALERTMANAGER_API_TOKEN, ALERTMANAGER_TARGET ותועדו ב-docs/environment-variables.rst וב-services/config_inspector_service.py.
  • נוספו בדיקות יחידה חדשות ב-tests/test_admin_report_command_alertmanager_ack.py המכסות את תרחישי ההצלחה והכשל.

🧪 בדיקות

השינויים נבדקו באמצעות בדיקות יחידה חדשות המדמות תרחישי הצלחה של Alertmanager, כשל ב-Alertmanager עם הצלחת Fallback, וכשל מוחלט בשני המסלולים. כל הבדיקות עברו בהצלחה.

  • Unit
  • Integration
  • Manual

🧪 בדיקות נדרשות ב‑PR

  • 🔍 Code Quality & Security
  • Unit Tests (3.11)
  • Unit Tests (3.12)

📝 סוג שינוי

  • fix: תיקון באג

✅ צ'קליסט

  • הקוד עוקב אחרי הסגנון (Black/isort/flake8/mypy)
  • בדיקות רצות ועוברות
  • תיעוד עודכן (README/Docs)
  • אם נוספו ג'ובים חדשים (Background Jobs) – וודא שהם רשומים ב-services/register_jobs.py (כולל Callback/Trigger להפעלה ידנית — למשל callback_name/trigger_func לפי המבנה) כדי שיופיעו בדשבורד
  • אם נוספו/שונו משתני סביבה – עודכן docs/environment-variables.rst וגם services/config_inspector_service.py
  • אם נוספו/השתנו טוקנים – עודכן גם docs/webapp/theming_and_css.rst + FEATURE_SUGGESTIONS/theme_matrix.md
  • אין סודות/מפתחות בקוד
  • אין מחיקות מסוכנות/פעולות על root (ראו .cursorrules)
  • הודעת הקומיט תואמת Conventional Commits (ע"פ הטבלה)
  • CHANGELOG עודכן אם נדרש
  • כל ה‑Required Checks לעיל ירוקים
  • צילום/וידאו UI מצורף אם רלוונטי

🧩 השפעות/סיכונים

  • השפעה על פרודקשן: משתמשים יקבלו כעת פידבק מדויק יותר לגבי סטטוס שליחת דיווחי /admin. אם Alertmanager אינו זמין, המשתמש יקבל על כך הודעה מפורשת.
  • ביצועים: תיתכן השהייה קלה בתגובה לפקודת /admin עקב המתנה לתשובת HTTP מ-Alertmanager (עם Timeout של 6 שניות).

🔗 קישורים

🧯 סיכון / החזרה לאחור (Rollback)

  • תוכנית חזרה לאחור במקרה תקלה: ביצוע Rollback ל-PR זה.

Open in Cursor Open in Web

cursoragent and others added 2 commits February 10, 2026 21:01
Co-authored-by: amir haim <amirbiron@users.noreply.github.com>
Co-authored-by: amir haim <amirbiron@users.noreply.github.com>
@cursor

cursor Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions

github-actions Bot commented Feb 10, 2026

Copy link
Copy Markdown

🧯 Dangerous deletes guard report

Policy: see .cursorrules — dangerous deletions are blocked unless wrapped safely.

Summary:

  • Flagged findings (blocking): 0
    0
  • Excluded matches (not blocking): 15
  • Total matches (all files): 129

Flagged findings (file:line:snippet):
(none)

Excluded matches (by path pattern)
./Dockerfile:42:    rm -rf /var/lib/apt/lists/*
./Dockerfile:121:    rm -rf /var/lib/apt/lists/*
./webapp/static/js/md_preview.bundle.js.map:4:  "sourcesContent": ["// Markdown-it plugin to render GitHub-style task lists; see\n//\n// https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments\n// https://github.com/blog/1825-t … [truncated]
./README.md:842:find . -name "__pycache__" -exec rm -rf {} +
./docs/DOCUMENTATION_GUIDE.md:453:rm -rf _build
./docs/Makefile:24:	rm -rf $(BUILDDIR)
./node_modules/mermaid/dist/chunks/mermaid.core/chunk-KS23V3DP.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequence  … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm.min/chunk-4HFYJGYH.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequen … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm.min/chunk-4HFYJGYH.mjs:1:var r={name:"mermaid",version:"11.12.0",description:"Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graph … [truncated]
./node_modules/mermaid/dist/chunks/mermaid.esm/chunk-2M32CCKP.mjs.map:4:  "sourcesContent": ["{\n  \"name\": \"mermaid\",\n  \"version\": \"11.12.0\",\n  \"description\": \"Markdown-ish syntax for generating flowcharts, mindmaps, sequence d … [truncated]
./node_modules/mermaid/dist/mermaid.min.js:1524:`,"getStyles"),c1e=RQe});var h1e={};dr(h1e,{diagram:()=>NQe});var NQe,f1e=N(()=>{"use strict";$ge();a1e();l1e();u1e();NQe={parser:Fge,db:n1e,renderer:o1e,styles:c1e}});var m1e,g1e=N(()=>{"use  … [truncated]
./node_modules/mermaid/dist/mermaid.js.map:4:  "sourcesContent": ["/**\n* Default values for dimensions\n*/\nconst defaultIconDimensions = Object.freeze({\n\tleft: 0,\n\ttop: 0,\n\twidth: 16,\n\theight: 16\n});\n/**\n* Default values for tr … [truncated]
./node_modules/mermaid/dist/mermaid.min.js.map:4:  "sourcesContent": ["/**\n* Default values for dimensions\n*/\nconst defaultIconDimensions = Object.freeze({\n\tleft: 0,\n\ttop: 0,\n\twidth: 16,\n\theight: 16\n});\n/**\n* Default values fo … [truncated]
./node_modules/katex/package.json:153:    "build": "rimraf dist/ && mkdirp dist && cp README.md dist && rollup -c --failAfterWarnings && webpack && node update-sri.js package dist/README.md",
./node_modules/katex/src/fonts/Makefile:139:	rm -rf pfa ff otf ttf woff woff2

@amirbiron
amirbiron marked this pull request as ready for review February 10, 2026 21:12
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Feb 10, 2026

Copy link
Copy Markdown

⏱️ Performance report

(No performance test durations collected. Mark tests with @pytest.mark.performance.)

@sentry

sentry Bot commented Feb 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.28571% with 30 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
main.py 64.28% 20 Missing and 10 partials ⚠️

📢 Thoughts on this report? Let us know!

Comment thread main.py Outdated
Co-authored-by: amir haim <amirbiron@users.noreply.github.com>
@github-actions

github-actions Bot commented Feb 10, 2026

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully!

To view locally:

  1. Download the artifacts
  2. Extract the zip file
  3. Open index.html in your browser

Comment thread main.py Outdated
Co-authored-by: amir haim <amirbiron@users.noreply.github.com>
Comment thread main.py
Co-authored-by: amir haim <amirbiron@users.noreply.github.com>
Comment thread main.py Outdated
Co-authored-by: amir haim <amirbiron@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread main.py

sent_direct = await _send_direct_admins(context, report)
if sent_direct:
await message.reply_text("כרגע Alertmanager לא זמין, אבל שלחתי את הדיווח ישירות לאדמין.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback bypasses Rule Engine and internal alerts

High Severity

The new /admin command flow bypasses notify_admins() entirely. When Alertmanager fails and _send_direct_admins() is used as fallback, messages are sent directly via bot.send_message, which bypasses both emit_internal_alert() and the Rule Engine's suppress/routing logic. The existing notify_admins() function (line 734) explicitly documents that admin messages should not be sent directly to avoid bypassing the Rule Engine. This breaks alert consolidation, suppression rules, and observability for fallback cases.

Fix in Cursor Fix in Web

Comment thread main.py
if low.endswith(":443"):
scheme = "https"
elif low.endswith(":9093") or low.endswith(":80") or low.startswith("localhost") or low.startswith("127.") or low.startswith("alertmanager"):
scheme = "http"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scheme guessing fails for non-standard HTTPS ports

Low Severity

The scheme guessing logic checks if the hostname starts with alertmanager and defaults to http, which incorrectly handles URLs like alertmanager.prod.example.com:8443 or alertmanager-api.example.com:9443 where HTTPS is running on non-standard ports. The check for startswith("alertmanager") on line 778 takes precedence over port-based detection for any port other than 443, causing HTTPS requests to fail. Users can work around this by using ALERTMANAGER_API_URL with the full scheme.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants