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(api): support allowedlocation for batch worker #898

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

pyshx
Copy link
Contributor

@pyshx pyshx commented Feb 21, 2025

Overview

What I've done

What I haven't done

How I tested

Screenshot

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Introduced an option to specify allowed locations for worker assignments, consolidating previous individual worker settings.
  • Refactor

    • Streamlined the job initialization process with enhanced validation of mandatory configuration values.
    • Improved error handling and resource parsing during job submission for increased reliability.

Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

The changes involve updates to the configuration and job submission logic. A new field, Worker_AllowedLocations, has been added to the Config struct, enhancing location-based settings for workers. The initBatch function now includes stricter validation for essential configuration values, improved error handling for numeric settings, and incorporates the new allowed locations into the batch configuration. Additionally, the job submission process has been modified to utilize the allowed locations during job allocation.

Changes

File(s) Change Summary
server/api/.../config/config.go Added new field Worker_AllowedLocations []string in the Config struct; existing fields such as Worker_BatchSAEmail, Worker_BinaryPath, Worker_BootDiskSizeGB, Worker_BootDiskType, Worker_ImageURL, Worker_MachineType, Worker_MaxConcurrency, and Worker_TaskCount retained.
server/api/.../repo.go Refactored the initBatch function: returns early if Worker_ImageURL is empty; added validations for GCPProject and GCPRegion; implemented dedicated parsing for boot disk size and task count with error handling; updated the batch configuration to include allowed locations; simplified the return statement.
server/api/.../infrastructure/gcpbatch/batch.go Introduced AllowedLocations []string in the BatchConfig struct; modified the SubmitJob method to build an allocation policy that utilizes the new AllowedLocations field during job submission.

Sequence Diagram(s)

sequenceDiagram
    participant Repo as initBatch
    participant Config as Config Struct
    participant BatchCfg as BatchConfig
    participant BatchRepo as BatchRepo
    participant GCP as GCP Service

    Repo->>Config: Retrieve configuration (includes Worker_AllowedLocations)
    alt If Worker_ImageURL is empty
        Repo->>Repo: Return nil (exit early)
    else
        Repo->>Config: Validate GCPProject and GCPRegion
        Repo->>Repo: Parse boot disk size & task count with error handling
        Repo->>BatchCfg: Build BatchConfig (with AllowedLocations)
        Repo->>BatchRepo: Initialize BatchRepo with BatchConfig
        BatchRepo->>GCP: Submit job using AllowedLocations in allocation policy
    end
Loading

Possibly related PRs

Poem

I’m a code rabbit, hopping on a trace,
Guiding new fields to a brand-new place,
Old worker settings fade with the light,
Allowed locations now make things right.
With clarity in each function and call,
Happy hops in the batch, big changes for all!
🐰✨


📜 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 f9334d6 and 64cd0ed.

📒 Files selected for processing (2)
  • server/api/internal/app/config/config.go (1 hunks)
  • server/api/internal/infrastructure/gcpbatch/batch.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • server/api/internal/infrastructure/gcpbatch/batch.go
  • server/api/internal/app/config/config.go

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.

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

netlify bot commented Feb 21, 2025

Deploy Preview for reearth-flow canceled.

Name Link
🔨 Latest commit 64cd0ed
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/67b82ce85760cf000834c57d

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 (5)
server/api/internal/app/repo.go (5)

107-109: Returning nil for empty Worker_ImageURL may obscure configuration issues.
Consider at least logging a warning or clarifying the intentional skip of batch initialization so that operators or developers are aware that no batch will be set up in this scenario.

 if conf.Worker_ImageURL == "" {
+   log.Warn("initBatch: Worker_ImageURL is empty, skipping GCP Batch initialization")
    return nil
 }

111-116: Mismatch in error handling approach.
Here, missing GCPProject or GCPRegion leads to a fatal log, but missing Worker_ImageURL merely returns nil. Consider unifying the approach—either consistently skip batch setup for all missing fields or fail for all critical fields.


118-121: Consider a fallback default for invalid boot disk size.
Current logic aborts the entire app if the disk size parsing fails. If you want a more graceful approach, consider reverting to a default (e.g., 50GB) instead of killing the process.


123-126: Graceful handling of invalid task count might be desirable.
Like the disk size, a non-numeric or unexpected input immediately terminates the process. A fallback or user-friendly error message might be more suitable for production environments.


141-146: Exiting on NewBatch creation failure.
The approach is consistent with other fatal checks in this function, ensuring issues are discovered early in initialization. If a more forgiving strategy is desired, you could log and return an error instead.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4dd55ea and f9334d6.

📒 Files selected for processing (3)
  • server/api/internal/app/config/config.go (1 hunks)
  • server/api/internal/app/repo.go (1 hunks)
  • server/api/internal/infrastructure/gcpbatch/batch.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Collect information
🔇 Additional comments (4)
server/api/internal/app/repo.go (1)

128-139: Good consistency in constructing the BatchConfig.
The new field AllowedLocations is cleanly integrated, and typed fields for numeric values (e.g., bootDiskSize) enhance clarity.

server/api/internal/app/config/config.go (1)

72-80: Verify numeric fields stored as strings.
Storing parameters like Worker_TaskCount as strings in the config is workable but can be prone to parse errors. You might consider using int-based fields if environment variable parsing supports it, or at least confirm each field is indeed processed correctly.

server/api/internal/infrastructure/gcpbatch/batch.go (2)

21-31: Strong internal typing in BatchConfig.
Using int for BootDiskSizeGB and TaskCount is a good improvement over string-based representations. Also, introducing AllowedLocations []string aligns with the new location constraints.


161-163: Ensuring location policy is applied.
Assigning AllowedLocations to AllocationPolicy_LocationPolicy effectively takes advantage of the newly introduced configuration. If empty, GCP’s batch service will allow default allocations, which can be valid, but verify that’s intended.

@pyshx pyshx merged commit 4d443bb into main Feb 21, 2025
21 checks passed
@pyshx pyshx deleted the feat(api)/support-allowedlocation-for-batch-worker branch February 21, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant