-
Notifications
You must be signed in to change notification settings - Fork 2
/
collector_test.sh
executable file
·76 lines (67 loc) · 2.15 KB
/
collector_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Source environment variables
if [ -z "$FULL_NAMESPACE" ]; then
echo "FULL_NAMESPACE not found, please run build.sh first to set up environment"
exit 1 # it is fine to exit with 1 here, as setup should not proceed past this
fi
# parse --env-file argument
while [[ "$#" -gt 0 ]]; do
case $1 in
--env-file) ENV_FILE="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
source "$ENV_FILE"
# Set default values if not found in env
if [ -z "$LOCAL_COLLECTOR_PORT" ]; then
export LOCAL_COLLECTOR_PORT=50051
fi
echo "🔄 Starting collector connectivity checks..."
# Array of hosts to try
hosts=("localhost" "127.0.0.1" "0.0.0.0")
test_ping=false
test_namespace=false
# Test port connectivity
if command -v nc &> /dev/null; then
test_command="nc -z"
for host in "${hosts[@]}"; do
echo " ⏳ Testing ${host}:${LOCAL_COLLECTOR_PORT}"
if ${test_command} "${host}" "${LOCAL_COLLECTOR_PORT}" 2>/dev/null; then
test_ping=true
break
fi
done
else
test_command="curl -s --connect-timeout 5"
for host in "${hosts[@]}"; do
echo " ⏳ Testing ${host}:${LOCAL_COLLECTOR_PORT}"
if $test_command "${host}:${LOCAL_COLLECTOR_PORT}" 2>/dev/null; then
test_ping=true
break
fi
done
fi
# Test container status
container_name="snapshotter-lite-local-collector-${SLOT_ID}-${FULL_NAMESPACE}"
if ! docker ps | grep -q "$container_name"; then
echo "❌ Collector container not found: $container_name"
else
echo "✅ Collector container running: $container_name"
test_namespace=true
fi
# Final status check
if [ "$test_ping" = true ] && [ "$test_namespace" = true ]; then
echo "✅ Collector is running and reachable"
exit 100
else
echo "⚠️ No active collector found - searching for available ports..."
for port in {50051..50059}; do
if ! nc -z localhost $port 2>/dev/null; then
echo "✅ Found available port: $port"
sed -i".backup" "s/^LOCAL_COLLECTOR_PORT=.*/LOCAL_COLLECTOR_PORT=${port}/" "${ENV_FILE}"
break
fi
done
exit 101
fi