Skip to content

Commit

Permalink
Add reliable check for Kafka broker being ready (#5154)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
Resolves #5148

## Description of the changes
- The previous approach used ```nc``` to check the availability of the
```Kafka port```, which was not reliable, especially when the Kafka
container was started asynchronously. The updated script now ensures a
more reliable check for Kafka readiness by attempting to list topics
using ```kafka-topics.sh``` within a loop. This modification ensures
that the script waits until Kafka is fully initialized before proceeding
with integration tests.

## How was this change tested?
- This modification ensures that the script waits until Kafka is fully
initialized before proceeding with integration tests.
- Ran ```bash scripts/kafka-integration-test.sh -k``` from the project
root.

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
  • Loading branch information
shashank-iitbhu authored Jan 29, 2024
1 parent befd5f4 commit ecf1dc0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/kafka-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ interval=5
end_time=$((SECONDS + timeout))

while [ $SECONDS -lt $end_time ]; do
if nc -z localhost 9092; then
# Check if Kafka is ready by attempting to describe a topic
if docker exec kafka /opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092 >/dev/null 2>&1; then
break
fi
echo "Kafka broker not ready, waiting ${interval} seconds"
sleep $interval
done

# Check if Kafka is still not available after the timeout
if ! nc -z localhost 9092; then
if ! docker exec kafka /opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092 >/dev/null 2>&1; then
echo "Timed out waiting for Kafka to start"
exit 1
fi

# Continue with the integration tests
make storage-integration-test

0 comments on commit ecf1dc0

Please sign in to comment.