Skip to content

Commit

Permalink
Merge pull request #382 from mborsz/page
Browse files Browse the repository at this point in the history
Use 10000 page size on listing events.
  • Loading branch information
kawych authored Oct 2, 2020
2 parents 4505c28 + 9450041 commit 959114b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion event-exporter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
11 changes: 10 additions & 1 deletion event-exporter/watchers/events/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
}
23 changes: 13 additions & 10 deletions event-exporter/watchers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
}
}

0 comments on commit 959114b

Please sign in to comment.