Skip to content

Commit

Permalink
feat: Replace pure watchers with (Informers + RetryWatchers) [up to you]
Browse files Browse the repository at this point in the history
  • Loading branch information
achetronic committed Apr 8, 2024
1 parent c5e0577 commit 389385f
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 39 deletions.
17 changes: 14 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool
var configPath string
var eventsPerSecond int
var enableWatcherPoolCleaner bool
var watcherEventsPerSecond int
var informerSecondsToResync int
var useWatchers bool

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -74,9 +76,12 @@ func main() {
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.StringVar(&configPath, "config", "notifik.yaml", "The path to configuration file.")
flag.IntVar(&eventsPerSecond, "events-per-second", 20, "Amount of events processed per second (best effort)")
flag.BoolVar(&enableWatcherPoolCleaner, "enable-watcher-cleaner", false,
"If set, WatcherPool cleaner will be enabled for orphan watchers")
flag.IntVar(&watcherEventsPerSecond, "watcher-events-per-second", 20, "Amount of events processed per second by pure watchers (best effort)")
flag.IntVar(&informerSecondsToResync, "informer-seconds-to-resync", 300, "Amount of seconds to resync all the objects by informers")
flag.BoolVar(&useWatchers, "use-watchers", false,
"If set, client-go will use watchers instead of informers (this decreases resiliency saving resources)")

opts := zap.Options{
Development: true,
Expand Down Expand Up @@ -185,7 +190,13 @@ func main() {
workloadController := xyz.WorkloadController{
Client: mgr.GetClient(),
Options: xyz.WorkloadControllerOptions{
EventsPerSecond: eventsPerSecond,
UseWatchers: useWatchers,

// Options for pure Watchers
WatcherEventsPerSecond: watcherEventsPerSecond,

// Options for Informers
InformerSecondsToResync: informerSecondsToResync,
},
}

Expand Down
2 changes: 1 addition & 1 deletion config/samples/config/notifik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ integrations:

# (Optional) Configuration parameters to be able to connect with Alertmanager
alertmanager:
url: "https://${TEST_USERNAME}:${TEST_PASSWORD}@webhook.site/d0fd5417-8931-476c-ae6e-c41eda3682af"
url: "https://${TEST_USERNAME}:${TEST_PASSWORD}@webhook.site/c78d856d-8cb3-41e8-ae1c-964c6e8bf304"
headers:
X-Scope-OrgID: freepik-company
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ spec:
# The 'key' field admits vitamin Golang templating (well known from Helm)
# The result of this field will be compared with 'value' for equality
key: |
{{- $source := . -}}
{{- $source := .object -}}
{{- printf "%s" $source.metadata.name -}}
value: testing

message:
reason: "NameMatchedAlert"
data: |
{{- $source := . -}}
{{- $source := .object -}}
{{- $now := (now | date "2006-01-02T15:04:05Z07:00") -}}
{{- $alertStructure := (printf `
{
Expand All @@ -43,7 +43,7 @@ spec:
},
"labels": {
"namespace": "%s",
"name": "%s",
"name": "%s"
},
"generatorURL": "string"
}` $now $source.metadata.namespace $source.metadata.name) -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ spec:
# The 'key' field admits vitamin Golang templating (well known from Helm)
# The result of this field will be compared with 'value' for equality
key: |
{{- $source := . -}}
{{- $source := .object -}}
{{- printf "%s" $source.metadata.name -}}
value: testing

message:
reason: "NameMatchedAlert"
data: |
{{- $source := . -}}
{{- $source := .object -}}
{{- $now := (now | date "2006-01-02T15:04:05Z07:00") -}}
{{- $alertStructure := (printf `
startsAt: "%s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ spec:
# The 'key' field admits vitamin Golang templating (well known from Helm)
# The result of this field will be compared with 'value' for equality
key: |
{{- $source := . -}}
{{- $source := .object -}}
{{- printf "%s" $source.metadata.name -}}
value: testing

message:
reason: "NameMatchedAlert"
data: |
{{- $source := . -}}
{{- $source := .object -}}
{{- printf "Hi, I'm on fire: %s/%s" $source.metadata.namespace $source.metadata.name -}}
Binary file added docs/img/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 389385f

Please sign in to comment.