From 21e6fed47a071985b906ed9c941c327f4fd55c03 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Tue, 16 Jan 2024 19:01:23 +0200 Subject: [PATCH] add changelog and manifest --- changelog/CHANGELOG.md | 2 + event_reporter/reporter/rate_limiter_test.go | 46 +++++++++++++++++++ .../event-reporter-statefulset.yaml | 18 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 changelog/CHANGELOG.md create mode 100644 event_reporter/reporter/rate_limiter_test.go diff --git a/changelog/CHANGELOG.md b/changelog/CHANGELOG.md new file mode 100644 index 0000000000000..cd33a58f215ff --- /dev/null +++ b/changelog/CHANGELOG.md @@ -0,0 +1,2 @@ +### Event reporter v2.0.3 +1. Implemented a fixed window rate limiter for the event reporter to prevent the application from overflowing the entire reporter queue. This enhancement ensures timely reporting without causing delays for other applications. \ No newline at end of file diff --git a/event_reporter/reporter/rate_limiter_test.go b/event_reporter/reporter/rate_limiter_test.go new file mode 100644 index 0000000000000..bba89a9a39929 --- /dev/null +++ b/event_reporter/reporter/rate_limiter_test.go @@ -0,0 +1,46 @@ +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/manifests/base/event-reporter/event-reporter-statefulset.yaml b/manifests/base/event-reporter/event-reporter-statefulset.yaml index 4174f47e4848b..8ea5c50cf9518 100644 --- a/manifests/base/event-reporter/event-reporter-statefulset.yaml +++ b/manifests/base/event-reporter/event-reporter-statefulset.yaml @@ -25,6 +25,24 @@ spec: args: - /usr/local/bin/event-reporter-server env: + - name: RATE_LIMITER_ENABLED + valueFrom: + configMapKeyRef: + name: argocd-cmd-params-cm + key: event-reporter.rate-limiter.enabled + optional: true + - name: RATE_LIMITER_BUCKET_SIZE + valueFrom: + configMapKeyRef: + name: argocd-cmd-params-cm + key: event-reporter.rate-limiter.bucket-size + optional: true + - name: RATE_LIMITER_DURATION + valueFrom: + configMapKeyRef: + name: argocd-cmd-params-cm + key: event-reporter.rate-limiter.duration + optional: true - name: EVENT_REPORTER_REPLICAS value: "5" - name: ARGOCD_TOKEN