mirror of
https://github.com/resmoio/kubernetes-event-exporter.git
synced 2026-08-20 07:16:16 +00:00
Before the change, the engine didn't call the `Close()` method of the sinks. This is needed in some cases, i.e when a sink implementation is buffered. This change adds a `Close()` method to the registry that will signal sinks to exit and wait for all sinks to exit before returning. This is then used in the engine stop logic. In the channel-based registry, the closing of all sinks is done in parallel (using a `sync.WaitGroup`). In the sync registry, sinks are closed sequentially. Fixes issue #10
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package exporter
|
|
|
|
import (
|
|
"github.com/opsgenie/kubernetes-event-exporter/pkg/kube"
|
|
"github.com/rs/zerolog/log"
|
|
"reflect"
|
|
)
|
|
|
|
// Engine is responsible for initializing the receivers from sinks
|
|
type Engine struct {
|
|
Route Route
|
|
Registry ReceiverRegistry
|
|
}
|
|
|
|
func NewEngine(config *Config, registry ReceiverRegistry) *Engine {
|
|
for _, v := range config.Receivers {
|
|
sink, err := v.GetSink()
|
|
if err != nil {
|
|
log.Fatal().Err(err).Str("name", v.Name).Msg("Cannot initialize sink")
|
|
}
|
|
|
|
log.Info().
|
|
Str("name", v.Name).
|
|
Str("type", reflect.TypeOf(sink).String()).
|
|
Msg("Registering sink")
|
|
|
|
registry.Register(v.Name, sink)
|
|
}
|
|
|
|
return &Engine{
|
|
Route: config.Route,
|
|
Registry: registry,
|
|
}
|
|
}
|
|
|
|
// OnEvent does not care whether event is add or update. Prior filtering should be done in the controller/watcher
|
|
func (e *Engine) OnEvent(event *kube.EnhancedEvent) {
|
|
e.Route.ProcessEvent(event, e.Registry)
|
|
}
|
|
|
|
// Stop stops all registered sinks
|
|
func (e *Engine) Stop() {
|
|
log.Info().Msg("Closing sinks")
|
|
e.Registry.Close()
|
|
log.Info().Msg("All sinks closed")
|
|
}
|