Skip to content

Commit 8a3338a

Browse files
committed
Logs broker connect/disconnect state
1 parent 2ab6fe2 commit 8a3338a

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

test/basic-with-kafkacat.yml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,39 @@ data:
1515
exec >> /tmp/testlog
1616
exec 2>&1
1717
18-
LAST_TS=$(kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '%T\n' -c 1 -u)
18+
PRODUCE_WAIT=.1
19+
MAX_AGE=5
20+
21+
UNIQUE="${HOSTNAME}@$(date -u -Ins)"
22+
23+
echo "Test $UNIQUE" >> /shared/produce.tmp
24+
sleep $PRODUCE_WAIT
25+
LAST=$(kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '%T= %s' -c 1 -u)
26+
27+
LAST_TS=$(echo $LAST | awk -F'= ' '{print $1}')
28+
LAST_MSG=$(echo $LAST | awk -F'= ' '{print $2}')
1929
NOW=$(date -u +%s%3N)
20-
echo "$NOW ($(date +%FT%H:%M:%S.%3N)):"
21-
echo "$LAST_TS"
22-
echo "$((($NOW - $LAST_TS)/1000)) seconds old"
30+
DIFF_S=$((($NOW - $LAST_TS)/1000))
31+
DIFF_MS=$((($NOW - $LAST_TS)%1000))
32+
#echo "$NOW ($(date +%FT%H:%M:%S.%3N)):"
33+
#echo "$LAST_TS"
34+
35+
if [ $DIFF_S -gt $MAX_AGE ]; then
36+
echo "Last message is $DIFF_S.$DIFF_MS old:"
37+
echo "$LAST_MSG"
38+
exit 10
39+
fi
2340
24-
#Q_TS=$(date -u +%s%3N)
25-
Q_TS=$LAST_TS
26-
kafkacat -Q -b $BOOTSTRAP -t test-basic-with-kafkacat:0:$Q_TS
41+
if [[ "$LAST_MSG" != *"$UNIQUE" ]]; then
42+
echo "Last message (at $LAST_TS) isn't from this test run ($UNIQUE):"
43+
echo "$LAST_MSG"
44+
exit 11
45+
fi
46+
47+
# get info about this message
48+
kafkacat -Q -b $BOOTSTRAP -t test-basic-with-kafkacat:0:$LAST_TS
49+
50+
# We haven't asserted that the consumer works, so we'll just have to assume that it will exit if it fails
2751
2852
exit 0
2953
@@ -91,7 +115,7 @@ spec:
91115
- >
92116
echo "--- start $HOSTNAME $(date --iso-8601='ns' -u) ---" >> /shared/produce.tmp;
93117
tail -f /shared/produce.tmp |
94-
kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v -T;
118+
kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v -T -d broker;
95119
volumeMounts:
96120
- name: config
97121
mountPath: /test
@@ -106,7 +130,7 @@ spec:
106130
- /bin/bash
107131
- -cex
108132
- >
109-
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '[%p,%o] %s\n' -u
133+
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '[%p,%o] %s\n' -u -d broker;
110134
volumeMounts:
111135
- name: config
112136
mountPath: /test
@@ -116,7 +140,6 @@ spec:
116140
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
117141
env:
118142
- name: BOOTSTRAP
119-
#value: kafka-0.broker.kafka.svc.cluster.local:9092,kafka-1.broker.kafka.svc.cluster.local:9092,kafka-2.broker.kafka.svc.cluster.local:9092
120143
value: kafka-0.broker.kafka.svc.cluster.local:9092
121144
command:
122145
- /bin/bash
@@ -139,6 +162,8 @@ spec:
139162
volumeMounts:
140163
- name: config
141164
mountPath: /test
165+
- name: shared
166+
mountPath: /shared
142167
volumes:
143168
- name: config
144169
configMap:

0 commit comments

Comments
 (0)