hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

refactor: move config defaults from TOML files to `Default` trait

Open SanchithHegde opened this issue 3 years ago • 2 comments

Type of Change

  • [ ] Bugfix
  • [ ] New feature
  • [ ] Enhancement
  • [x] Refactoring
  • [ ] Dependency updates

Description

This PR moves default values for router and drainer binaries' configuration from the defaults.toml files to the implementation of the Default trait. Since we add a #[serde(default)] to the Settings struct, it will use the Default trait implementation to provide the default values.

Motivation and Context

This should help catch errors in the default configuration values during compilation, and help reduce binary size.

How did you test it?

Ran the router and drainer binaries, verified that they both work with the current defaults provided.

Checklist

  • [x] I formatted the code cargo +nightly fmt --all
  • [x] I addressed lints thrown by cargo clippy
  • [x] I reviewed submitted code
  • [ ] I added unit tests for my changes where possible
  • [ ] I added a CHANGELOG entry if applicable

SanchithHegde avatar Jan 11 '23 10:01 SanchithHegde

There are some mandatory field needs to configured in the ENV's, for those we can't provide default values. This approach will fail for those cases.

We need to check in compile time only for field where we can assign defaults and not all.

Example: Database username is mandatory field needs to passed and we can't assign a default to it.

Yes, I did think of this problem when making this change, and intentionally used String::new() for such fields.

One solution that I can think of is that we can perform checks on startup to verify that these required fields are present and are not empty. What do you think?

SanchithHegde avatar Jan 11 '23 10:01 SanchithHegde

Assign defaults to all fields and in runtime evaluate the values are not equal to deaults

jarnura avatar Jan 11 '23 10:01 jarnura