Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #145 from omauger/add_throttlePeriod_param
Browse files Browse the repository at this point in the history
Add ThrottlePeriod param to give possibility to choose period for evi…
  • Loading branch information
mustafaakin-atl authored Nov 6, 2021
2 parents 984b6a9 + 0782a2d commit 21217ec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,13 @@ Standard out is also another file in Linux. `logLevel` refers to the application
`trace`, `debug`, `info`, `warn`, `error`, `fatal` and `panic`. When not specified, default level is set to `info`. You
can use the following configuration as an example.

By default, events emit with eventime > 5seconds since catching are not collected.
You can set this period with trottlePeriod in seconds. Consider to increase time of seconds to catch more events like "Backoff".

```yaml
logLevel: error
logFormat: json
trottlePeriod: 5
route:
routes:
- match:
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
}

engine := exporter.NewEngine(&cfg, &exporter.ChannelBasedReceiverRegistry{})
w := kube.NewEventWatcher(kubeconfig, cfg.Namespace, engine.OnEvent)
w := kube.NewEventWatcher(kubeconfig, cfg.Namespace, cfg.ThrottlePeriod, engine.OnEvent)

ctx, cancel := context.WithCancel(context.Background())
leaderLost := make(chan bool)
Expand Down
1 change: 1 addition & 0 deletions pkg/exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {
// TODO: I am not sure what to do here.
LogLevel string `yaml:"logLevel"`
LogFormat string `yaml:"logFormat"`
ThrottlePeriod int64 `yaml:"throttlePeriod" default:"5""`
Namespace string `yaml:"namespace"`
LeaderElection kube.LeaderElectionConfig `yaml:"leaderElection"`
Route Route `yaml:"route"`
Expand Down
6 changes: 4 additions & 2 deletions pkg/kube/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type EventWatcher struct {
labelCache *LabelCache
annotationCache *AnnotationCache
fn EventHandler
throttlePeriod time.Duration
}

func NewEventWatcher(config *rest.Config, namespace string, fn EventHandler) *EventWatcher {
func NewEventWatcher(config *rest.Config, namespace string, throttlePeriod int64, fn EventHandler) *EventWatcher {
clientset := kubernetes.NewForConfigOrDie(config)
factory := informers.NewSharedInformerFactoryWithOptions(clientset, 0, informers.WithNamespace(namespace))
informer := factory.Core().V1().Events().Informer()
Expand All @@ -32,6 +33,7 @@ func NewEventWatcher(config *rest.Config, namespace string, fn EventHandler) *Ev
labelCache: NewLabelCache(config),
annotationCache: NewAnnotationCache(config),
fn: fn,
throttlePeriod: time.Second*time.Duration(throttlePeriod),
}

informer.AddEventHandler(watcher)
Expand All @@ -52,7 +54,7 @@ func (e *EventWatcher) OnUpdate(oldObj, newObj interface{}) {
func (e *EventWatcher) onEvent(event *corev1.Event) {
// TODO: Re-enable this after development
// It's probably an old event we are catching, it's not the best way but anyways
if time.Since(event.LastTimestamp.Time) > time.Second*5 {
if time.Since(event.LastTimestamp.Time) > e.throttlePeriod {
return
}

Expand Down

0 comments on commit 21217ec

Please sign in to comment.