-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement feature and add tests #5071
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Alert Template Rendering Errors
The workflow contains two template rendering issues:
- The
servicefield is incorrectly accessed asalert.serviceor directly fromalertin bothdictgetand Mustache conditional expressions. It should bealert.labels.serviceto match typical alert data structures. - The
keep.dictgetfunction for theenvironmentfield uses{{ alert.environment }}as an unsafe default value. This can cause a rendering error ifalert.environmentis missing, defeating the purpose of safe rendering. A static string should be used instead.
examples/workflows/teams-adaptive-cards-safe-rendering.yaml#L39-L45
keep/examples/workflows/teams-adaptive-cards-safe-rendering.yaml
Lines 39 to 45 in 6a7c559
| "type": "TextBlock", | |
| "text": "**🌍 Environment**: keep.dictget({{ alert.labels }}, \"environment\", {{ alert.environment }})" | |
| }, | |
| { | |
| "type": "TextBlock", | |
| "text": "**🏷️ Service**: keep.dictget({{ alert }}, \"service\", \"Unknown\")" | |
| }, |
examples/workflows/teams-adaptive-cards-safe-rendering.yaml#L77-L80
keep/examples/workflows/teams-adaptive-cards-safe-rendering.yaml
Lines 77 to 80 in 6a7c559
| { | |
| "type": "TextBlock", | |
| "text": "**🏷️ Service**: {{#alert.service}}{{ alert.service }}{{/alert.service}}{{^alert.service}}Unknown{{/alert.service}}" | |
| }, |
Bug: Mustache Template Errors in Teams Rendering
The teams-safe-rendering-mustache-conditionals action contains two issues:
- The fallback for the
Environmentfield uses{{ alert.environment }}, which can still fail ifalert.environmentis undefined, undermining the safe rendering approach. A static string fallback should be used instead. - The
Servicefield incorrectly references{{ alert.service }}instead of{{ alert.labels.service }}, which is inconsistent with how other label fields are accessed.
examples/workflows/teams-adaptive-cards-safe-rendering.yaml#L73-L79
keep/examples/workflows/teams-adaptive-cards-safe-rendering.yaml
Lines 73 to 79 in 6a7c559
| { | |
| "type": "TextBlock", | |
| "text": "**🌍 Environment**: {{#alert.labels.environment}}{{ alert.labels.environment }}{{/alert.labels.environment}}{{^alert.labels.environment}}{{ alert.environment }}{{/alert.labels.environment}}" | |
| }, | |
| { | |
| "type": "TextBlock", | |
| "text": "**🏷️ Service**: {{#alert.service}}{{ alert.service }}{{/alert.service}}{{^alert.service}}Unknown{{/alert.service}}" |
Was this report helpful? Give feedback by reacting with 👍 or 👎
🚨 BugBot couldn't runSomething went wrong. Try again by commenting "bugbot run", or contact support (requestId: serverGenReqId_3db1e77b-cb68-4b91-b124-740eaa19ecd4). |
close #5070
GitHub issue %235070, concerning conditional namespace display in Teams Adaptive Cards, was addressed.
The root cause was identified in
keep/iohandler/iohandler.py'srender_context()method, wheresafe=Truecaused aRenderExceptionfor missing mustache template keys (e.g.,{{ alert.labels.namespace }}).To resolve this, three new tests were added to
tests/test_teams_provider.py:test_github_issue_5070_mustache_template_rendering()to reproduce the issue.test_teams_adaptive_card_safe_rendering_patterns()to test the Teams provider with safe rendering.test_render_context_safe_parameter_handling()to validateIOHandler.render_context()behavior.Two safe rendering patterns were documented and tested:
keep.dictget({{ alert.labels }}, 'namespace', 'N/A')for robust default value handling.An example workflow,
examples/workflows/teams-adaptive-cards-safe-rendering.yaml, was created to demonstrate these patterns. A documentation fileGITHUB_ISSUE_5070_IMPLEMENTATION.mdwas also added.pyproject.tomlandpoetry.lockwere not modified, adhering to specific constraints, ensuring compatibility with Python 3.11 . All tests pass.