From b2d58ac51f4e22f1fb1ad87ce039309c529d98b3 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Thu, 16 May 2024 17:15:48 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20redis=20cached:=20batch=20size=20op?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1alpha1/limitador_types.go | 4 ++++ api/v1alpha1/zz_generated.deepcopy.go | 5 +++++ .../limitador-operator.clusterserviceversion.yaml | 2 +- .../limitador.kuadrant.io_limitadors.yaml | 4 ++++ .../bases/limitador.kuadrant.io_limitadors.yaml | 4 ++++ controllers/limitador_controller_test.go | 2 ++ doc/storage.md | 14 +++++++------- pkg/limitador/redis_cache_storage_options.go | 3 +++ pkg/limitador/redis_cache_storage_options_test.go | 2 ++ 9 files changed, 32 insertions(+), 8 deletions(-) diff --git a/api/v1alpha1/limitador_types.go b/api/v1alpha1/limitador_types.go index 29b2ca1a..ea6ee44d 100644 --- a/api/v1alpha1/limitador_types.go +++ b/api/v1alpha1/limitador_types.go @@ -224,6 +224,10 @@ type RedisCachedOptions struct { // +optional // ResponseTimeout defines the timeout for Redis commands in milliseconds [default: 350] ResponseTimeout *int `json:"response-timeout,omitempty"` + + // +optional + // BatchSize defines the size of entries to flush in as single flush [default: 100] + BatchSize *int `json:"batch-size,omitempty"` } type RedisCached struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 7ddbe327..f86a96ca 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -436,6 +436,11 @@ func (in *RedisCachedOptions) DeepCopyInto(out *RedisCachedOptions) { *out = new(int) **out = **in } + if in.BatchSize != nil { + in, out := &in.BatchSize, &out.BatchSize + *out = new(int) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RedisCachedOptions. diff --git a/bundle/manifests/limitador-operator.clusterserviceversion.yaml b/bundle/manifests/limitador-operator.clusterserviceversion.yaml index 7436e33f..de495ab9 100644 --- a/bundle/manifests/limitador-operator.clusterserviceversion.yaml +++ b/bundle/manifests/limitador-operator.clusterserviceversion.yaml @@ -37,7 +37,7 @@ metadata: capabilities: Basic Install categories: Integration & Delivery containerImage: quay.io/kuadrant/limitador-operator:latest - createdAt: "2024-05-03T10:11:12Z" + createdAt: "2024-05-16T14:52:42Z" operators.operatorframework.io/builder: operator-sdk-v1.32.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/Kuadrant/limitador-operator diff --git a/bundle/manifests/limitador.kuadrant.io_limitadors.yaml b/bundle/manifests/limitador.kuadrant.io_limitadors.yaml index 4495a278..65710a9d 100644 --- a/bundle/manifests/limitador.kuadrant.io_limitadors.yaml +++ b/bundle/manifests/limitador.kuadrant.io_limitadors.yaml @@ -1055,6 +1055,10 @@ spec: x-kubernetes-map-type: atomic options: properties: + batch-size: + description: 'BatchSize defines the size of entries to + flush in as single flush [default: 100]' + type: integer flush-period: description: 'FlushPeriod for counters in milliseconds [default: 1000]' diff --git a/config/crd/bases/limitador.kuadrant.io_limitadors.yaml b/config/crd/bases/limitador.kuadrant.io_limitadors.yaml index cbb7160a..19df7af3 100644 --- a/config/crd/bases/limitador.kuadrant.io_limitadors.yaml +++ b/config/crd/bases/limitador.kuadrant.io_limitadors.yaml @@ -1056,6 +1056,10 @@ spec: x-kubernetes-map-type: atomic options: properties: + batch-size: + description: 'BatchSize defines the size of entries to + flush in as single flush [default: 100]' + type: integer flush-period: description: 'FlushPeriod for counters in milliseconds [default: 1000]' diff --git a/controllers/limitador_controller_test.go b/controllers/limitador_controller_test.go index 9192e775..93d0b4c4 100644 --- a/controllers/limitador_controller_test.go +++ b/controllers/limitador_controller_test.go @@ -603,6 +603,7 @@ var _ = Describe("Limitador controller", func() { FlushPeriod: ptr.To(3), MaxCached: ptr.To(4), ResponseTimeout: ptr.To(5), + BatchSize: ptr.To(6), } Expect(k8sClient.Create(ctx, limitadorObj)).Should(Succeed()) @@ -633,6 +634,7 @@ var _ = Describe("Limitador controller", func() { "--flush-period", "3", "--max-cached", "4", "--response-timeout", "5", + "--batch-size", "6", ), ) }, specTimeOut) diff --git a/doc/storage.md b/doc/storage.md index 285e5e34..c10feb39 100644 --- a/doc/storage.md +++ b/doc/storage.md @@ -108,12 +108,12 @@ Additionally, caching options can be specified in the `spec.storage.redis-cached ### Options -| Option | Description | -|----------------|-----------------------------------------------------------------------| -| `ttl` | TTL for cached counters in milliseconds [default: 5000] | -| `ratio` | Ratio to apply to the TTL from Redis on cached counters [default: 10] | -| `flush-period` | Flushing period for counters in milliseconds [default: 1000] | -| `max-cached` | Maximum amount of counters cached [default: 10000] | +| Option | Description | +|----------------------|-----------------------------------------------------------------------| +| `batch-size` | Size of entries to flush in as single flush [default: 100] | +| `flush-period` | Flushing period for counters in milliseconds [default: 1000] | +| `max-cached` | Maximum amount of counters cached [default: 10000] | +| `response-timeout` | Timeout for Redis commands in milliseconds [default: 350] | For example: @@ -128,7 +128,7 @@ spec: configSecretRef: # The secret reference storing the URL for Redis name: redisconfig options: # Every option is optional - ttl: 1000 + batch-size: 50 max-cached: 5000 ``` diff --git a/pkg/limitador/redis_cache_storage_options.go b/pkg/limitador/redis_cache_storage_options.go index 0d388d18..3228319b 100644 --- a/pkg/limitador/redis_cache_storage_options.go +++ b/pkg/limitador/redis_cache_storage_options.go @@ -30,6 +30,9 @@ func RedisCachedDeploymentOptions(ctx context.Context, cl client.Client, defSecr if redisCachedObj.Options.ResponseTimeout != nil { command = append(command, "--response-timeout", strconv.Itoa(*redisCachedObj.Options.ResponseTimeout)) } + if redisCachedObj.Options.BatchSize != nil { + command = append(command, "--batch-size", strconv.Itoa(*redisCachedObj.Options.BatchSize)) + } } return DeploymentStorageOptions{ diff --git a/pkg/limitador/redis_cache_storage_options_test.go b/pkg/limitador/redis_cache_storage_options_test.go index 32fc47b9..3a9ba601 100644 --- a/pkg/limitador/redis_cache_storage_options_test.go +++ b/pkg/limitador/redis_cache_storage_options_test.go @@ -108,6 +108,7 @@ func TestRedisCachedDeploymentOptions(t *testing.T) { FlushPeriod: ptr.To(3), MaxCached: ptr.To(4), ResponseTimeout: ptr.To(5), + BatchSize: ptr.To(6), }, } options, err := RedisCachedDeploymentOptions(ctx, cl, namespace, redisObj) @@ -120,6 +121,7 @@ func TestRedisCachedDeploymentOptions(t *testing.T) { "--flush-period", "3", "--max-cached", "4", "--response-timeout", "5", + "--batch-size", "6", }, }, )