Skip to content

Commit

Permalink
Merge pull request #139 from Kuadrant/redis-cached-new-params
Browse files Browse the repository at this point in the history
✨ redis cached: batch size option
  • Loading branch information
eguzki authored May 21, 2024
2 parents f586167 + b2d58ac commit f4f05c9
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/limitador_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions bundle/manifests/limitador.kuadrant.io_limitadors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/limitador.kuadrant.io_limitadors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
2 changes: 2 additions & 0 deletions controllers/limitador_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -633,6 +634,7 @@ var _ = Describe("Limitador controller", func() {
"--flush-period", "3",
"--max-cached", "4",
"--response-timeout", "5",
"--batch-size", "6",
),
)
}, specTimeOut)
Expand Down
14 changes: 7 additions & 7 deletions doc/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
```

Expand Down
3 changes: 3 additions & 0 deletions pkg/limitador/redis_cache_storage_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions pkg/limitador/redis_cache_storage_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -120,6 +121,7 @@ func TestRedisCachedDeploymentOptions(t *testing.T) {
"--flush-period", "3",
"--max-cached", "4",
"--response-timeout", "5",
"--batch-size", "6",
},
},
)
Expand Down

0 comments on commit f4f05c9

Please sign in to comment.