-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor scalers parsing to unify them #5037
Comments
I take a look at some use cases inside keda/pkg/scalers/azure_log_analytics_scaler.go Lines 246 to 255 in faf8c9a
My proposal is to move this helper function to something like |
There are also additional things that needs to be considered.
|
So for this case we are just going to throw out an error right? // getParameterFromConfig gets the parameter from the configs, if checkAuthParams is true
// then AuthParams is also check for the parameter
func getParameterFromConfig(config *ScalerConfig, parameter string, checkAuthParams bool, isOptional bool) (string, error) {
if val, ok := config.AuthParams[parameter]; checkAuthParams && ok && val != "" {
return val, nil
} else if val, ok := config.TriggerMetadata[parameter]; ok && val != "" {
return val, nil
} else if val, ok := config.TriggerMetadata[fmt.Sprintf("%sFromEnv", parameter)]; ok && val != "" {
return config.ResolvedEnv[config.TriggerMetadata[fmt.Sprintf("%sFromEnv", parameter)]], nil
}
// if its an optional field, we can throw out something here, just put empty string as an arbitrary value for now
if isOptional {
return "", nil
}
return "", fmt.Errorf("error parsing metadata. Details: %s was not found in metadata. Check your ScaledObject configuration", parameter) wdyt? |
I think that this can be useful and I agree with the approach of having a single function like getParameterFromConfig with some config parameters, but I'd be more explicit, something like:
There are some parameters that we must read only from secure sources 😄 |
Our discussion on Slack: certGiven, err := getParameterFromConfigV2(config, "cert", false, true, false, true, "", reflect.TypeOf("")) I will give it a try to see if I can make it a little more readable, I'm thinking something along the lines of certGiven, err := getParameterFromConfigV2(config, "cert", USE_AUTHENTICATION | OPTIONAL, "") I'm thinking we can leverage generics to sugar coat the reflections a bit, I guess we it will be hard to get rid of the reflections entirely but maybe we can at least hide them. And then the false, true, false, true - this might actually be a good candidate for masked binary flags, imho those would improve the code readability @zroubalik: func getParameterFromConfigV2(config *ScalerConfig, parameter string, options ...opt.ConfigOption) {}
...
param, err := getParameterFromConfigV2(config, "cert", opt.UseAuth(), opt.Optional(), opt.TypeString()) This is just a draft ^, there might be better names and usage, but I think it is also viable option to think about |
I like the idea of And I took a stab at replacing reflections from the current implementation of |
Thanks @wozniakjan for giving an attempt on this. Coincidently, I also drafted a go at this as well, using the functional option pattern. #5391 . Please help to take a look too 💪 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed due to inactivity. |
@JorTurFer, @dttung2905 I spent some time playing around with a slightly different approach to scalers config parsing and the desired refactor. My efforts are in #5676. I wanted to achieve a similar experience as In high-level terms, this is what I managed to get with an example of some fine-tunning, and I think it might be promising: type MyConfigXYZ struct {
Flag bool `keda:"name=flag, parsingOrder=triggerMetadata"`
Addr string `keda:"name=addr, parsingOrder=triggerMetadata;resolvedEnv, optional"`
Headers map[string]int `keda:"name=headers, parsingOrder=triggerMetadata, optional, default=d"`
}
sc := &scalerconfig.ScalerConfig{ ... }
conf := MyConfigXYZ{}
if err := sc.TypedConfig(conf); err != nil {
...
} |
given #5676 merged, I will continue with refactor of the individual scalers
It looks like there are 59 configs overall, prometheus already taken care of. @dttung2905 given you already worked on kafka, would you like to try that one? I will try first five alphabetically this week
|
@wozniakjan I have created a separate issue to track this. I can start on this kafka later today as well |
Proposal
Currently, each scaler parses the configuration using its own way, some of them use helpers for reading envs, other don't, some use one helper, others use their own helpers...
There is a lot of fragmentation in scalers code and we should unify it
Use-Case
No response
Is this a feature you are interested in implementing yourself?
Maybe
Anything else?
No response
The text was updated successfully, but these errors were encountered: