-
Notifications
You must be signed in to change notification settings - Fork 2
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): specify machine type and concurrency info of worker through env vars #884
Conversation
WalkthroughThe changes introduce multiple new fields to the Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant CFG as Config Loader
participant IB as initBatch Function
participant BC as BatchConfig
participant BR as BatchRepo (SubmitJob)
participant GCP as GCP Batch Service
App->>CFG: Load configuration values
CFG->>IB: Provide config (incl. worker fields)
IB->>BC: Convert string values & initialize BatchConfig
BC->>BR: Pass configuration for batch processing
BR->>GCP: Submit job with BootDiskSizeGB, BootDiskType, MachineType, TaskCount
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (2)
✨ Finishing Touches
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
Documentation and Community
|
✅ Deploy Preview for reearth-flow canceled.
|
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 (2)
server/api/internal/app/repo.go (1)
113-119
: Consider using a helper function for string to int conversion.The conversion logic for
MaxConcurrency
is duplicated withTaskCount
. Consider extracting this into a helper function to improve code maintainability and reduce duplication.Apply this diff to extract the conversion logic:
+func convertToInt(value string, fieldName string) int { + result, err := strconv.Atoi(value) + if err != nil { + log.Fatalf("Failed to convert %s: %v", fieldName, err) + } + return result +} func initBatch(ctx context.Context, conf *config.Config) (batchRepo gateway.Batch) { var err error if conf.Worker_ImageURL != "" { config := gcpbatch.BatchConfig{ BinaryPath: conf.Worker_BinaryPath, ImageURI: conf.Worker_ImageURL, MachineType: conf.Worker_MachineType, - MaxConcurrency: func() int { - mc, err := strconv.Atoi(conf.Worker_MaxConcurrency) - if err != nil { - log.Fatalf("Failed to convert MaxConcurrency: %v", err) - } - return mc - }(), + MaxConcurrency: convertToInt(conf.Worker_MaxConcurrency, "MaxConcurrency"), ProjectID: conf.GCPProject, Region: conf.GCPRegion, SAEmail: conf.Worker_BatchSAEmail, - TaskCount: func() int { - tc, err := strconv.Atoi(conf.Worker_TaskCount) - if err != nil { - log.Fatalf("Failed to convert TaskCount: %v", err) - } - return tc - }(), + TaskCount: convertToInt(conf.Worker_TaskCount, "TaskCount"), }server/api/internal/app/config/config.go (1)
75-77
: Consider using integer types for numeric configurations.The
Worker_MaxConcurrency
andWorker_TaskCount
fields are defined as strings but represent numeric values. Consider using integer types with string tags for better type safety and to avoid runtime conversion errors.Apply this diff to use integer types:
- Worker_MaxConcurrency string `envconfig:"WORKER_MAX_CONCURRENCY" default:"4" pp:",omitempty"` - Worker_TaskCount string `envconfig:"WORKER_TASK_COUNT" default:"1" pp:",omitempty"` + Worker_MaxConcurrency int `envconfig:"WORKER_MAX_CONCURRENCY" default:"4" pp:",omitempty"` + Worker_TaskCount int `envconfig:"WORKER_TASK_COUNT" default:"1" pp:",omitempty"`This change would require updating the
initBatch
function to remove the string to int conversion:// In server/api/internal/app/repo.go config := gcpbatch.BatchConfig{ BinaryPath: conf.Worker_BinaryPath, ImageURI: conf.Worker_ImageURL, MachineType: conf.Worker_MachineType, - MaxConcurrency: convertToInt(conf.Worker_MaxConcurrency, "MaxConcurrency"), + MaxConcurrency: conf.Worker_MaxConcurrency, ProjectID: conf.GCPProject, Region: conf.GCPRegion, SAEmail: conf.Worker_BatchSAEmail, - TaskCount: convertToInt(conf.Worker_TaskCount, "TaskCount"), + TaskCount: conf.Worker_TaskCount, }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.work.sum
is excluded by!**/*.sum
📒 Files selected for processing (3)
server/api/internal/app/config/config.go
(3 hunks)server/api/internal/app/repo.go
(2 hunks)server/api/internal/infrastructure/gcpbatch/batch.go
(3 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
server/api/internal/app/repo.go
110-110: File is not goimports
-ed
(goimports)
server/api/internal/app/config/config.go
35-35: File is not goimports
-ed
(goimports)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: ci-api / ci-api-test
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: 3
♻️ Duplicate comments (1)
server/api/internal/infrastructure/gcpbatch/batch.go (1)
21-31
: 🛠️ Refactor suggestionAdd field validation in BatchConfig.
The struct fields lack validation for their values.
+func (c *BatchConfig) Validate() error { + if c.BootDiskSizeGB <= 0 { + return fmt.Errorf("BootDiskSizeGB must be greater than 0") + } + if c.TaskCount <= 0 { + return fmt.Errorf("TaskCount must be greater than 0") + } + if !regexp.MustCompile(`^[a-z][a-z0-9]*-[a-z0-9-]*$`).MatchString(c.MachineType) { + return fmt.Errorf("invalid machine type format") + } + return nil +}
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
server/api/internal/app/config/config.go
(3 hunks)server/api/internal/app/repo.go
(2 hunks)server/api/internal/infrastructure/gcpbatch/batch.go
(2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
server/api/internal/app/repo.go
110-110: File is not goimports
-ed
(goimports)
server/api/internal/app/config/config.go
35-35: File is not goimports
-ed
(goimports)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: ci-api / ci-api-test
🔇 Additional comments (1)
server/api/internal/infrastructure/gcpbatch/batch.go (1)
137-146
: LGTM! Well-structured boot disk configuration.The implementation of boot disk configuration is clean and properly uses the new configuration fields.
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