Skip to content

Commit

Permalink
feat: add skip-event-updates option (#16)
Browse files Browse the repository at this point in the history
* feat:  add --skip-event-updates
skip-event-updates will skip updating the event data. Only first time data will be logged.
Add
```json
      "skip-event-updates": "true"
```
to your config.json
  • Loading branch information
mwennrich authored Apr 11, 2024
1 parent c608f2b commit 9d45ca8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 10 additions & 4 deletions eventrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ type EventRouter struct {
// event sink
// TODO: Determine if we want to support multiple sinks.
eSink sinks.EventSinkInterface

// skipEventUpdates will skip updating events in the sink
skipEventUpdates bool
}

// NewEventRouter will create a new event router using the input params
func NewEventRouter(kubeClient kubernetes.Interface, eventsInformer coreinformers.EventInformer) *EventRouter {
func NewEventRouter(kubeClient kubernetes.Interface, eventsInformer coreinformers.EventInformer, skipEventUpdates bool) *EventRouter {
if viper.GetBool("enable-prometheus") {
prometheus.MustRegister(kubernetesWarningEventCounterVec)
prometheus.MustRegister(kubernetesNormalEventCounterVec)
Expand All @@ -102,8 +105,9 @@ func NewEventRouter(kubeClient kubernetes.Interface, eventsInformer coreinformer
}

er := &EventRouter{
kubeClient: kubeClient,
eSink: sinks.ManufactureSink(),
kubeClient: kubeClient,
eSink: sinks.ManufactureSink(),
skipEventUpdates: skipEventUpdates,
}
_, err := eventsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: er.addEvent,
Expand Down Expand Up @@ -145,7 +149,9 @@ func (er *EventRouter) updateEvent(objOld interface{}, objNew interface{}) {
eOld := objOld.(*v1.Event)
eNew := objNew.(*v1.Event)
prometheusEvent(eNew)
er.eSink.UpdateEvents(eNew, eOld)
if !er.skipEventUpdates {
er.eSink.UpdateEvents(eNew, eOld)
}
}

// prometheusEvent is called when an event is added or updated
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// addr tells us what address to have the Prometheus metrics listen on.
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")

// setup a signal hander to gracefully exit
// setup a signal handler to gracefully exit
func sigHandler() <-chan struct{} {
stop := make(chan struct{})
go func() {
Expand Down Expand Up @@ -74,6 +74,7 @@ func loadConfig() kubernetes.Interface {
viper.SetDefault("sink", "glog")
viper.SetDefault("resync-interval", time.Minute*30)
viper.SetDefault("enable-prometheus", true)
viper.SetDefault("skip-event-updates", false)
if err = viper.ReadInConfig(); err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -118,8 +119,9 @@ func main() {
sharedInformers := informers.NewSharedInformerFactory(clientset, viper.GetDuration("resync-interval"))
eventsInformer := sharedInformers.Core().V1().Events()

skipEventUpdates := viper.GetBool("skip-event-updates")
// TODO: Support locking for HA https://github.com/kubernetes/kubernetes/pull/42666
eventRouter := NewEventRouter(clientset, eventsInformer)
eventRouter := NewEventRouter(clientset, eventsInformer, skipEventUpdates)
stop := sigHandler()

// Startup the http listener for Prometheus Metrics endpoint.
Expand Down
3 changes: 2 additions & 1 deletion yaml/eventrouter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ apiVersion: v1
data:
config.json: |-
{
"sink": "stdout"
"sink": "stdout",
"skip-event-updates": "true"
}
---
apiVersion: apps/v1
Expand Down

0 comments on commit 9d45ca8

Please sign in to comment.