-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Agent] Support for config constraints #17112
[Agent] Support for config constraints #17112
Conversation
Pinging @elastic/ingest-management (Project:fleet) |
if err := filter(ast); err != nil { | ||
return errors.New(err, "failed to filter configuration", errors.TypeConfig) | ||
} | ||
} |
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.
Maybe we should log when a constrains fails?
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.
I think I did not correctly express my requirement here, my bad.
The above code do log when a constraint fails, but I think we should also log when a constraints matches and we filter content.
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.
A few small changes:
- Adding logger when a constrains disable configuration?
- Initialize the var store and the methods once?
osKernelKey = "os.kernel" | ||
osPlatformKey = "os.platform" | ||
osVersionKey = "os.version" | ||
) |
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.
Can you add a documentation with the variables that are accessible in the configuration?
This will be useful when writing the documentation and also when we implement them in UI.
regs := boolexp.NewMethodsReg() | ||
if err := regs.Register(validateVersionFuncName, regValidateVersion); err != nil { | ||
return false, err | ||
} |
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.
This could be defined once and reused?
return false, err | ||
} | ||
|
||
if err := initVarStore(store); err != 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.
Looking a the fields used I think this could be defined once and reused?
The following requires a reboot to change:
// Agent
store.vars[agentIDKey] = agentInfo.AgentID()
store.vars[agentVersionKey] = release.Version()
// Host
store.vars[hostArchKey] = info.Architecture
// Operating system
store.vars[osFamilyKey] = runtime.GOOS
store.vars[osKernelKey] = info.KernelVersion
store.vars[osPlatformKey] = info.OS.Family
store.vars[osVersionKey] = info.OS.Version
@@ -36,6 +36,7 @@ func TestBoolexp(t *testing.T) { | |||
}{ | |||
// Variables | |||
{expression: "%{[hello.var]} == 'hello'", result: true}, | |||
{expression: "%{[hello.var]} != 'hello'", result: false}, |
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.
oops I've missed that :)
807fa81
to
981c2c4
Compare
if isOK, err := evaluateConstraint(constraint); !isOK || err != nil { | ||
if err == nil { | ||
// log only constraint not matching | ||
log.Infof("constraint '%s' not matching for datasource: %v", constraint, datasourceNode.String()) |
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.
We might want to reduce what we want to output to the log to the type of the datasource and id? This is just to make sure we do not expose credentials in the log this could be a problem with metricbeat where datasource have a higher change of containing secrets.
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.
constriant is at datasource level and as such it does not contain type, ID is optional for now. i think namespace, output is a identifying configuration and id if present will be logged
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.
sound good ^
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.
Should this have somewhere a changelog entry?
Could you update the PR description with more details on what is actually done in this PR and how? At the moment it references to 3 different issues.
@@ -80,6 +80,10 @@ func getInfoFromStore(s ioStore) (*persistentAgentInfo, error) { | |||
errors.M(errors.MetaKeyPath, AgentConfigFile)) | |||
} | |||
|
|||
if err := reader.Close(); err != 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.
How is this related to this PR?
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.
this fixes an issue on windows i experienced on tests by introducing more extensive use of agentInfo.ID()
@@ -118,6 +122,10 @@ func updateAgentInfo(s ioStore, agentInfo *persistentAgentInfo) error { | |||
errors.M(errors.MetaKeyPath, AgentConfigFile)) | |||
} | |||
|
|||
if err := reader.Close(); err != 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.
How is this related to this PR?
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.
same as ^^^
Good comment, I've missed that.. I need to update my local checklist for PR review. |
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.
LGTM, Missing changelog entry.
[Agent] Support for config constraints (#17112) (cherry picked from commit e0370f6) Co-authored-by: Michal Pristas <[email protected]>
What does this PR do?
Followup tohttps://github.com//issues/15690.
This PR introduces contraints as described in this issue: #16409
This PR enhances emitter not only to use decorators to enrich configuration but filters to modify ast by dropping some nodes.
It introduces also constraints filter which loads all datasets and for those which contain constraint node parses this nodes and uses existing boolexp implementation to evaluate expressions.
It also allows user to use some basic variables such as
agent.id
,agent.version
and such.Nodes containing constraints section and where constraint is evaluated as FALSE, these nodes are dropped.
Checklist
Fixes: #16409