Skip to content

Commit

Permalink
icinga2: rename eventstream package to icinga2
Browse files Browse the repository at this point in the history
  • Loading branch information
oxzi authored and julianbrost committed Apr 12, 2024
1 parent ead40ab commit 8ca9efd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions cmd/icinga-notifications-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/icinga/icinga-notifications/internal/channel"
"github.com/icinga/icinga-notifications/internal/config"
"github.com/icinga/icinga-notifications/internal/daemon"
"github.com/icinga/icinga-notifications/internal/eventstream"
"github.com/icinga/icinga-notifications/internal/icinga2"
"github.com/icinga/icinga-notifications/internal/incident"
"github.com/icinga/icinga-notifications/internal/listener"
"github.com/icinga/icingadb/pkg/logging"
Expand Down Expand Up @@ -86,19 +86,19 @@ func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

esLauncher := &eventstream.Launcher{
icinga2Launcher := &icinga2.Launcher{
Ctx: ctx,
Logs: logs,
Db: db,
RuntimeConfig: nil, // Will be set below as it is interconnected..
}

runtimeConfig := config.NewRuntimeConfig(esLauncher.Launch, logs, db)
runtimeConfig := config.NewRuntimeConfig(icinga2Launcher.Launch, logs, db)
if err := runtimeConfig.UpdateFromDatabase(ctx); err != nil {
logger.Fatalw("failed to load config from database", zap.Error(err))
}

esLauncher.RuntimeConfig = runtimeConfig
icinga2Launcher.RuntimeConfig = runtimeConfig

go runtimeConfig.PeriodicUpdates(ctx, 1*time.Second)

Expand All @@ -108,7 +108,7 @@ func main() {
}

// Wait to load open incidents from the database before either starting Event Stream Clients or starting the Listener.
esLauncher.Ready()
icinga2Launcher.Ready()
if err := listener.NewListener(db, runtimeConfig, logs).Run(ctx); err != nil {
logger.Errorw("Listener has finished with an error", zap.Error(err))
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RuntimeConfig struct {
ConfigSet

// EventStreamLaunchFunc is a callback to launch an Event Stream API Client.
// This became necessary due to circular imports, either with the incident or eventstream package.
// This became necessary due to circular imports, either with the incident or icinga2 package.
EventStreamLaunchFunc func(source *Source)

// pending contains changes to config objects that are to be applied to the embedded live config.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

// This file contains the Launcher type to, well, launch new Event Stream Clients through a callback function.

Expand All @@ -18,7 +18,7 @@ import (
"sync"
)

// Launcher allows starting a new Event Stream API Client through a callback from within the config package.
// Launcher allows starting a new Icinga 2 Event Stream API Client through a callback from within the config package.
//
// This architecture became kind of necessary to work around circular imports due to the RuntimeConfig's omnipresence.
type Launcher struct {
Expand All @@ -32,13 +32,13 @@ type Launcher struct {
waitingSources []*config.Source
}

// Launch either directly launches an Event Stream Client for this Source or enqueues it until the Launcher is Ready.
// Launch either directly launches an Icinga 2 Event Stream Client for this Source or enqueues it until the Launcher is Ready.
func (launcher *Launcher) Launch(src *config.Source) {
launcher.mutex.Lock()
defer launcher.mutex.Unlock()

if !launcher.isReady {
launcher.Logs.GetChildLogger("eventstream").
launcher.Logs.GetChildLogger("icinga2").
With(zap.Int64("source-id", src.ID)).
Debug("Postponing Event Stream Client Launch as Launcher is not ready yet")
launcher.waitingSources = append(launcher.waitingSources, src)
Expand All @@ -55,17 +55,17 @@ func (launcher *Launcher) Ready() {

launcher.isReady = true
for _, src := range launcher.waitingSources {
launcher.Logs.GetChildLogger("eventstream").
launcher.Logs.GetChildLogger("icinga2").
With(zap.Int64("source-id", src.ID)).
Debug("Launching postponed Event Stream Client")
launcher.launch(src)
}
launcher.waitingSources = nil
}

// launch a new Event Stream API Client based on the Icinga2Source configuration.
// launch a new Icinga 2 Event Stream API Client based on the config.Source configuration.
func (launcher *Launcher) launch(src *config.Source) {
logger := launcher.Logs.GetChildLogger("eventstream").With(zap.Int64("source-id", src.ID))
logger := launcher.Logs.GetChildLogger("icinga2").With(zap.Int64("source-id", src.ID))

if src.Type != config.SourceTypeIcinga2 ||
!src.Icinga2BaseURL.Valid ||
Expand Down
2 changes: 1 addition & 1 deletion internal/eventstream/util.go → internal/icinga2/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

import (
"net/url"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eventstream
package icinga2

import (
"github.com/stretchr/testify/assert"
Expand Down

0 comments on commit 8ca9efd

Please sign in to comment.