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

feat(ledger): add configurable default and max page sizes #214

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Jan 7, 2025

Fixes ENG-1577

@gfyrag gfyrag requested a review from a team as a code owner January 7, 2025 08:33
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Warning

Rate limit exceeded

@gfyrag has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 46 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fa111fb and 160d0e3.

⛔ Files ignored due to path filters (2)
  • config/crd/bases/formance.com_brokers.yaml is excluded by !**/*.yaml
  • helm/crds/templates/crds/apiextensions.k8s.io_v1_customresourcedefinition_brokers.formance.com.yaml is excluded by !**/*.yaml
📒 Files selected for processing (2)
  • api/formance.com/v1beta1/broker_types.go (1 hunks)
  • docs/09-Configuration reference/02-Custom Resource Definitions.md (1 hunks)

Walkthrough

The pull request introduces documentation updates for the Settings Custom Resource Definition (CRD) in Operator v2. New configuration settings are added for job security contexts, including run-as configurations for containers and init-containers. Additionally, ledger API pagination settings are introduced to control default and maximum page sizes. The documentation structure is refined to provide more explicit type descriptions, enhancing clarity for users configuring the system.

Changes

File Change Summary
docs/09-Configuration reference/01-Settings.md - Added new settings for job security contexts:
- jobs.<owner-kind>.init-containers.<container-name>.run-as
- jobs.<owner-kind>.containers.<container-name>.run-as
- Added ledger API pagination settings:
- ledger.api.default-page-size
- ledger.api.max-page-size
- Updated table header for more descriptive type information
internal/resources/ledgers/deployments.go - Added logic to retrieve and set environment variables for page size settings:
- DEFAULT_PAGE_SIZE
- MAX_PAGE_SIZE
api/formance.com/v1beta1/broker_types.go - Updated comments in BrokerStatus struct to use constants instead of string values for clarity

Sequence Diagram

sequenceDiagram
    participant Settings as Settings CRD
    participant Deployment as Ledger Deployment
    participant Container as Ledger Container

    Settings->>Deployment: Configure page size settings
    Deployment->>Container: Set environment variables
    Container->>Container: Apply pagination configuration
Loading

Assessment against linked issues

Objective Addressed Explanation
Add appropriate settings for pagination (ENG-1577)
Add appropriate settings for job security contexts (ENG-1577)

Poem

🐰 Hop along, config so bright,
Settings dancing with delight!
Page sizes set with rabbit's care,
Security contexts everywhere!
Configuration's magical flight! 🚀


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
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 (3)
internal/resources/ledgers/deployments.go (1)

174-182: Add validation for default page size.

Consider adding validation to ensure the default page size is a positive integer. This will prevent potential issues with invalid values.

 defaultPageSize, err := settings.GetInt(ctx, stack.Name, "ledger", "api", "default-page-size")
 if err != nil {
   return fmt.Errorf("failed to get default page size: %w", err)
 }
