diff --git a/agent/handlers/task_server_setup_linux_test.go b/agent/handlers/task_server_setup_linux_test.go index 421bd903276..2a76370d492 100644 --- a/agent/handlers/task_server_setup_linux_test.go +++ b/agent/handlers/task_server_setup_linux_test.go @@ -38,7 +38,7 @@ import ( const ( internalError = "internal error" - defaultNetworkInterfaceNameErrorMessage = "failed to obtain default network interface name: unable to obtain default network interface name on host from v3 endpoint ID: %s" + defaultNetworkInterfaceNameErrorMessage = "failed to obtain default network interface name: unable to obtain default network interface name on host from endpoint ID: %s" ) func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) { diff --git a/agent/handlers/v4/tmdsstate_linux.go b/agent/handlers/v4/tmdsstate_linux.go index 42d4af3d203..b5e08f10258 100644 --- a/agent/handlers/v4/tmdsstate_linux.go +++ b/agent/handlers/v4/tmdsstate_linux.go @@ -26,7 +26,7 @@ import ( ) const ( - defaultNetworkInterfaceNameNotFoundError = "unable to obtain default network interface name on host from v3 endpoint ID: %s" + defaultNetworkInterfaceNameNotFoundError = "unable to obtain default network interface name on host from endpoint ID: %s" ) // Returns task metadata including the task network configuration in v4 format for the diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go index fe914cd37a4..26f6d1bc806 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go @@ -53,7 +53,7 @@ const ( requestTimedOutError = "%s: request timed out" // This is our initial assumption of how much time it would take for the Linux commands used to inject faults // to finish. This will be confirmed/updated after more testing. - requestTimeoutDuration = 5 + requestTimeoutSeconds = 5 // Commands that will be used to start/stop/check fault. iptablesNewChainCmd = "iptables -w %d -N %s" iptablesAppendChainRuleCmd = "iptables -w %d -A %s -p %s --dport %s -j DROP" @@ -135,7 +135,7 @@ func (h *FaultHandler) StartNetworkBlackholePort() func(http.ResponseWriter, *ht defer rwMu.Unlock() ctx := context.Background() - ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutDuration*time.Second) + ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutSeconds*time.Second) defer cancel() var responseBody types.NetworkFaultInjectionResponse @@ -202,7 +202,7 @@ func (h *FaultHandler) startNetworkBlackholePort(ctx context.Context, protocol, } // Creating a new chain - newChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesNewChainCmd, requestTimeoutDuration, chain) + newChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesNewChainCmd, requestTimeoutSeconds, chain) cmdOutput, err := h.runExecCommand(ctx, strings.Split(newChainCmdString, " ")) if err != nil { logger.Error("Unable to create new chain", logger.Fields{ @@ -216,7 +216,7 @@ func (h *FaultHandler) startNetworkBlackholePort(ctx context.Context, protocol, } // Appending a new rule based on the protocol and port number from the request body - appendRuleCmdString := nsenterPrefix + fmt.Sprintf(iptablesAppendChainRuleCmd, requestTimeoutDuration, chain, protocol, port) + appendRuleCmdString := nsenterPrefix + fmt.Sprintf(iptablesAppendChainRuleCmd, requestTimeoutSeconds, chain, protocol, port) cmdOutput, err = h.runExecCommand(ctx, strings.Split(appendRuleCmdString, " ")) if err != nil { logger.Error("Unable to append rule to chain", logger.Fields{ @@ -230,7 +230,7 @@ func (h *FaultHandler) startNetworkBlackholePort(ctx context.Context, protocol, } // Inserting the chain into the built-in INPUT/OUTPUT table - insertChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesInsertChainCmd, requestTimeoutDuration, insertTable, chain) + insertChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesInsertChainCmd, requestTimeoutSeconds, insertTable, chain) cmdOutput, err = h.runExecCommand(ctx, strings.Split(insertChainCmdString, " ")) if err != nil { logger.Error("Unable to insert chain to table", logger.Fields{ @@ -281,7 +281,7 @@ func (h *FaultHandler) StopNetworkBlackHolePort() func(http.ResponseWriter, *htt defer rwMu.Unlock() ctx := context.Background() - ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutDuration*time.Second) + ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutSeconds*time.Second) defer cancel() var responseBody types.NetworkFaultInjectionResponse @@ -349,7 +349,7 @@ func (h *FaultHandler) stopNetworkBlackHolePort(ctx context.Context, protocol, p } // Clearing the appended rules that's associated to the chain - clearChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesClearChainCmd, requestTimeoutDuration, chain) + clearChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesClearChainCmd, requestTimeoutSeconds, chain) cmdOutput, err := h.runExecCommand(ctx, strings.Split(clearChainCmdString, " ")) if err != nil { logger.Error("Unable to clear chain", logger.Fields{ @@ -363,7 +363,7 @@ func (h *FaultHandler) stopNetworkBlackHolePort(ctx context.Context, protocol, p } // Removing the chain from either the built-in INPUT/OUTPUT table - deleteFromTableCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteFromTableCmd, requestTimeoutDuration, insertTable, chain) + deleteFromTableCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteFromTableCmd, requestTimeoutSeconds, insertTable, chain) cmdOutput, err = h.runExecCommand(ctx, strings.Split(deleteFromTableCmdString, " ")) if err != nil { logger.Error("Unable to delete chain from table", logger.Fields{ @@ -378,7 +378,7 @@ func (h *FaultHandler) stopNetworkBlackHolePort(ctx context.Context, protocol, p } // Deleting the chain - deleteChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteChainCmd, requestTimeoutDuration, chain) + deleteChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteChainCmd, requestTimeoutSeconds, chain) cmdOutput, err = h.runExecCommand(ctx, strings.Split(deleteChainCmdString, " ")) if err != nil { logger.Error("Unable to delete chain", logger.Fields{ @@ -429,7 +429,7 @@ func (h *FaultHandler) CheckNetworkBlackHolePort() func(http.ResponseWriter, *ht defer rwMu.RUnlock() ctx := context.Background() - ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutDuration*time.Second) + ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutSeconds*time.Second) defer cancel() var responseBody types.NetworkFaultInjectionResponse @@ -481,7 +481,7 @@ func (h *FaultHandler) checkNetworkBlackHolePort(ctx context.Context, protocol, nsenterPrefix = fmt.Sprintf(nsenterCommandString, netNs) } - cmdString := nsenterPrefix + fmt.Sprintf(iptablesChainExistCmd, requestTimeoutDuration, chain, protocol, port) + cmdString := nsenterPrefix + fmt.Sprintf(iptablesChainExistCmd, requestTimeoutSeconds, chain, protocol, port) cmdList := strings.Split(cmdString, " ") cmdOutput, err := h.runExecCommand(ctx, cmdList) @@ -548,7 +548,7 @@ func (h *FaultHandler) StartNetworkLatency() func(http.ResponseWriter, *http.Req stringToBeLogged := "Failed to start fault" // All command executions for the start network latency workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) @@ -620,7 +620,7 @@ func (h *FaultHandler) StopNetworkLatency() func(http.ResponseWriter, *http.Requ stringToBeLogged := "Failed to stop fault" // All command executions for the stop network latency workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, _, err := h.checkTCFault(ctx, taskMetadata) @@ -691,7 +691,7 @@ func (h *FaultHandler) CheckNetworkLatency() func(http.ResponseWriter, *http.Req stringToBeLogged := "Failed to check status for fault" // All command executions for the check network latency workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, _, err := h.checkTCFault(ctx, taskMetadata) @@ -761,7 +761,7 @@ func (h *FaultHandler) StartNetworkPacketLoss() func(http.ResponseWriter, *http. stringToBeLogged := "Failed to start fault" // All command executions for the start network packet loss workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) @@ -833,7 +833,7 @@ func (h *FaultHandler) StopNetworkPacketLoss() func(http.ResponseWriter, *http.R stringToBeLogged := "Failed to stop fault" // All command executions for the stop network packet loss workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. _, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) @@ -904,7 +904,7 @@ func (h *FaultHandler) CheckNetworkPacketLoss() func(http.ResponseWriter, *http. stringToBeLogged := "Failed to check status for fault" // All command executions for the check network packet loss workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. _, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) diff --git a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go index fe914cd37a4..26f6d1bc806 100644 --- a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go +++ b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go @@ -53,7 +53,7 @@ const ( requestTimedOutError = "%s: request timed out" // This is our initial assumption of how much time it would take for the Linux commands used to inject faults // to finish. This will be confirmed/updated after more testing. - requestTimeoutDuration = 5 + requestTimeoutSeconds = 5 // Commands that will be used to start/stop/check fault. iptablesNewChainCmd = "iptables -w %d -N %s" iptablesAppendChainRuleCmd = "iptables -w %d -A %s -p %s --dport %s -j DROP" @@ -135,7 +135,7 @@ func (h *FaultHandler) StartNetworkBlackholePort() func(http.ResponseWriter, *ht defer rwMu.Unlock() ctx := context.Background() - ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutDuration*time.Second) + ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutSeconds*time.Second) defer cancel() var responseBody types.NetworkFaultInjectionResponse @@ -202,7 +202,7 @@ func (h *FaultHandler) startNetworkBlackholePort(ctx context.Context, protocol, } // Creating a new chain - newChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesNewChainCmd, requestTimeoutDuration, chain) + newChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesNewChainCmd, requestTimeoutSeconds, chain) cmdOutput, err := h.runExecCommand(ctx, strings.Split(newChainCmdString, " ")) if err != nil { logger.Error("Unable to create new chain", logger.Fields{ @@ -216,7 +216,7 @@ func (h *FaultHandler) startNetworkBlackholePort(ctx context.Context, protocol, } // Appending a new rule based on the protocol and port number from the request body - appendRuleCmdString := nsenterPrefix + fmt.Sprintf(iptablesAppendChainRuleCmd, requestTimeoutDuration, chain, protocol, port) + appendRuleCmdString := nsenterPrefix + fmt.Sprintf(iptablesAppendChainRuleCmd, requestTimeoutSeconds, chain, protocol, port) cmdOutput, err = h.runExecCommand(ctx, strings.Split(appendRuleCmdString, " ")) if err != nil { logger.Error("Unable to append rule to chain", logger.Fields{ @@ -230,7 +230,7 @@ func (h *FaultHandler) startNetworkBlackholePort(ctx context.Context, protocol, } // Inserting the chain into the built-in INPUT/OUTPUT table - insertChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesInsertChainCmd, requestTimeoutDuration, insertTable, chain) + insertChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesInsertChainCmd, requestTimeoutSeconds, insertTable, chain) cmdOutput, err = h.runExecCommand(ctx, strings.Split(insertChainCmdString, " ")) if err != nil { logger.Error("Unable to insert chain to table", logger.Fields{ @@ -281,7 +281,7 @@ func (h *FaultHandler) StopNetworkBlackHolePort() func(http.ResponseWriter, *htt defer rwMu.Unlock() ctx := context.Background() - ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutDuration*time.Second) + ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutSeconds*time.Second) defer cancel() var responseBody types.NetworkFaultInjectionResponse @@ -349,7 +349,7 @@ func (h *FaultHandler) stopNetworkBlackHolePort(ctx context.Context, protocol, p } // Clearing the appended rules that's associated to the chain - clearChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesClearChainCmd, requestTimeoutDuration, chain) + clearChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesClearChainCmd, requestTimeoutSeconds, chain) cmdOutput, err := h.runExecCommand(ctx, strings.Split(clearChainCmdString, " ")) if err != nil { logger.Error("Unable to clear chain", logger.Fields{ @@ -363,7 +363,7 @@ func (h *FaultHandler) stopNetworkBlackHolePort(ctx context.Context, protocol, p } // Removing the chain from either the built-in INPUT/OUTPUT table - deleteFromTableCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteFromTableCmd, requestTimeoutDuration, insertTable, chain) + deleteFromTableCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteFromTableCmd, requestTimeoutSeconds, insertTable, chain) cmdOutput, err = h.runExecCommand(ctx, strings.Split(deleteFromTableCmdString, " ")) if err != nil { logger.Error("Unable to delete chain from table", logger.Fields{ @@ -378,7 +378,7 @@ func (h *FaultHandler) stopNetworkBlackHolePort(ctx context.Context, protocol, p } // Deleting the chain - deleteChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteChainCmd, requestTimeoutDuration, chain) + deleteChainCmdString := nsenterPrefix + fmt.Sprintf(iptablesDeleteChainCmd, requestTimeoutSeconds, chain) cmdOutput, err = h.runExecCommand(ctx, strings.Split(deleteChainCmdString, " ")) if err != nil { logger.Error("Unable to delete chain", logger.Fields{ @@ -429,7 +429,7 @@ func (h *FaultHandler) CheckNetworkBlackHolePort() func(http.ResponseWriter, *ht defer rwMu.RUnlock() ctx := context.Background() - ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutDuration*time.Second) + ctxWithTimeout, cancel := h.osExecWrapper.NewExecContextWithTimeout(ctx, requestTimeoutSeconds*time.Second) defer cancel() var responseBody types.NetworkFaultInjectionResponse @@ -481,7 +481,7 @@ func (h *FaultHandler) checkNetworkBlackHolePort(ctx context.Context, protocol, nsenterPrefix = fmt.Sprintf(nsenterCommandString, netNs) } - cmdString := nsenterPrefix + fmt.Sprintf(iptablesChainExistCmd, requestTimeoutDuration, chain, protocol, port) + cmdString := nsenterPrefix + fmt.Sprintf(iptablesChainExistCmd, requestTimeoutSeconds, chain, protocol, port) cmdList := strings.Split(cmdString, " ") cmdOutput, err := h.runExecCommand(ctx, cmdList) @@ -548,7 +548,7 @@ func (h *FaultHandler) StartNetworkLatency() func(http.ResponseWriter, *http.Req stringToBeLogged := "Failed to start fault" // All command executions for the start network latency workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) @@ -620,7 +620,7 @@ func (h *FaultHandler) StopNetworkLatency() func(http.ResponseWriter, *http.Requ stringToBeLogged := "Failed to stop fault" // All command executions for the stop network latency workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, _, err := h.checkTCFault(ctx, taskMetadata) @@ -691,7 +691,7 @@ func (h *FaultHandler) CheckNetworkLatency() func(http.ResponseWriter, *http.Req stringToBeLogged := "Failed to check status for fault" // All command executions for the check network latency workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, _, err := h.checkTCFault(ctx, taskMetadata) @@ -761,7 +761,7 @@ func (h *FaultHandler) StartNetworkPacketLoss() func(http.ResponseWriter, *http. stringToBeLogged := "Failed to start fault" // All command executions for the start network packet loss workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. latencyFaultExists, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) @@ -833,7 +833,7 @@ func (h *FaultHandler) StopNetworkPacketLoss() func(http.ResponseWriter, *http.R stringToBeLogged := "Failed to stop fault" // All command executions for the stop network packet loss workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. _, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) @@ -904,7 +904,7 @@ func (h *FaultHandler) CheckNetworkPacketLoss() func(http.ResponseWriter, *http. stringToBeLogged := "Failed to check status for fault" // All command executions for the check network packet loss workflow all together should finish within 5 seconds. // Thus, create the context here so that it can be shared by all os/exec calls. - ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutDuration*time.Second) + ctx, cancel := h.osExecWrapper.NewExecContextWithTimeout(context.Background(), requestTimeoutSeconds*time.Second) defer cancel() // Check the status of current fault injection. _, packetLossFaultExists, err := h.checkTCFault(ctx, taskMetadata) diff --git a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go index 7e4eab949a9..d32206d6215 100644 --- a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go +++ b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go @@ -131,7 +131,7 @@ var ( stopNetworkPacketLossTestPrefix = fmt.Sprintf(stopFaultRequestType, types.PacketLossFaultType) checkNetworkPacketLossTestPrefix = fmt.Sprintf(checkStatusFaultRequestType, types.PacketLossFaultType) - ctxTimeoutDuration = requestTimeoutDuration * time.Second + ctxTimeoutDuration = requestTimeoutSeconds * time.Second ) type networkFaultInjectionTestCase struct {