Skip to content
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

[Ingest-Manager] Fix capabilities resolution in inspect command #24346

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- Fix: Successfully installed and enrolled agent running standalone{pull}[24128]24128
- Make installer atomic on windows {pull}[24253]24253
- Remove installed services on agent uninstall {pull}[24151]24151
- Fix capabilities resolution in inspect command {pull}[24346]24346
- Fix windows installer during enroll {pull}[24343]24343

==== New features
Expand Down
20 changes: 16 additions & 4 deletions x-pack/elastic-agent/pkg/capabilities/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,23 @@ func inputsMap(cfgInputs interface{}, l *logger.Logger) []map[string]interface{}

inputsMap := make([]map[string]interface{}, 0, len(inputsSet))
for _, s := range inputsSet {
mm, ok := s.(map[string]interface{})
if !ok {
switch mm := s.(type) {
case map[string]interface{}:
inputsMap = append(inputsMap, mm)
case map[interface{}]interface{}:
newMap := make(map[string]interface{})
for k, v := range mm {
key, ok := k.(string)
if !ok {
continue
}

newMap[key] = v
}
inputsMap = append(inputsMap, newMap)
default:
continue
}
inputsMap = append(inputsMap, mm)
}

return inputsMap
Expand Down Expand Up @@ -188,7 +200,7 @@ func (c *multiInputsCapability) Apply(in interface{}) (interface{}, error) {

inputsMap, err = c.cleanupInput(inputsMap)
if err != nil {
c.log.Errorf("cleaning up config object failed for capability 'multi-outputs': %v", err)
c.log.Errorf("cleaning up config object failed for capability 'multi-inputs': %v", err)
return in, nil
}

Expand Down
39 changes: 35 additions & 4 deletions x-pack/elastic-agent/pkg/capabilities/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,21 @@ func (c *multiOutputsCapability) cleanupOutput(cfgMap map[string]interface{}) (m
return cfgMap, nil
}

outputsMap, ok := outputsIface.(map[string]interface{})
if !ok {
switch outputsMap := outputsIface.(type) {
case map[string]interface{}:
handleOutputMapStr(outputsMap)
cfgMap[outputKey] = outputsMap
case map[interface{}]interface{}:
handleOutputMapIface(outputsMap)
cfgMap[outputKey] = outputsMap
default:
return nil, fmt.Errorf("outputs must be a map")
}

return cfgMap, nil
}

func handleOutputMapStr(outputsMap map[string]interface{}) {
for outputName, outputIface := range outputsMap {
acceptValue := true

Expand All @@ -208,7 +218,28 @@ func (c *multiOutputsCapability) cleanupOutput(cfgMap map[string]interface{}) (m

delete(outputMap, conditionKey)
}
}

cfgMap[outputKey] = outputsMap
return cfgMap, nil
func handleOutputMapIface(outputsMap map[interface{}]interface{}) {
for outputName, outputIface := range outputsMap {
acceptValue := true

outputMap, ok := outputIface.(map[interface{}]interface{})
if ok {
conditionIface, found := outputMap[conditionKey]
if found {
conditionVal, ok := conditionIface.(bool)
if ok {
acceptValue = conditionVal
}
}
}

if !acceptValue {
delete(outputsMap, outputName)
continue
}

delete(outputMap, conditionKey)
}
}
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/capabilities/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type multiUpgradeCapability struct {
func (c *multiUpgradeCapability) Apply(in interface{}) (interface{}, error) {
upgradeMap := upgradeObject(in)
if upgradeMap == nil {
c.log.Warnf("expecting map config object but got nil for capability 'multi-outputs'")
c.log.Warnf("expecting map config object but got nil for capability 'multi-upgrade'")
// not an upgrade we don't alter origin
return in, nil
}
Expand Down