Commit 6a83aefd authored by Faho Shubladze's avatar Faho Shubladze Committed by Leo Ahnn
Browse files

Fixed plugin status overload issue

cr: https://code.amazon.com/reviews/CR-55342854
parent a6736534
......@@ -451,7 +451,7 @@ func (r *Processor) pluginExecutionReport(
outputs map[string]*contracts.PluginResult,
totalNumberOfPlugins int) {
_, _, runtimeStatuses := contracts.DocumentResultAggregator(log, pluginID, outputs)
_, _, _, runtimeStatuses := contracts.DocumentResultAggregator(log, pluginID, outputs)
outputContent, err := jsonutil.Marshal(runtimeStatuses)
if err != nil {
log.Error("could not marshal plugin outputs! ", err)
......@@ -496,7 +496,7 @@ func (r *Processor) associationExecutionReport(
errorCode string,
associationStatus string) {
_, _, runtimeStatuses := contracts.DocumentResultAggregator(log, "", outputs)
_, _, _, runtimeStatuses := contracts.DocumentResultAggregator(log, "", outputs)
runtimeStatusesContent, err := jsonutil.Marshal(runtimeStatuses)
if err != nil {
log.Error("could not marshal plugin outputs ", err)
......
......@@ -62,16 +62,17 @@ func prepareRuntimeStatus(log log.T, pluginResult PluginResult) PluginRuntimeSta
// DocumentResultAggregator aggregates the result from the plugins to construct the agent response
func DocumentResultAggregator(log log.T,
pluginID string,
pluginOutputs map[string]*PluginResult) (ResultStatus, map[string]int, map[string]*PluginRuntimeStatus) {
pluginOutputs map[string]*PluginResult) (documentStatus ResultStatus, runtimeStatusCounts map[string]int,
runtimeStatusesFiltered map[string]*PluginRuntimeStatus, runtimeStatuses map[string]*PluginRuntimeStatus) {
runtimeStatuses := make(map[string]*PluginRuntimeStatus)
runtimeStatuses = make(map[string]*PluginRuntimeStatus)
for pluginID, pluginResult := range pluginOutputs {
rs := prepareRuntimeStatus(log, *pluginResult)
runtimeStatuses[pluginID] = &rs
}
// TODO instance this needs to be revised to be in parity with ec2config
documentStatus := ResultStatusSuccess
var runtimeStatusCounts = map[string]int{}
documentStatus = ResultStatusSuccess
runtimeStatusCounts = map[string]int{}
pluginCounts := len(runtimeStatuses)
for _, pluginResult := range runtimeStatuses {
......@@ -109,14 +110,18 @@ func DocumentResultAggregator(log log.T,
documentStatus = ResultStatusInProgress
}
runtimeStatusesFiltered := make(map[string]*PluginRuntimeStatus)
runtimeStatusesFiltered = make(map[string]*PluginRuntimeStatus)
// When pluginID isn't empty, the agent is sending update information about the current plugin.
// When it's empty, the agent is sending update information about the document.
// When it's empty, the agent only sends plugin status if it's a single plugin invocation.
if pluginID != "" {
runtimeStatusesFiltered[pluginID] = runtimeStatuses[pluginID]
} else {
runtimeStatuses = runtimeStatusesFiltered
} else if len(runtimeStatuses) <= 1 {
runtimeStatusesFiltered = runtimeStatuses
}
return documentStatus, runtimeStatusCounts, runtimeStatusesFiltered
return documentStatus, runtimeStatusCounts, runtimeStatusesFiltered, runtimeStatuses
}
......@@ -122,8 +122,8 @@ func TestDocumentStatus(t *testing.T) {
},
}
for _, tstCase := range testCases {
status1, _, _ := DocumentResultAggregator(logger, "aws:runScript", tstCase.Input)
status2, _, _ := DocumentResultAggregator(logger, "", tstCase.Input)
status1, _, _, _ := DocumentResultAggregator(logger, "aws:runScript", tstCase.Input)
status2, _, _, _ := DocumentResultAggregator(logger, "", tstCase.Input)
assert.Equal(t, status1, ResultStatusInProgress)
assert.Equal(t, status2, tstCase.Output)
}
......@@ -157,6 +157,6 @@ func TestDocumentStatusCount(t *testing.T) {
"Success": 1,
"Failed": 1,
}
_, statusCount, _ := DocumentResultAggregator(logger, "", input)
_, statusCount, _, _ := DocumentResultAggregator(logger, "", input)
assert.Equal(t, statusCount, output)
}
......@@ -75,7 +75,7 @@ func run(context context.T,
for res := range statusChan {
results[res.PluginID] = &res
//TODO decompose this function to return only Status
status, _, _ := contracts.DocumentResultAggregator(context.Log(), res.PluginID, results)
status, _, _, _ := contracts.DocumentResultAggregator(context.Log(), res.PluginID, results)
docResult := contracts.DocumentResult{
Status: status,
PluginResults: results,
......@@ -98,7 +98,7 @@ func run(context context.T,
pluginOutputContent, _ := jsonutil.Marshal(outputs)
context.Log().Debugf("Plugin outputs %v", jsonutil.Indent(pluginOutputContent))
//send DocLevel response
status, _, _ := contracts.DocumentResultAggregator(context.Log(), "", outputs)
status, _, _, _ := contracts.DocumentResultAggregator(context.Log(), "", outputs)
result := contracts.DocumentResult{
Status: status,
PluginResults: outputs,
......
......@@ -198,7 +198,7 @@ func (p *WorkerBackend) pluginListener(statusChan chan contracts.PluginResult) {
var result = res
results[res.PluginID] = &result
//TODO move the aggregator under executer package and protect it, there's global lock in this package
status, _, _ := contracts.DocumentResultAggregator(log, res.PluginID, results)
status, _, _, _ := contracts.DocumentResultAggregator(log, res.PluginID, results)
docResult := contracts.DocumentResult{
Status: status,
PluginResults: results,
......@@ -209,7 +209,7 @@ func (p *WorkerBackend) pluginListener(statusChan chan contracts.PluginResult) {
p.input <- replyMessage
}
log.Info("document execution complete")
finalStatus, _, _ = contracts.DocumentResultAggregator(log, "", results)
finalStatus, _, _, _ = contracts.DocumentResultAggregator(log, "", results)
}
......
......@@ -289,7 +289,7 @@ func orchestrationDirCleanup(context context.T, pluginsCount int, pluginOutputs
if pluginsCount == len(pluginOutputs) {
// this will clean the orchestration folder for the successful and failed document executions only when the agent is configured
orchestrationDirectoryCleanupConfig := context.AppConfig().Ssm.OrchestrationDirectoryCleanup
documentResult, _, _ := contracts.DocumentResultAggregator(log, "", pluginOutputs)
documentResult, _, _, _ := contracts.DocumentResultAggregator(log, "", pluginOutputs)
statusWithCleanupConfig := map[contracts.ResultStatus]map[string]interface{}{
contracts.ResultStatusSuccess: {appconfig.OrchestrationDirCleanupForSuccessCommand: nil, appconfig.OrchestrationDirCleanupForSuccessFailedCommand: nil},
contracts.ResultStatusFailed: {appconfig.OrchestrationDirCleanupForSuccessFailedCommand: nil},
......
......@@ -25,7 +25,7 @@ import (
// build SendReply Payload from the internal plugins map
func FormatPayload(log log.T, pluginID string, agentInfo contracts.AgentInfo, outputs map[string]*contracts.PluginResult) messageContracts.SendReplyPayload {
status, statusCount, runtimeStatuses := contracts.DocumentResultAggregator(log, pluginID, outputs)
status, statusCount, runtimeStatuses, _ := contracts.DocumentResultAggregator(log, pluginID, outputs)
additionalInfo := contracts.AdditionalInfo{
Agent: agentInfo,
DateTime: times.ToIso8601UTC(time.Now()),
......
......@@ -9,27 +9,10 @@
},
"dateTime": "2015-07-09T23:23:40.023Z",
"runtimeStatusCounts": {
"Success": 2
}
},
"documentStatus": "Success",
"documentTraceOutput": "",
"runtimeStatus": {
"runPowerShellScript1": {
"code": 0,
"name": "aws:runPowerShellScript",
"status": "Success",
"output": "standard output of test case\n----------ERROR-------\nstandard error of test case",
"startDateTime": "2015-07-09T23:23:39.019Z",
"endDateTime": "2015-07-09T23:23:39.023Z"
},
"runPowerShellScript2": {
"code": 0,
"name": "aws:runPowerShellScript",
"status": "Success",
"output": "standard output of test case\n----------ERROR-------\nstandard error of test case",
"startDateTime": "2015-07-09T23:23:39.019Z",
"endDateTime": "2015-07-09T23:23:39.023Z"
}
}
}
\ No newline at end of file
......@@ -9,28 +9,10 @@
},
"dateTime": "2015-07-09T23:23:40.023Z",
"runtimeStatusCounts": {
"Skipped": 1,
"Success": 1
}
},
"documentStatus": "Success",
"documentTraceOutput": "",
"runtimeStatus": {
"runPowerShellScript1": {
"code": 0,
"name": "aws:runPowerShellScript",
"status": "Skipped",
"output": "Step execution skipped due to unsatisfied preconditions",
"startDateTime": "2015-07-09T23:23:39.019Z",
"endDateTime": "2015-07-09T23:23:39.023Z"
},
"runPowerShellScript2": {
"code": 0,
"name": "aws:runPowerShellScript",
"status": "Success",
"output": "standard output of test case\n----------ERROR-------\nstandard error of test case",
"startDateTime": "2015-07-09T23:23:39.019Z",
"endDateTime": "2015-07-09T23:23:39.023Z"
}
}
}
\ No newline at end of file
......@@ -142,6 +142,12 @@ func verifyRunCommandOutput(suite *RunCommandOutputTestSuite,
c <- 1
} else if sendReplyPayload.DocumentStatus == expectedResultStatus {
foundPlugin := false
runTimeStatusCount := 0
for _, counts := range sendReplyPayload.AdditionalInfo.RuntimeStatusCounts {
runTimeStatusCount += counts
}
if runTimeStatusCount <= 1 {
for _, pluginStatus := range sendReplyPayload.RuntimeStatus {
if pluginStatus.Status == expectedResultStatus {
foundPlugin = true
......@@ -150,6 +156,11 @@ func verifyRunCommandOutput(suite *RunCommandOutputTestSuite,
assert.Equal(suite.T(), pluginStatus.Code, code, "Exit code is %v expected %v", pluginStatus.Code, code)
}
}
} else {
suite.T().Log("For multiple plugin docs, last sendreply contains empty plugin runtime status map.")
foundPlugin = true
}
if !foundPlugin {
suite.T().Errorf("Couldn't find plugin with result status %v", expectedResultStatus)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment