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

allow user to specify default value when using store #1020

Merged
merged 3 commits into from
Feb 4, 2025

Conversation

mcalhoun
Copy link
Member

@mcalhoun mcalhoun commented Feb 4, 2025

what

  • Added support for default values in the !store YAML function using the pipe (|) syntax
  • Added comprehensive test coverage for the store function, including default value scenarios
  • Updated documentation to reflect the new default value functionality

why

  • Provides a fallback mechanism when store values are not found, preventing errors
  • Improves user experience by allowing graceful handling of missing values
  • Makes the store function more resilient and flexible in different environments
  • Support cold-start scenarios where components the target component depends on haven't been provisioned yet

references

  • Related to store functionality described in /core-concepts/projects/configuration/stores
  • Implements similar default value patterns found in other YAML processors

Summary by CodeRabbit

  • New Features
    • Introduced an optional default value for YAML store lookups, allowing a fallback when a key is not found.
    • Enhanced parameter parsing and error handling for a smoother user experience.
  • Tests
    • Added comprehensive tests to cover diverse lookup scenarios and default value usage.
  • Documentation
    • Updated the YAML store function guide to include details on the new default value parameter and its usage.

Copy link
Member Author

mcalhoun commented Feb 4, 2025

@mergify mergify bot added the triage Needs triage label Feb 4, 2025
@mcalhoun mcalhoun added the no-release Do not create a new release (wait for additional code changes) label Feb 4, 2025 — with Graphite App
@mcalhoun mcalhoun self-assigned this Feb 4, 2025
@mcalhoun mcalhoun marked this pull request as ready for review February 4, 2025 16:51
@mcalhoun mcalhoun requested a review from a team as a code owner February 4, 2025 16:51
@mcalhoun mcalhoun removed the triage Needs triage label Feb 4, 2025
Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

📝 Walkthrough

Walkthrough

The changes introduce a defaultValue field to the params struct, allowing a default value to be specified alongside existing parameters. The getParams function has been removed, with its logic integrated into processTagStore, which now splits the input string on the pipe symbol to separate parameters from the default value. Error handling has been updated to return the default value if a lookup fails. A new test file has been created to validate these changes, and the documentation for the !store YAML function has been updated to reflect the new optional parameter.

Changes

File(s) Change summary
internal/exec/yaml_func_store.go,
internal/exec/yaml_func_store_test.go
Added defaultValue field to the params struct and integrated its processing into processTagStore. Updated error handling and added comprehensive unit tests.
website/docs/.../store.mdx Updated documentation for the !store YAML function to include details on using an optional default_value parameter with the new syntax.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Caller
  participant P as processTagStore
  participant Store as Store Service
  participant Logger as Logger

  Caller->>P: Invoke processTagStore("storeParams|defaultValue")
  P->>P: Split input into storeParams and defaultValue
  P->>Store: Lookup value using storeParams
  alt Lookup Success
    Store-->>P: Return value
    P-->>Caller: Return retrieved value
  else Lookup Failure
    P->>P: Check for provided defaultValue
    alt Default value provided
      P-->>Caller: Return defaultValue
    else No default value
      P->>Logger: Log error
      P-->>Caller: Return error
    end
  end
Loading

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dceeb04 and b0b828b.

📒 Files selected for processing (3)
  • internal/exec/yaml_func_store.go (2 hunks)
  • internal/exec/yaml_func_store_test.go (1 hunks)
  • website/docs/core-concepts/stacks/yaml-functions/store.mdx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/exec/yaml_func_store_test.go
  • internal/exec/yaml_func_store.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (4)
website/docs/core-concepts/stacks/yaml-functions/store.mdx (4)

11-14: Updated Remote Stores Documentation
The introductory section now explicitly lists Redis along with SSM Parameter Store and Artifactory as examples of supported remote stores. This improves clarity and aligns with the new functionality.


18-19: Clarified Default Value Support
The revised description now clearly states that the !store function accepts an optional default value. This helps set the right expectations for users when a store key is missing.


26-27: Enhanced Usage Example with Default Value
The updated code snippet now demonstrates how to use the default value with the | default syntax, making it easier for users to understand the new convention.


41-43: Documenting the default_value Argument
Adding the default_value argument to the arguments list clearly explains its role when a key isn’t found in the store. Consider including a brief note about quoting—if default values include spaces or special characters, the entire string may need to be quoted, as noted in previous reviews.


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 or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

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
Contributor

@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: 1

🧹 Nitpick comments (2)
internal/exec/yaml_func_store.go (2)

29-43: Pipe-based default value parsing is effective.

The parsing logic is straightforward and clearly signals invalid formats. Consider more robust parsing if multiple pipes or extra arguments are intended in the future.


67-80: Consider returning errors instead of exiting.

Exiting might be limiting for callers who need to handle errors in different ways. A potential refactor:

-    u.LogErrorAndExit(fmt.Errorf("failed to get key: %s", err))
+    return fmt.Errorf("failed to get key: %w", err)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75f70b6 and 2dc79e1.

📒 Files selected for processing (3)
  • internal/exec/yaml_func_store.go (2 hunks)
  • internal/exec/yaml_func_store_test.go (1 hunks)
  • website/docs/core-concepts/stacks/yaml-functions/store.mdx (2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
internal/exec/yaml_func_store_test.go

39-39: Error return value of redisStore.Set is not checked

(errcheck)


40-40: Error return value of redisStore.Set is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: Summary
🔇 Additional comments (7)
internal/exec/yaml_func_store.go (2)

14-18: Pointer-based default value field looks good.

Using a pointer to differentiate between having no default and having an empty default is clean and clear.


45-65: Parameter handling for 3 or 4 arguments is consistent.

The logic for assigning stack, component, and key works nicely.

internal/exec/yaml_func_store_test.go (1)

42-98: Tests cover essential scenarios.

You have thorough coverage for default handling, invalid formats, cross-stack lookups, and more. Helpful for preventing regressions.

website/docs/core-concepts/stacks/yaml-functions/store.mdx (4)

12-12: Updated remote store reference is clear.

Explicitly noting Redis support is helpful.


18-18: Highlighting default value usage.

Mentioning two or three parameters plus a default is concise and user-friendly.


26-28: Example with default value is straightforward.

Illustrates the syntax well.


42-45: Documentation for 'default_value' parameter aligns with code.

This clarifies how to handle missing keys elegantly.

internal/exec/yaml_func_store_test.go Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 4, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 4, 2025
@mcalhoun mcalhoun merged commit 92f70c1 into main Feb 4, 2025
46 checks passed
@mcalhoun mcalhoun deleted the add-store-defaults branch February 4, 2025 21:24
Copy link

github-actions bot commented Feb 5, 2025

These changes were released in v1.159.0.

Cerebrovinny pushed a commit that referenced this pull request Feb 9, 2025
* allow user to specify default value when using store

* Update internal/exec/yaml_func_store_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* allow user to specify default value when using store

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything no-release Do not create a new release (wait for additional code changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants