Troubleshooting Kafka
Exception: KafkaError{code=OFFSET_OUT_OF_RANGE,val=1,str="Broker: Offset out of range"}
This happens where Kafka and the consumers get out of sync. Possible reasons are:
- Running out of disk space or memory
- Having a sustained event spike that causes very long processing times, causing Kafka to drop messages as they go past the retention time
- Date/time out of sync issues due to a restart or suspend/resume cycle
Note: These solutions may result in data loss when resetting the offset of the snuba consumers.
The proper solution is as follows (reported by @rmisyurev):
- Receive consumers list:Copied
docker compose run --rm kafka kafka-consumer-groups --bootstrap-server kafka:9092 --list
- Get group info:Copied
docker compose run --rm kafka kafka-consumer-groups --bootstrap-server kafka:9092 --group snuba-consumers --describe
- Watching what is going to happen with offset by using dry-run (optional):Copied
docker compose run --rm kafka kafka-consumer-groups --bootstrap-server kafka:9092 --group snuba-consumers --topic events --reset-offsets --to-latest --dry-run
- Set offset to latest and execute:Copied
docker compose run --rm kafka kafka-consumer-groups --bootstrap-server kafka:9092 --group snuba-consumers --topic events --reset-offsets --to-latest --execute
Tip
You can replace snuba-consumers
with other consumer groups or events
with other topics when needed.
This option is as follows (reported by @gabn88):
- Set offset to latest and execute:Copied
docker compose run --rm kafka kafka-consumer-groups --bootstrap-server kafka:9092 --all-groups --all-topics --reset-offsets --to-latest --execute
Unlike the proper solution, this involves resetting the offsets of all consumer groups and all topics.
The nuclear option is removing all Kafka-related volumes and recreating them which will cause data loss. Any data that was pending there will be gone upon deleting these volumes.
Stop the instance:
Copieddocker compose down --volumes
Remove the Kafka & Zookeeper related volumes:
Copieddocker volume rm sentry-kafka docker volume rm sentry-zookeeper
Run the install script again:
Copied./install.sh
Start the instance:
Copieddocker compose up --wait
If you want to reduce the disk space used by Kafka, you'll need to carefully calculate how much data you are ingesting, how much data loss you can tolerate and then follow the recommendations on this awesome StackOverflow post or this post on our community forum.
You could, however, add these on the Kafka container's environment variables (by @csvan):
services:
kafka:
# ...
environment:
KAFKA_LOG_RETENTION_HOURS: 24
KAFKA_LOG_CLEANER_ENABLE: true
KAFKA_LOG_CLEANUP_POLICY: delete
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").