diff --git a/VERSION b/VERSION index ce37d80924146..0f0493e10e366 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.9-2024.2.19-5d3b6792c \ No newline at end of file +2.9-2024.2.19-7f1e9b76a \ No newline at end of file diff --git a/changelog/CHANGELOG-2.9-2024.2.19-7f1e9b76a.md b/changelog/CHANGELOG-2.9-2024.2.19-7f1e9b76a.md new file mode 100644 index 0000000000000..5ae31eb65b85e --- /dev/null +++ b/changelog/CHANGELOG-2.9-2024.2.19-7f1e9b76a.md @@ -0,0 +1,2 @@ +### Features +- fix: revert 2.9-2024.2.4-fc84c8a9c due to cmp issue \ No newline at end of file diff --git a/cmd/event-reporter-server/commands/event_reporter_server.go b/cmd/event-reporter-server/commands/event_reporter_server.go index 29a1a3c9b5c8e..7faccc062705a 100644 --- a/cmd/event-reporter-server/commands/event_reporter_server.go +++ b/cmd/event-reporter-server/commands/event_reporter_server.go @@ -3,7 +3,6 @@ package commands import ( "context" "fmt" - "github.com/argoproj/argo-cd/v2/event_reporter/reporter" "math" "time" @@ -177,11 +176,6 @@ func NewCommand() *cobra.Command { BaseURL: codefreshUrl, AuthToken: codefreshToken, }, - RateLimiterOpts: &reporter.RateLimiterOpts{ - Enabled: rateLimiterEnabled, - Rate: rateLimiterDuration, - Capacity: rateLimiterBucketSize, - }, } log.Infof("Starting event reporter server with grpc transport %v", useGrpc) diff --git a/event_reporter/controller/controller.go b/event_reporter/controller/controller.go index 4f0008b771a84..e16137ac360a8 100644 --- a/event_reporter/controller/controller.go +++ b/event_reporter/controller/controller.go @@ -41,8 +41,8 @@ type eventReporterController struct { metricsServer *metrics.MetricsServer } -func NewEventReporterController(appInformer cache.SharedIndexInformer, cache *servercache.Cache, settingsMgr *settings.SettingsManager, applicationServiceClient appclient.ApplicationClient, appLister applisters.ApplicationLister, codefreshConfig *codefresh.CodefreshConfig, metricsServer *metrics.MetricsServer, featureManager *reporter.FeatureManager, rateLimiterOpts *reporter.RateLimiterOpts) EventReporterController { - appBroadcaster := reporter.NewBroadcaster(featureManager, metricsServer, rateLimiterOpts) +func NewEventReporterController(appInformer cache.SharedIndexInformer, cache *servercache.Cache, settingsMgr *settings.SettingsManager, applicationServiceClient appclient.ApplicationClient, appLister applisters.ApplicationLister, codefreshConfig *codefresh.CodefreshConfig, metricsServer *metrics.MetricsServer, featureManager *reporter.FeatureManager) EventReporterController { + appBroadcaster := reporter.NewBroadcaster(featureManager, metricsServer) appInformer.AddEventHandler(appBroadcaster) return &eventReporterController{ appBroadcaster: appBroadcaster, diff --git a/event_reporter/reporter/broadcaster.go b/event_reporter/reporter/broadcaster.go index 4d2b58f3beebf..0136d697f6a96 100644 --- a/event_reporter/reporter/broadcaster.go +++ b/event_reporter/reporter/broadcaster.go @@ -40,17 +40,15 @@ type broadcasterHandler struct { filter sharding.ApplicationFilterFunction featureManager *FeatureManager metricsServer *metrics.MetricsServer - rateLimiter *RateLimiter } -func NewBroadcaster(featureManager *FeatureManager, metricsServer *metrics.MetricsServer, rateLimiterOpts *RateLimiterOpts) Broadcaster { +func NewBroadcaster(featureManager *FeatureManager, metricsServer *metrics.MetricsServer) Broadcaster { // todo: pass real value here filter := getApplicationFilter("") return &broadcasterHandler{ filter: filter, featureManager: featureManager, metricsServer: metricsServer, - rateLimiter: NewRateLimiter(rateLimiterOpts), } } @@ -78,13 +76,6 @@ func (b *broadcasterHandler) notify(event *appv1.ApplicationWatchEvent) { for _, s := range subscribers { if s.matches(event) { - duration, err := b.rateLimiter.Limit(event.Application.Name) - if err != nil { - log.Infof("adding application '%s' to channel failed, due to rate limit, duration left %s", event.Application.Name, duration.String()) - b.metricsServer.IncAppEventsCounter(event.Application.Name, false) - continue - } - select { case s.ch <- event: { diff --git a/event_reporter/reporter/rate_limiter.go b/event_reporter/reporter/rate_limiter.go deleted file mode 100644 index 3b65f7db41da4..0000000000000 --- a/event_reporter/reporter/rate_limiter.go +++ /dev/null @@ -1,36 +0,0 @@ -package reporter - -import ( - "context" - "github.com/mennanov/limiters" - "time" -) - -type RateLimiterOpts struct { - Enabled bool - Rate time.Duration - Capacity int -} - -type RateLimiter struct { - opts *RateLimiterOpts - limiters map[string]*limiters.FixedWindow -} - -func NewRateLimiter(opts *RateLimiterOpts) *RateLimiter { - return &RateLimiter{opts: opts, limiters: make(map[string]*limiters.FixedWindow)} -} - -func (rl *RateLimiter) Limit(applicationName string) (time.Duration, error) { - if !rl.opts.Enabled { - return time.Duration(0), nil - } - - limiter := rl.limiters[applicationName] - if limiter == nil { - limiter = limiters.NewFixedWindow(int64(rl.opts.Capacity), rl.opts.Rate, limiters.NewFixedWindowInMemory(), limiters.NewSystemClock()) - rl.limiters[applicationName] = limiter - } - - return limiter.Limit(context.Background()) -} diff --git a/event_reporter/reporter/rate_limiter_test.go b/event_reporter/reporter/rate_limiter_test.go deleted file mode 100644 index bba89a9a39929..0000000000000 --- a/event_reporter/reporter/rate_limiter_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package reporter - -import ( - "testing" - "time" -) - -func TestRateLimiter(t *testing.T) { - t.Run("Limiter is turned off", func(t *testing.T) { - rl := NewRateLimiter(&RateLimiterOpts{ - Enabled: false, - }) - d, err := rl.Limit("foo") - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - if d != 0 { - t.Errorf("Expected 0 duration, got %v", d) - } - }) - t.Run("Limiter is turned on", func(t *testing.T) { - rl := NewRateLimiter(&RateLimiterOpts{ - Enabled: true, - Rate: time.Second, - Capacity: 1, - }) - d, err := rl.Limit("foo") - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - if d != 0 { - t.Errorf("Expected 0 duration, got %v", d) - } - }) - t.Run("Limiter is turned on but with 0 capacity", func(t *testing.T) { - rl := NewRateLimiter(&RateLimiterOpts{ - Enabled: true, - Rate: time.Second, - Capacity: 0, - }) - _, err := rl.Limit("foo") - if err == nil { - t.Errorf("Expected error, got nil") - } - }) -} diff --git a/event_reporter/server.go b/event_reporter/server.go index f65e1bbefc357..a90f1b6f41784 100644 --- a/event_reporter/server.go +++ b/event_reporter/server.go @@ -93,7 +93,6 @@ type EventReporterServerOpts struct { BaseHRef string RootPath string CodefreshConfig *codefresh.CodefreshConfig - RateLimiterOpts *reporter.RateLimiterOpts } type handlerSwitcher struct { @@ -153,7 +152,7 @@ func (a *EventReporterServer) Init(ctx context.Context) { } func (a *EventReporterServer) RunController(ctx context.Context) { - controller := event_reporter.NewEventReporterController(a.appInformer, a.Cache, a.settingsMgr, a.ApplicationServiceClient, a.appLister, a.CodefreshConfig, a.serviceSet.MetricsServer, a.featureManager, a.RateLimiterOpts) + controller := event_reporter.NewEventReporterController(a.appInformer, a.Cache, a.settingsMgr, a.ApplicationServiceClient, a.appLister, a.CodefreshConfig, a.serviceSet.MetricsServer, a.featureManager) go controller.Run(ctx) }