-
Notifications
You must be signed in to change notification settings - Fork 70
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
Escape mustaches in prometheus rules for Helm. #645
Conversation
WalkthroughA new template file Changes
Sequence Diagram(s)sequenceDiagram
participant H as Helm CLI
participant T as alerts.yaml Template
participant G as Glob Matcher
participant F as Alert Files
participant O as Aggregated YAML Output
H->>T: Execute helm template command
T->>G: Search for "alerts/*.yaml"
G->>F: Return matching alert files
T->>F: Read file content and add source comments
T->>O: Aggregate all file contents
O-->>H: Render complete YAML document
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
We usually solve this by importing alerts from the separated alerts
directory
Could you please update PR to use the similar logic?
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/system/kafka-operator/templates/alerts.yaml (1)
1-1
: YAML Linter Compatibility NoteSince this file is a Helm template, YAML linter errors (such as the one reported on line 1) may occur because of the templating syntax. Consider adding an appropriate YAML linter disable comment (or configuring your linter accordingly) to avoid false positives.
🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 1-1: syntax error: expected the node content, but found '-'
(syntax)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/system/kafka-operator/templates/alerts.yaml
(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
packages/system/kafka-operator/templates/alerts.yaml
[error] 1-1: syntax error: expected the node content, but found '-'
(syntax)
{{- range $path, $file := $files }} | ||
--- | ||
# from: {{ $path }} | ||
{{ toString $file }} |
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.
🛠️ Refactor suggestion
Escape Mustaches in Alert File Contents
To prevent Helm from misinterpreting Prometheus rule mustaches within the alert files, pipe the file content through a replacement function. For example, using Sprig’s replace
function, convert each opening and closing mustache into an escaped version. This ensures that the raw alert definitions (which likely contain mustache syntax) are rendered literally.
Below is a proposed diff change for line 5:
-{{ toString $file }}
+{{ toString $file | replace "{{" "{{\"{{\"}}" | replace "}}" "{{\"}}\"}}" }}
This diff replaces all occurrences of {{
with {{"{{"}}
and }}
with {{"}}"}}
, which should effectively escape the mustaches.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
{{ toString $file }} | |
{{ toString $file | replace "{{" "{{\"{{\"}}" | replace "}}" "{{\"}}\"}}" }} |
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.
LGTM
Summary by CodeRabbit