diff --git a/cmd/eventlistenersink/main.go b/cmd/eventlistenersink/main.go index 0b42c3e041..8d88bd9a29 100644 --- a/cmd/eventlistenersink/main.go +++ b/cmd/eventlistenersink/main.go @@ -20,6 +20,7 @@ import ( "fmt" "log" "net/http" + "time" "go.uber.org/zap" @@ -101,5 +102,15 @@ func main() { w.WriteHeader(200) fmt.Fprint(w, "ok") }) - logger.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", sinkArgs.Port), nil)) + + srv := &http.Server{ + Addr: fmt.Sprintf(":%s", sinkArgs.Port), + ReadTimeout: sinkArgs.ELReadTimeOut * time.Second, + WriteTimeout: sinkArgs.ELWriteTimeOut * time.Second, + IdleTimeout: sinkArgs.ELIdleTimeOut * time.Second, + Handler: http.TimeoutHandler(http.DefaultServeMux, + sinkArgs.ELTimeOutHandler*time.Second, "EventListener Timeout!\n"), + } + + logger.Fatal(srv.ListenAndServe()) } diff --git a/config/controller.yaml b/config/controller.yaml index d496df19eb..59c9ffb003 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -57,6 +57,10 @@ spec: "-stderrthreshold", "INFO", "-el-image", "ko://github.com/tektoncd/triggers/cmd/eventlistenersink", "-el-port", "8080", + "-el-readtimeout", "5", + "-el-writetimeout", "40", + "-el-idleimeout", "120", + "-el-timeouthandler", "30", "-period-seconds", "10", "-failure-threshold", "1" ] diff --git a/pkg/reconciler/v1alpha1/eventlistener/eventlistener.go b/pkg/reconciler/v1alpha1/eventlistener/eventlistener.go index c18e1b4f9e..cc68c8efa2 100644 --- a/pkg/reconciler/v1alpha1/eventlistener/eventlistener.go +++ b/pkg/reconciler/v1alpha1/eventlistener/eventlistener.go @@ -67,6 +67,18 @@ var ( // ElPort defines the port for the EventListener to listen on ElPort = flag.Int("el-port", 8080, "The container port for the EventListener to listen on.") + // ELReadTimeOut defines the read timeout for EventListener Server + ELReadTimeOut = flag.Int64("el-readtimeout", 5, + "The read timeout for EventListener Server.") + // ELWriteTimeOut defines the write timeout for EventListener Server + ELWriteTimeOut = flag.Int64("el-writetimeout", 40, + "The write timeout for EventListener Server.") + // ELIdleTimeOut defines the read timeout for EventListener Server + ELIdleTimeOut = flag.Int64("el-idletimeout", 30, + "The idle timeout for EventListener Server.") + // ELTimeOutHandler defines the timeout for Timeout Handler of EventListener Server + ELTimeOutHandler = flag.Int64("el-timeouthandler", 5, + "The timeout for Timeout Handler of EventListener Server.") // PeriodSeconds defines Period Seconds for the EventListener Liveness and Readiness Probes PeriodSeconds = flag.Int("period-seconds", 10, "The Period Seconds for the EventListener Liveness and Readiness Probes.") @@ -290,6 +302,10 @@ func (r *Reconciler) reconcileDeployment(logger *zap.SugaredLogger, el *v1alpha1 "-el-name", el.Name, "-el-namespace", el.Namespace, "-port", strconv.Itoa(*ElPort), + "-el-readtimeout", strconv.FormatInt(*ELReadTimeOut, 10), + "-el-writetimeout", strconv.FormatInt(*ELWriteTimeOut, 10), + "-el-idletimeout", strconv.FormatInt(*ELIdleTimeOut, 10), + "-el-timeouthandler", strconv.FormatInt(*ELTimeOutHandler, 10), }, VolumeMounts: []corev1.VolumeMount{{ Name: "config-logging", diff --git a/pkg/sink/initialization.go b/pkg/sink/initialization.go index 8454018772..33bd6d9b59 100644 --- a/pkg/sink/initialization.go +++ b/pkg/sink/initialization.go @@ -18,6 +18,7 @@ package sink import ( "flag" + "time" triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned" "golang.org/x/xerrors" @@ -41,6 +42,14 @@ var ( "The namespace of the EventListener resource for this sink.") portFlag = flag.String("port", "", "The port for the EventListener sink to listen on.") + elReadTimeOut = flag.Int64("el-readtimeout", 5, + "The read timeout for EventListener Server.") + elWriteTimeOut = flag.Int64("el-writetimeout", 40, + "The write timeout for EventListener Server.") + elIdleTimeOut = flag.Int64("el-idletimeout", 30, + "The idle timeout for EventListener Server.") + elTimeOutHandler = flag.Int64("el-timeouthandler", 5, + "The timeout for Timeout Handler of EventListener Server.") ) // Args define the arguments for Sink. @@ -51,6 +60,14 @@ type Args struct { ElNamespace string // Port is the port the Sink should listen on. Port string + // ELReadTimeOut defines the read timeout for EventListener Server + ELReadTimeOut time.Duration + // ELWriteTimeOut defines the write timeout for EventListener Server + ELWriteTimeOut time.Duration + // ELIdleTimeOut defines the read timeout for EventListener Server + ELIdleTimeOut time.Duration + // ELTimeOutHandler defines the timeout for Timeout Handler of EventListener Server + ELTimeOutHandler time.Duration } // Clients define the set of client dependencies Sink requires. @@ -73,9 +90,13 @@ func GetArgs() (Args, error) { return Args{}, xerrors.Errorf("-%s arg not found", port) } return Args{ - ElName: *nameFlag, - ElNamespace: *namespaceFlag, - Port: *portFlag, + ElName: *nameFlag, + ElNamespace: *namespaceFlag, + Port: *portFlag, + ELReadTimeOut: time.Duration(*elReadTimeOut), + ELWriteTimeOut: time.Duration(*elWriteTimeOut), + ELIdleTimeOut: time.Duration(*elIdleTimeOut), + ELTimeOutHandler: time.Duration(*elTimeOutHandler), }, nil }