Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis cached: response timeout #128

Merged
merged 2 commits into from
Apr 5, 2024
Merged

redis cached: response timeout #128

merged 2 commits into from
Apr 5, 2024

Conversation

eguzki
Copy link
Contributor

@eguzki eguzki commented Apr 4, 2024

What

Resilient cache was introduced in Kuadrant/limitador#279 with a new command line argument for redis_cached backend storage: --response-timeout <timeout> Timeout for Redis commands in milliseconds [default: 350]

docker run --rm -t limitador:local limitador-server limit.yaml redis_cached --help
Uses Redis to store counters, with an in-memory cache

Usage: limitador-server <LIMITS_FILE> redis_cached [OPTIONS] <URL>

Arguments:
  <URL>  Redis URL to use

Options:
      --ttl <TTL>                   TTL for cached counters in milliseconds [default: 5000]
      --ratio <ratio>               Ratio to apply to the TTL from Redis on cached counters [default: 10]
      --flush-period <flush>        Flushing period for counters in milliseconds [default: 1000]
      --max-cached <max>            Maximum amount of counters cached [default: 10000]
      --response-timeout <timeout>  Timeout for Redis commands in milliseconds [default: 350]
  -h, --help                        Print help

This PR exposes response-timeout at the Limitador CRD

Verification steps

dev setup

make local-setup

deploy redis

kubectl create namespace redis-ns
kubectl -n redis-ns apply -f - <<EOF
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  labels:
    app: redis
spec:
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
        - name: redis
          image: redis
---
apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  selector:
    app: redis
  ports:
    - name: redis
      port: 6379
      protocol: TCP
      targetPort: 6379
EOF

Deploy the limitador CR with redis-cached storage with response timeout set to 500ms

k apply -f - <<EOF
---
apiVersion: v1
kind: Secret
metadata:
  name: redisconfig
stringData:
  URL: redis://redis.redis-ns:6379
type: Opaque
EOF
k apply -f - <<EOF
---
apiVersion: limitador.kuadrant.io/v1alpha1
kind: Limitador
metadata:
  name: limitador
spec:
  storage:
    redis-cached:
      configSecretRef:
        name: redisconfig
      options:
        response-timeout: 500
  limits:
    - conditions: []
      max_value: 2
      namespace: toystore-app
      seconds: 30
      variables: []
EOF

Check deployment is correct

kubectl wait --timeout=300s --for=condition=Ready limitador limitador

Should return

limitador.limitador.kuadrant.io/limitador condition met

Check command line

kubectl get deployment/limitador-limitador  -o yaml | yq '.spec.template.spec.containers[0].command'

should look like this

- limitador-server
- --http-port
- "8080"
- --rls-port
- "8081"
- /home/limitador/etc/limitador-config.yaml
- redis_cached
- $(LIMITADOR_OPERATOR_REDIS_URL)
- --response-timeout
- "500"

@eguzki eguzki added kind/enhancement New feature or request size/small labels Apr 4, 2024
@eguzki eguzki self-assigned this Apr 4, 2024
@eguzki eguzki marked this pull request as ready for review April 4, 2024 17:42
@codecov-commenter
Copy link

Codecov Report

Merging #128 (0ca5e04) into main (06400fd) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
+ Coverage   68.11%   68.19%   +0.08%     
==========================================
  Files          16       16              
  Lines        1151     1154       +3     
==========================================
+ Hits          784      787       +3     
  Misses        325      325              
  Partials       42       42              
Flag Coverage Δ
unit 66.29% <100.00%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
api/v1alpha1 (u) 100.00% <ø> (ø)
pkg/helpers (u) ∅ <ø> (∅)
pkg/log (u) 31.81% <ø> (ø)
pkg/reconcilers (u) 36.76% <ø> (ø)
pkg/limitador (u) 88.12% <100.00%> (+0.09%) ⬆️
controllers (i) 72.57% <ø> (ø)
Files Coverage Δ
api/v1alpha1/limitador_types.go 100.00% <ø> (ø)
pkg/limitador/redis_cache_storage_options.go 100.00% <100.00%> (ø)

Copy link
Member

@adam-cattermole adam-cattermole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great, run through verification steps and all working, also tested update and removal

@eguzki eguzki merged commit e9207fb into main Apr 5, 2024
11 checks passed
@eguzki eguzki deleted the response-timeout branch April 5, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request size/small
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants