-
Notifications
You must be signed in to change notification settings - Fork 84
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 Nomad policy parsing and add tests #114
Conversation
policy/nomad/parser.go
Outdated
Target: parseTarget(p.Policy[keyTarget]), | ||
Strategy: parseStrategy(p.Policy[keyStrategy]), | ||
// Policy is enabled by default. | ||
if p.Enabled == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might put the default above in the initializer.
configMapString = make(map[string]string) | ||
|
||
for k, v := range targetAttr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on my phone, can't trace this back, but wanted to make sure that this is only expected to be set if "config" existed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this moving values from targetMap["config"]
(which is a map[string]interface{}
) into configMapString
(which is map[string]string
).
So if "config"
is not set we don't need to do anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested locally and this resolves #99 #98 #71
my only comment would be that the parsing error log formatting is a little weird:
2020-05-04T09:53:10.923+0200 [ERROR] policy_handler.policy_handler: invalid policy: 1 error occurred:
* scaling->policy->source must be string, found []interface {}
: policy_id=f99ca263-7a1e-bc3a-b331-7db33053173f
not sure if there is a way to improve this, or its a by-product of multierror.
Yeah, that's not great. These are validation error messages, so I will improve them in a new PR. |
This PR makes the logic that parses a policy from Nomad into the internal policy representation the Autoscaler uses.
The new parser makes a few assumptions:
scaling->policy->evaluation_interval
defaults to the value ofscan_interval
default_evaluation_time
from the agent config file.Policy.Target.Config
map has the values fromscaling->policy->target->config
(which are defined in the jobspec) merged with the values fromapi.ScalingPolicy.Target
(which are predefined by the Nomad API as the group, job and namespace that has thescaling
stanza). Values in the jobspec have higher priority.api.ScalingPolicy.Target
are copied over toPolicy.Target.Config
asjob_id
andgroup
if they are present yet (i.e., if the jobspec hasjob_id
the value won't be copied over).Open questions:
evaluation_interval
is used in the jobspec andscan_interval
is used in the agent config. Should one of them be renamed so they match?scan_interval
renamed todefault_evaluation_time
.Job
andGroup
seems unnecessary, but there are other parts that rely on them beingjob_id
andgroup
, so I didn't want to change them now. Using them as-is would require users to write them capitalize in the jobspec, which is unusual. Maybe have some automatic case conversion?Closes #99
Closes #98
Closes #71