-
Notifications
You must be signed in to change notification settings - Fork 7
PCSM-219: Align all env var config with CLI and HTTP request options #165
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
base: main
Are you sure you want to change the base?
Conversation
- Add github.com/spf13/viper to go.mod - Create config/config.go with Init() function - Bind env vars for global options only (not clone tuning) PCSM-219: Integrate Viper with Cobra for logging and server options - Call config.Init() in PersistentPreRun - Use Viper for log-level, log-json, no-color flags - Use Viper for source/target URIs and port - Simplify getPort() to use Viper with env var fallback
- Add --mongodb-cli-operation-timeout persistent flag (NOT hidden) - Update MongoDBOperationTimeout() to use Viper - Add deprecated alias OperationMongoDBCliTimeout() for backward compat
- Add --use-collection-bulk-write hidden persistent flag - Update UseCollectionBulkWrite() to use Viper - Env var PCSM_USE_COLLECTION_BULK_WRITE still supported
- Add --clone-num-parallel-collections hidden flag - Add --clone-num-read-workers hidden flag - Add --clone-num-insert-workers hidden flag - Add --clone-segment-size hidden flag - Add --clone-read-batch-size hidden flag - All clone tuning options use Viper (CLI only, no env var support)
- Add github.com/go-playground/validator/v10 dependency - Create validate/validate.go with singleton validator - Create validate/errors.go with error types and translation - Create validate/bytesize.go with custom byte size validators
- Extend pcsm.StartOptions with clone tuning fields - Update startRequest with clone tuning fields and validation tags - Add Validate() method to startRequest - Add resolveStartOptions() to merge HTTP/CLI/config values - Add resolveCloneSegmentSize/resolveCloneReadBatchSize helpers - HTTP values take precedence over CLI values
- Add --mongodb-cli-operation-timeout to PCSM Options - Update Environment Variables section with table format - Add Clone Tuning Options section with CLI/HTTP parameters - Update HTTP API /start with clone tuning parameters documentation
- Make --port a persistent flag (inherited by all subcommands) - Remove duplicate port flag definitions from subcommands - Simplify getPort() to use Viper directly (handles CLI > env var > default) - Remove unused pflag import
- Add configuration reference table to config/config.go (single source of truth) - Remove redundant config source comments from config/values.go - Remove references to external decision documents - Simplify function comments to describe behavior, not configuration
- Replace decision references with self-documenting comments - Comments now describe what/why, not where it was decided
- Remove getPort() wrapper, use viper.GetInt("port") directly
- Remove unused GetString, GetInt, GetBool, IsSet wrappers from config/config.go
- These wrappers added no value (pure pass-through with no added logic)
PCSM-219: Update VSCode settings and README with additional config options PCSM-219: Fix
| } | ||
|
|
||
| // validateByteSizeMin validates minimum byte size. | ||
| // Tag usage: bytesizemin=16MB |
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.
🚫 [golangci] reported by reviewdog 🐶
Comment should end in a period (godot)
| } | ||
|
|
||
| // validateByteSizeMax validates maximum byte size. | ||
| // Tag usage: bytesizemax=64GiB |
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.
🚫 [golangci] reported by reviewdog 🐶
Comment should end in a period (godot)
| // registerTagNameFunc uses JSON tag names in error messages. | ||
| func registerTagNameFunc(v *validator.Validate) { | ||
| v.RegisterTagNameFunc(func(fld reflect.StructField) string { | ||
| name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0] |
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.
🚫 [golangci] reported by reviewdog 🐶
Magic number: 2, in detected (mnd)
| case "required": | ||
| return "is required" | ||
| case "gte": | ||
| return fmt.Sprintf("must be at least %s", e.Param()) |
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.
🚫 [golangci] reported by reviewdog 🐶
string-format: fmt.Sprintf can be replaced with string concatenation (perfsprint)
| case "gte": | ||
| return fmt.Sprintf("must be at least %s", e.Param()) | ||
| case "lte": | ||
| return fmt.Sprintf("must be at most %s", e.Param()) |
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.
🚫 [golangci] reported by reviewdog 🐶
string-format: fmt.Sprintf can be replaced with string concatenation (perfsprint)
| case "lte": | ||
| return fmt.Sprintf("must be at most %s", e.Param()) | ||
| case "min": | ||
| return fmt.Sprintf("must be at least %s", e.Param()) |
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.
🚫 [golangci] reported by reviewdog 🐶
string-format: fmt.Sprintf can be replaced with string concatenation (perfsprint)
| return err | ||
| } | ||
|
|
||
| var errs ValidationErrors |
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.
🚫 [golangci] reported by reviewdog 🐶
Consider pre-allocating errs (prealloc)
| IncludeNamespaces: params.IncludeNamespaces, | ||
| ExcludeNamespaces: params.ExcludeNamespaces, | ||
| // Validate request | ||
| if err := params.Validate(); err != nil { |
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.
🚫 [golangci] reported by reviewdog 🐶
avoid inline error handling using if err := ...; err != nil; use plain assignment err := ... (noinlineerr)
|
|
||
| // Validate validates the startRequest. | ||
| func (r *startRequest) Validate() error { | ||
| return validate.Struct(r) |
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.
🚫 [golangci] reported by reviewdog 🐶
error returned from external package is unwrapped: sig: func github.com/percona/percona-clustersync-mongodb/validate.Struct(s any) error (wrapcheck)
Configuration Management:
Environment Variable Renaming (Backward Compatible):
All legacy env var names continue to work with deprecation warnings logged at startup.