Search code examples
apache-kafkakafka-producer-api

How can I know that a kafka topic is full?


Lets say I have one kafka broker configured with one partition

log.retention.bytes=80000 
log.retention.hours=6

What will happen if I try to send a record with the producer api to a broker and the log of the topic got full before the retention period?

Will my message get dropped? Or will kafka free some space from the old messages and add mine?

How can I know if a topic is getting full and logs are being deleted before being consumed?
Is there a way to monitor or expose a metric when a topic is getting full?


Solution

  • What will happen if I try to send a record with the producer api to a broker and the log of the topic got full before the retention period? Will my message get dropped? Or will kafka free some space from the old messages and add mine?

    cleanup.policy property from topic config which by default is delete, says that "The delete policy will discard old segments when their retention time or size limit has been reached."

    So, if you send record with producer api and topic got full, it will discard old segments.

    How can I know if a topic is getting full and logs are being deleted before being consumed? Is there a way to monitor or expose a metric when a topic is getting full?

    You can get Partition size using below script:

    /bin/kafka-log-dirs.sh --describe --bootstrap-server : --topic-list
    

    You will need to develop a script that will run above script for fetching current size of topic and send it periodically to Datadog. In Datadog, you can create widget that will trigger appropriate action(e.g. sending email alerts) once size reaches a particular threshold.