nrvnrvn / k8dis

Redis Operator for Kubernetes
Apache License 2.0
5 stars 0 forks source link

What's the best way to enable logging of GET/SET? #6

Open nrvnrvn opened 2 years ago

nrvnrvn commented 2 years ago

From https://github.com/amaizfinance/redis-operator/issues/32: Hi @nrvnrvn ,

I would like to have your thoughts so in development environment I can debug all GET/SET from the Redis cluster through the operator.

This one can be done by running a command redis-cli monitor (https://redis.io/commands/MONITOR) that watches all events and logs them (can be written to a file if wanted). But I don't know what would be the best practice to make it "embedded" with the operator.

Should the operator launch another container just doing sleep X && redis-cli monitor (the sleep would be to wait for the other container Redis server to be ready)? Or do you see something better? Maybe I should create this deployment on my own without relying on the operator?

In both cases, should my redis-cli monitor watches all the cluster, or just the master?

Thank you, @sneko

For now I'm using a "homemade" solution (another pod):

apiVersion: v1
kind: Pod
metadata:
  name: redis-logger
spec:
  containers:
  - name: redis-logger
    image: redis:5-alpine
    imagePullPolicy: Always
    # Note: exclude all "ping" logs that are just noise
    # [WORKAROUND] For whatever reason even if the "grep" example is the best one it won't work within "command/args" on Kubernetes. Like if "grep -v XXX" was always considered as looking for "-v XXX" instead of excluding "XXX"
    # I did multiple attempts by quotes, using "command" array, "args" array... none worked whereas directly on the pod it works as expected. Anyway found a less precise but working filter with "awk" instead :)
    # command: ["/bin/sh", "-c", "/usr/local/bin/redis-cli -h $(REDIS_MASTER_HOST) -p $(REDIS_MASTER_PORT) MONITOR | grep -v \"] \\\"ping\\\"\""]
    command: ["/bin/sh", "-c", "/usr/local/bin/redis-cli -h $(REDIS_MASTER_HOST) -p $(REDIS_MASTER_PORT) MONITOR | awk !/\"ping\"/"]
    env:
    - name: REDIS_MASTER_HOST
      valueFrom:
        configMapKeyRef:
          name: XXXXXX
          key: redis.master.host
    - name: REDIS_MASTER_PORT
      valueFrom:
        configMapKeyRef:
          name: XXXXXX
          key: redis.master.port

Hope it can help :)