keda
keda copied to clipboard
[WIP] Generic parameter parser for scalers
This PR intends to further improve the work related to refactoring of scalers accomplished by https://github.com/kedacore/keda/pull/5319 and https://github.com/kedacore/keda/pull/5228. This depends on https://github.com/kedacore/keda/pull/5319 and requires a rebase after that PR merges first because this contains commits from that PR.
All unique changes proposed here are in the last commit https://github.com/kedacore/keda/pull/5388/commits/f03313c69ce29d56066d8eb896d55acb2c67e46e can be summarized in following points:
- dropping reflections argument from
getParameterFromConfigV2in favour of generics - adding a type constraint to catch bugs from calling
getParameterFromConfigV2with types not supported byconvertToTypeduring compile time - implicit type conversion so the rest of the code doesn't need type assertions
this means following invocation changes from
activationLagThreshold, err := getParameterFromConfigV2(config, activationLagThresholdMetricName, true, false, false, true, int64(defaultKafkaActivationLagThreshold), reflect.TypeOf(int64(64)))
if activationLagThreshold.(int64) < 0 {
...
}
to slightly simpler
activationLagThreshold, err := getParameterFromConfigV2(config, activationLagThresholdMetricName, true, false, false, true, defaultKafkaActivationLagThreshold)
if activationLagThreshold < 0 {
...
}
Checklist
- [x] I have verified that my change is according to the deprecations & breaking changes policy
- [x] Tests have been added
- [ ] Changelog has been updated and is aligned with our changelog requirements
- [x] Commits are signed with Developer Certificate of Origin (DCO - learn more)
Relates to https://github.com/kedacore/keda/issues/5037