-if defaultPageSize != nil {
+if defaultPageSize != nil && *defaultPageSize > 0 {
   container.Env = append(container.Env,
     core.Env("DEFAULT_PAGE_SIZE", fmt.Sprint(*defaultPageSize)),
   )
+} else if defaultPageSize != nil {
+  return fmt.Errorf("default page size must be positive, got: %d", *defaultPageSize)
 }
docs/09-Configuration reference/01-Settings.md (2)

26-27: Enhance documentation for pagination settings.

Consider adding:

  1. Example values for both settings
  2. More detailed descriptions explaining the impact of these settings
  3. Recommended value ranges or best practices
-| ledger.api.default-page-size                                                             | Int                                                           |                                            | Default api page size                                                                                          |
-| ledger.api.max-page-size                                                                 | Int                                                           |                                            | Max page size                                                                                                  |
+| ledger.api.default-page-size                                                             | Int                                                           | 50                                         | Default number of items per page in API responses. Must be a positive integer.                                  |
+| ledger.api.max-page-size                                                                 | Int                                                           | 1000                                       | Maximum allowed items per page in API responses. Must be greater than or equal to default page size.            |

36-37: Fix markdown formatting issues.

  1. Add blank lines around the table
  2. Replace the plus sign with an asterisk for consistent list formatting
 | caddy.image                                                                              | string                                                        |                                            | Caddy image                                                                                                    |
+
- +                                                                                        | jobs.`<owner-kind>`.init-containers.`<container-name>`.run-as | Map    | user=X, group=X                                                                                                                | Configure the security context for init containers in jobs by specifying the user and group IDs to run as                      |  
+| jobs.`<owner-kind>`.init-containers.`<container-name>`.run-as                           | Map                                                           | user=X, group=X                            | Configure the security context for init containers in jobs by specifying the user and group IDs to run as      |
+
 | jobs.`<owner-kind>`.containers.`<container-name>`.run-as                                 | Map                                                           | user=X, group=X                            | Configure the security context for containers in jobs by specifying the user and group IDs to run as           |
🧰 Tools
🪛 Markdownlint (0.37.0)

37-37: Expected: asterisk; Actual: plus
Unordered list style

(MD004, ul-style)


37-37: Expected: 0; Actual: 1
Unordered list indentation

(MD007, ul-indent)


36-36: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6727093 and 56b988f.

📒 Files selected for processing (2)
  • docs/09-Configuration reference/01-Settings.md (1 hunks)
  • internal/resources/ledgers/deployments.go (1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.37.0)
docs/09-Configuration reference/01-Settings.md

37-37: Expected: asterisk; Actual: plus
Unordered list style

(MD004, ul-style)


37-37: Expected: 0; Actual: 1
Unordered list indentation

(MD007, ul-indent)


36-36: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

Comment on lines +184 to +192
maxPageSize, err := settings.GetInt(ctx, stack.Name, "ledger", "api", "max-page-size")
if err != nil {
return fmt.Errorf("failed to get max page size: %w", err)
}
if maxPageSize != nil {
container.Env = append(container.Env,
core.Env("MAX_PAGE_SIZE", fmt.Sprint(*maxPageSize)),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for max page size and its relationship with default page size.

Consider adding validation to ensure:

  1. The max page size is a positive integer
  2. The max page size is greater than or equal to the default page size (when both are set)
 maxPageSize, err := settings.GetInt(ctx, stack.Name, "ledger", "api", "max-page-size")
 if err != nil {
   return fmt.Errorf("failed to get max page size: %w", err)
 }
-if maxPageSize != nil {
+if maxPageSize != nil && *maxPageSize > 0 {
+  if defaultPageSize != nil && *maxPageSize < *defaultPageSize {
+    return fmt.Errorf("max page size (%d) must be greater than or equal to default page size (%d)", *maxPageSize, *defaultPageSize)
+  }
   container.Env = append(container.Env,
     core.Env("MAX_PAGE_SIZE", fmt.Sprint(*maxPageSize)),
   )
+} else if maxPageSize != nil {
+  return fmt.Errorf("max page size must be positive, got: %d", *maxPageSize)
 }

Committable suggestion skipped: line range outside the PR's diff.

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: 0

🧹 Nitpick comments (1)
api/formance.com/v1beta1/broker_types.go (1)

43-44: Consider aligning kubebuilder validation with constant references

While the documentation update to use constant references (ModeOneStreamByService and ModeOneStreamByStack) improves maintainability, the kubebuilder validation still uses string literals. Consider updating the validation to use the constants for consistency.

-//+kubebuilder:validation:Enum:={OneStreamByService, OneStreamByStack}
+//+kubebuilder:validation:Enum:={ModeOneStreamByService, ModeOneStreamByStack}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 56b988f and fa111fb.

📒 Files selected for processing (1)
  • api/formance.com/v1beta1/broker_types.go (1 hunks)

@gfyrag gfyrag force-pushed the feat/ledger-page-sizes branch from fa111fb to 160d0e3 Compare January 7, 2025 08:47
@gfyrag gfyrag enabled auto-merge January 7, 2025 08:48
@gfyrag gfyrag added this pull request to the merge queue Jan 7, 2025
Merged via the queue into main with commit e603a1c Jan 7, 2025
6 of 7 checks passed
@gfyrag gfyrag deleted the feat/ledger-page-sizes branch January 7, 2025 08:52
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