Skip to content

Conversation

@chupe
Copy link
Collaborator

@chupe chupe commented Dec 18, 2025

PCSM-219 Powered by Pull Request Badge

Configuration Management:

  • Integrated Viper with Cobra for unified config handling (CLI flags → env vars → defaults)
  • Added hidden CLI flags for clone/replication tuning (--clone-parallelism, --clone-read-workers, etc.)
  • Extended HTTP API /start endpoint to accept tuning parameters
  • Added value range validation for numeric tuning options
    Environment Variable Renaming (Backward Compatible):
Old Name New Name
PCSM_CLONE_NUM_PARALLEL_COLLECTIONS PCSM_CLONE_PARALLELISM
PCSM_CLONE_NUM_READ_WORKERS PCSM_CLONE_READ_WORKERS
PCSM_CLONE_NUM_INSERT_WORKERS PCSM_CLONE_INSERT_WORKERS
PCSM_CLONE_READ_BATCH_BYTES PCSM_CLONE_READ_BATCH_SIZE
PCSM_USE_COLLECTION_BULK_WRITE PCSM_USE_LEGACY_BULK_WRITE
PCSM_MONGODB_CLI_OPERATION_TIMEOUT PCSM_MONGODB_OPERATION_TIMEOUT

All legacy env var names continue to work with deprecation warnings logged at startup.

chupe added 13 commits December 23, 2025 20:18
- 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
Copy link
Contributor

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
Copy link
Contributor

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]
Copy link
Contributor

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())
Copy link
Contributor

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())
Copy link
Contributor

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())
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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)

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