From 9450041868c6fa8967414e6e91967e3e72ef5e8c Mon Sep 17 00:00:00 2001 From: Maciej Borsz Date: Fri, 2 Oct 2020 13:26:54 +0200 Subject: [PATCH] Use 10000 page size on listing events. In large clusters, we see up to 1M events and fetching them using default 500 page size is impossible due to limited token expiration time. --- event-exporter/Makefile | 2 +- event-exporter/watchers/events/watcher.go | 11 ++++++++++- event-exporter/watchers/watcher.go | 23 +++++++++++++---------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/event-exporter/Makefile b/event-exporter/Makefile index a8cabe2b8..0fb6c44e1 100644 --- a/event-exporter/Makefile +++ b/event-exporter/Makefile @@ -19,7 +19,7 @@ BINARY_NAME = event-exporter PREFIX = staging-k8s.gcr.io IMAGE_NAME = event-exporter -TAG = v0.3.3 +TAG = v0.3.4 build: ${ENVVAR} go build -mod=vendor -a -o ${BINARY_NAME} diff --git a/event-exporter/watchers/events/watcher.go b/event-exporter/watchers/events/watcher.go index 2febbf0c6..a311bf99c 100644 --- a/event-exporter/watchers/events/watcher.go +++ b/event-exporter/watchers/events/watcher.go @@ -36,6 +36,14 @@ const ( // the hour, since it takes some time to deliver this event via watch. // 2 hours ought to be enough for anybody. eventStorageTTL = 2 * time.Hour + + // Large clusters can have up to 1M events. Fetching them using default + // 500 page requires 2000 requests and is not able to finish before + // continuation token will expire. + // Value 10000 translates to ~100 requests that each takes 0.5s-1s, + // so in total listing should take ~1m, which is still below 2.5m-5m + // token expiration time. + eventWatchListPageSize = 10000 ) // OnListFunc represent an action on the initial list of object received @@ -76,6 +84,7 @@ func NewEventWatcher(client kubernetes.Interface, config *EventWatcherConfig) wa StorageType: watchers.TTLStorage, StorageTTL: eventStorageTTL, }, - ResyncPeriod: config.ResyncPeriod, + ResyncPeriod: config.ResyncPeriod, + WatchListPageSize: eventWatchListPageSize, }) } diff --git a/event-exporter/watchers/watcher.go b/event-exporter/watchers/watcher.go index f3dc9d1df..ff87713f3 100644 --- a/event-exporter/watchers/watcher.go +++ b/event-exporter/watchers/watcher.go @@ -24,10 +24,11 @@ import ( // WatcherConfig represents the configuration of the Kubernetes API watcher. type WatcherConfig struct { - ListerWatcher cache.ListerWatcher - ExpectedType interface{} - StoreConfig *WatcherStoreConfig - ResyncPeriod time.Duration + ListerWatcher cache.ListerWatcher + ExpectedType interface{} + StoreConfig *WatcherStoreConfig + ResyncPeriod time.Duration + WatchListPageSize int64 } // Watcher is an interface of the generic proactive API watcher. @@ -45,12 +46,14 @@ func (w *watcher) Run(stopCh <-chan struct{}) { // NewWatcher creates a new Kubernetes API watcher using provided configuration. func NewWatcher(config *WatcherConfig) Watcher { + r := cache.NewReflector( + config.ListerWatcher, + config.ExpectedType, + newWatcherStore(config.StoreConfig), + config.ResyncPeriod, + ) + r.WatchListPageSize = config.WatchListPageSize return &watcher{ - reflector: cache.NewReflector( - config.ListerWatcher, - config.ExpectedType, - newWatcherStore(config.StoreConfig), - config.ResyncPeriod, - ), + reflector: r, } }