Skip to content
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

Fix query service env vars handling for additionalEnvs (closes #578) #591

Conversation

TheShubhendra
Copy link
Contributor

@TheShubhendra TheShubhendra commented Jan 3, 2025

This PR addresses the issue where the handling of additional environment variables (additionalEnvs) in the query service was not flexible enough. The changes allow for both backward-compatible key-value pairs and more advanced configurations, including value references from secrets and config maps.

Changes made:

  • Updated statefulset.yaml to handle different structures for additionalEnvs.
  • Modified values.yaml to include examples for both types of configurations.

Closes #578.

Summary by CodeRabbit

  • Documentation

    • Updated documentation for Query Service environment variables.
    • Improved configuration guidance for environment variable settings.
    • Added support for more flexible environment variable configurations.
  • Improvements

    • Enhanced SMTP configuration validation to prevent conflicts.
    • Introduced a new function for dynamic rendering of environment variables, improving configuration handling.
  • Version Update

    • Updated Helm Chart version from 0.64.1 to 0.64.2.

@TheShubhendra TheShubhendra requested a review from a team as a code owner January 3, 2025 11:10
Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request modifies the SigNoz chart configuration to enhance environment variable handling for the query service. The changes introduce a more flexible approach to defining environment variables in the statefulset.yaml and values.yaml files. The new configuration supports multiple ways of setting environment variables, including direct values, secret references, and configmap references, providing users with greater configuration flexibility.

Changes

File Change Summary
charts/signoz/templates/query-service/statefulset.yaml Enhanced environment variable handling with conditional logic for map-type values and added conflict validation for SMTP configurations.
charts/signoz/values.yaml Updated documentation and structure for environment variables, supporting more advanced configuration methods.
charts/signoz/templates/_helpers.tpl Added a new function signoz.renderAdditionalEnv to dynamically render environment variables based on input data structures.
charts/signoz/Chart.yaml Updated version from 0.64.1 to 0.64.2.

Assessment against linked issues

Objective Addressed Explanation
Enable flexible env variable configuration [#578]
Support secret and configmap references
Provide multiple ways to define env variables

Poem

🐰 In the realm of charts and configs so bright,
Env vars dance with newfound might!
Secrets whisper, values gleam,
Flexibility reigns supreme!
A rabbit's config, now so clean! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef68412 and 7d0c06d.

📒 Files selected for processing (1)
  • charts/signoz/Chart.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • charts/signoz/Chart.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test-chart

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
charts/signoz/templates/query-service/statefulset.yaml (1)

143-152: LGTM! Well-structured environment variable handling.

The implementation elegantly supports both backward-compatible simple values and advanced configurations using Kubernetes native patterns. This allows users to reference values from secrets and configmaps while maintaining compatibility with existing configurations.

Consider adding validation to ensure that when using the map structure, at least one of value or valueFrom is specified. Also, adding comments to explain the supported formats would improve maintainability.

 {{- range $key, $val := .Values.queryService.additionalEnvs }}
 - name: {{ $key }}
+  {{- /* Support both simple values and advanced configurations with secrets/configmaps */ -}}
   {{- if kindIs "map" $val }}
+    {{- /* Ensure either value or valueFrom is specified */ -}}
+    {{- if and (not $val.value) (not $val.valueFrom) }}
+      {{- fail (printf "Environment variable '%s' must specify either 'value' or 'valueFrom'" $key) }}
+    {{- end }}
     {{- if $val.value}}
     value: {{ $val.value | quote }}
     {{- end}}
charts/signoz/values.yaml (1)

599-614: Documentation looks good, consider adding more examples.

The documentation clearly explains both configuration methods with good examples. The recommendation to use the flexible structure is helpful for users.

Consider enhancing the documentation with:

  1. More examples showing different valueFrom sources:
    additionalEnvs:
      # Example with ConfigMap
      CONFIG_KEY:
        valueFrom:
          configMapKeyRef:
            name: my-config
            key: my-key
      
      # Example with Secret
      API_KEY:
        valueFrom:
          secretKeyRef:
            name: my-secret
            key: api-key
      
      # Example with Field Ref
      POD_NAME:
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
  2. A note about validation requirements when using the flexible structure.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1911336 and aaa098d.

📒 Files selected for processing (2)
  • charts/signoz/templates/query-service/statefulset.yaml (1 hunks)
  • charts/signoz/values.yaml (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
charts/signoz/templates/_helpers.tpl (1)

750-768: Consider collisions caused by uppercase conversion.
Converting keys to uppercase and ignoring duplicates may inadvertently drop keys if their uppercase variants match. It's generally advisable to fail fast or warn if collisions occur, rather than silently skipping one. You could add a check to log or surface a warning about potential collisions.

- {{- if not (hasKey $processedKeys $key) }}
+ {{- if hasKey $processedKeys $key }}
+ {{- /* Optionally log or warn about duplicate uppercase environment variable names */ -}}
+ {{- else }}
{{- $processedKeys = merge $processedKeys (dict $key true) -}}
...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aaa098d and 914341e.

📒 Files selected for processing (2)
  • charts/signoz/templates/_helpers.tpl (1 hunks)
  • charts/signoz/templates/query-service/statefulset.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • charts/signoz/templates/query-service/statefulset.yaml
🔇 Additional comments (3)
charts/signoz/templates/_helpers.tpl (3)

743-746: Documentation is well-structured and clear.
Great job on adding a concise explanatory comment above the function definition, making it immediately clear what this template function does.


747-749: Good use of local variables to manage input and processed keys.
The usage of $dict to hold the initial data and $processedKeys to track duplicates is helpful for maintaining readability.


757-765: Validate special types (secrets, configMaps) if needed.
If you plan on supporting additional structures (e.g., further nested objects for secret references), you may need specialized handling logic here. This is a good start, but keep in mind future expansions for more complex environment variable structures.

charts/signoz/templates/_helpers.tpl Outdated Show resolved Hide resolved
charts/signoz/templates/_helpers.tpl Show resolved Hide resolved
@grandwizard28
Copy link
Contributor

@TheShubhendra, this looks good, can you please bump the SigNoz version in Charts.yaml?

@TheShubhendra
Copy link
Contributor Author

@TheShubhendra, this looks good, can you please bump the SigNoz version in Charts.yaml?

Done!

@grandwizard28 grandwizard28 merged commit ecf3b59 into SigNoz:main Jan 6, 2025
3 of 4 checks passed
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.

Enable all kinds of env variables in query-service
2 participants