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

Add Timeout for EventListener Server #747

Merged
merged 1 commit into from
Nov 17, 2020
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
9 changes: 6 additions & 3 deletions cmd/eventlistenersink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ func main() {
})

srv := &http.Server{
Addr: fmt.Sprintf(":%s", sinkArgs.Port),
IdleTimeout: 120 * time.Second,
Handler: mux,
Addr: fmt.Sprintf(":%s", sinkArgs.Port),
ReadTimeout: sinkArgs.ELReadTimeOut * time.Second,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadTimeout includes reading both headers + body. Maybe we should use ReadHeaderTimeout instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or may we set both? What would be the sane values for all these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 seconds sounds reasonable to me.

WriteTimeout: sinkArgs.ELWriteTimeOut * time.Second,
IdleTimeout: sinkArgs.ELIdleTimeOut * time.Second,
dibyom marked this conversation as resolved.
Show resolved Hide resolved
Handler: http.TimeoutHandler(mux,
sinkArgs.ELTimeOutHandler*time.Second, "EventListener Timeout!\n"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to add some extra info here e.g. the eventID or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unless we write our own custom thing.

}

if err := srv.ListenAndServe(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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-idletimeout", "120",
"-el-timeouthandler", "30",
"-period-seconds", "10",
"-failure-threshold", "1"
]
Expand Down
9 changes: 9 additions & 0 deletions docs/eventlisteners.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ using [Event Interceptors](#Interceptors).
- [EventListener Response](#eventlistener-response)
- [How does the EventListener work?](#how-does-the-eventlistener-work)
- [Examples](#examples)
- [Response Timeout](#response-timeout)
- [Multi-Tenant Concerns](#multi-tenant-concerns)
- [Multiple EventListeners (One EventListener Per Namespace)](#multiple-eventlisteners-one-eventlistener-per-namespace)
- [Multiple EventListeners (Multiple EventListeners per Namespace)](#multiple-eventlisteners-multiple-eventlisteners-per-namespace)
Expand Down Expand Up @@ -878,6 +879,14 @@ Follow [GitHub example](https://github.com/tektoncd/triggers/blob/master/example
For complete examples, see
[the examples folder](https://github.com/tektoncd/triggers/tree/master/examples).

## Response Timeout
Eventlistener sink timeout if EventListener isn't able to process the request within certain duration. The response timeout configuration is defined in [controller.yaml](../config/controller.yaml).
- `-el-readtimeout`: This define ReadTimeOut for sink server. Default value is 5 s.
- `-el-writetimeout`: This define WriteTimeout for sink server. Default value is 40s.
- `-el-idletimeout`: This define the IdleTimeout for sink server. Default value is 120s.
- `-el-timeouthandler`: This define the Timeout for Handler for sink server's route. Default value is 30s.


## Multi-Tenant Concerns

The EventListener is effectively an additional form of client into Tekton, versus what
Expand Down
1 change: 1 addition & 0 deletions pkg/interceptors/bitbucket/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"

triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/interceptors/cel/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import (
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"github.com/google/go-cmp/cmp"
triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fakekubeclient "knative.dev/pkg/client/injection/kube/client/fake"
"knative.dev/pkg/logging"
rtesting "knative.dev/pkg/reconciler/testing"

triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
)

const testNS = "testing-ns"
Expand Down
1 change: 1 addition & 0 deletions pkg/interceptors/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"

triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
1 change: 1 addition & 0 deletions pkg/interceptors/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"

triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
16 changes: 16 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -328,6 +340,10 @@ func (r *Reconciler) reconcileDeployment(ctx context.Context, logger *zap.Sugare
"-el-name", el.Name,
"-el-namespace", el.Namespace,
"-port", strconv.Itoa(*ElPort),
"-readtimeout", strconv.FormatInt(*ELReadTimeOut, 10),
"-writetimeout", strconv.FormatInt(*ELWriteTimeOut, 10),
"-idletimeout", strconv.FormatInt(*ELIdleTimeOut, 10),
"-timeouthandler", strconv.FormatInt(*ELTimeOutHandler, 10),
},
VolumeMounts: []corev1.VolumeMount{{
Name: "config-logging",
Expand Down
4 changes: 4 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func makeDeployment(ops ...func(d *appsv1.Deployment)) *appsv1.Deployment {
"-el-name", eventListenerName,
"-el-namespace", namespace,
"-port", strconv.Itoa(*ElPort),
"readtimeout", strconv.FormatInt(*ELReadTimeOut, 10),
"writetimeout", strconv.FormatInt(*ELWriteTimeOut, 10),
"idletimeout", strconv.FormatInt(*ELIdleTimeOut, 10),
"timeouthandler", strconv.FormatInt(*ELTimeOutHandler, 10),
},
VolumeMounts: []corev1.VolumeMount{{
Name: "config-logging",
Expand Down
27 changes: 24 additions & 3 deletions pkg/sink/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package sink

import (
"flag"
"time"

triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned"
"golang.org/x/xerrors"
Expand All @@ -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("readtimeout", 5,
"The read timeout for EventListener Server.")
elWriteTimeOut = flag.Int64("writetimeout", 40,
"The write timeout for EventListener Server.")
elIdleTimeOut = flag.Int64("idletimeout", 30,
"The idle timeout for EventListener Server.")
elTimeOutHandler = flag.Int64("timeouthandler", 5,
"The timeout for Timeout Handler of EventListener Server.")
)

// Args define the arguments for Sink.
Expand All @@ -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.
Expand All @@ -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
}

Expand Down