keda icon indicating copy to clipboard operation
keda copied to clipboard

[WIP] Generic parameter parser for scalers

Open wozniakjan opened this issue 1 year ago • 0 comments

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 getParameterFromConfigV2 in favour of generics
  • adding a type constraint to catch bugs from calling getParameterFromConfigV2 with types not supported by convertToType during 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

Relates to https://github.com/kedacore/keda/issues/5037

wozniakjan avatar Jan 16 '24 18:01 wozniakjan