Skip to content

Commit be493f2

Browse files
committed
working collector
Signed-off-by: MJarmo <michal.jarmolkiewicz@sap.com>
1 parent 4aff7b6 commit be493f2

2 files changed

Lines changed: 164 additions & 79 deletions

File tree

auditlog-config.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

setup-auditlog.sh

Lines changed: 164 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,58 @@
22

33
set -e
44

5-
echo "Step 1: Cloning opentelemetry-collector..."
6-
if [ -d "opentelemetry-collector" ]; then
7-
echo "Directory opentelemetry-collector already exists, skipping clone..."
8-
else
9-
git clone https://github.com/apeirora/opentelemetry-collector
10-
fi
11-
12-
echo "Step 2: Checking out to main branch..."
13-
cd opentelemetry-collector
14-
git checkout main
15-
cd ..
16-
17-
echo "Step 3: Cloning opentelemetry-collector-contrib..."
5+
echo "Step 1: Cloning opentelemetry-collector-contrib..."
186
if [ -d "opentelemetry-collector-contrib" ]; then
197
echo "Directory opentelemetry-collector-contrib already exists, skipping clone..."
208
else
219
git clone https://github.com/apeirora/opentelemetry-collector-contrib
2210
fi
2311

24-
echo "Step 4: Checking out contrib to main branch..."
12+
echo "Step 2: Checking out contrib to fixRedisStart branch..."
2513
cd opentelemetry-collector-contrib
26-
git checkout main
14+
git checkout fixRedisStart
2715
cd ..
2816

29-
echo "Step 5: Cloning opentelemetry-go..."
17+
echo "Step 3: Cloning opentelemetry-go..."
3018
if [ -d "opentelemetry-go" ]; then
3119
echo "Directory opentelemetry-go already exists, skipping clone..."
3220
else
3321
git clone https://github.com/apeirora/opentelemetry-go
3422
fi
3523

36-
echo "Step 6: Checking out to AuditLog branch..."
24+
echo "Step 4: Checking out to AuditLog branch..."
3725
cd opentelemetry-go
3826
git checkout AuditLog
3927
cd ..
4028

41-
echo "Step 7: Building otelcontribcol for Linux (Docker)..."
29+
echo "Step 5: Building otelcontribcol for Linux (Docker)..."
4230
cd opentelemetry-collector-contrib
4331

44-
if [ -f "bin/otelcontribcol_linux_amd64" ]; then
45-
echo "Linux binary already exists, skipping build..."
46-
echo "Found: bin/otelcontribcol_linux_amd64"
32+
NEEDS_REBUILD=0
33+
if [ ! -f "bin/otelcontribcol_linux_amd64" ]; then
34+
NEEDS_REBUILD=1
4735
else
36+
if [ -f "extension/storage/redisstorageextension/extension.go" ]; then
37+
if [ "extension/storage/redisstorageextension/extension.go" -nt "bin/otelcontribcol_linux_amd64" ] 2>/dev/null; then
38+
echo "Extension source code modified (newer than binary), rebuilding..."
39+
NEEDS_REBUILD=1
40+
else
41+
EXT_MOD_TIME=$(stat -c %Y "extension/storage/redisstorageextension/extension.go" 2>/dev/null || stat -f %m "extension/storage/redisstorageextension/extension.go" 2>/dev/null || echo "0")
42+
BIN_MOD_TIME=$(stat -c %Y "bin/otelcontribcol_linux_amd64" 2>/dev/null || stat -f %m "bin/otelcontribcol_linux_amd64" 2>/dev/null || echo "0")
43+
if [ "$EXT_MOD_TIME" -gt "$BIN_MOD_TIME" ] 2>/dev/null && [ "$EXT_MOD_TIME" != "0" ] && [ "$BIN_MOD_TIME" != "0" ]; then
44+
echo "Extension source code is newer than binary (by timestamp), rebuilding..."
45+
NEEDS_REBUILD=1
46+
fi
47+
fi
48+
fi
49+
fi
50+
51+
if [ $NEEDS_REBUILD -eq 0 ] && git status --porcelain extension/storage/redisstorageextension/extension.go 2>/dev/null | grep -q "^.M"; then
52+
echo "Extension source code has uncommitted changes, rebuilding to be safe..."
53+
NEEDS_REBUILD=1
54+
fi
55+
56+
if [ $NEEDS_REBUILD -eq 1 ]; then
4857
echo "Building Linux binary for Docker..."
4958
GOOS=linux GOARCH=amd64 make otelcontribcol
5059
if [ $? -eq 0 ]; then
@@ -53,12 +62,15 @@ else
5362
echo "Build failed!"
5463
exit 1
5564
fi
65+
else
66+
echo "Linux binary already exists and is up to date, skipping build..."
67+
echo "Found: bin/otelcontribcol_linux_amd64"
5668
fi
5769
cd ..
5870

59-
echo "Step 8: Build finished successfully, proceeding..."
71+
echo "Step 6: Build finished successfully, proceeding..."
6072

61-
echo "Step 9: Creating Docker network and starting Redis container..."
73+
echo "Step 7: Creating Docker network and starting Redis container..."
6274
if ! docker network ls --format '{{.Name}}' | grep -q "^otel-network$"; then
6375
echo "Creating Docker network 'otel-network'..."
6476
docker network create otel-network || {
@@ -218,11 +230,21 @@ else
218230
fi
219231
fi
220232

221-
echo "Step 10: Creating auditlog-config.yaml..."
222-
cat > auditlog-config.yaml << 'EOF'
233+
echo "Step 8: Creating auditlog-config.yaml..."
234+
echo "Getting Redis container IP address for config..."
235+
REDIS_IP_FOR_CONFIG=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis 2>/dev/null || echo "")
236+
if [ -z "$REDIS_IP_FOR_CONFIG" ]; then
237+
echo "Warning: Could not get Redis IP, using hostname 'redis'"
238+
REDIS_ENDPOINT="redis:6379"
239+
else
240+
echo "Using Redis IP address: $REDIS_IP_FOR_CONFIG"
241+
REDIS_ENDPOINT="${REDIS_IP_FOR_CONFIG}:6379"
242+
fi
243+
244+
cat > auditlog-config.yaml << EOF
223245
extensions:
224246
redis_storage:
225-
endpoint: redis:6379
247+
endpoint: ${REDIS_ENDPOINT}
226248
db: 0
227249
228250
receivers:
@@ -240,9 +262,9 @@ exporters:
240262
queue_size: 1000
241263
storage: redis_storage
242264
batch:
243-
flush_timeout: 1m
244-
min_size: 100
245-
max_size: 1000
265+
flush_timeout: 5s
266+
min_size: 1
267+
max_size: 100
246268
247269
service:
248270
extensions: [redis_storage]
@@ -261,7 +283,7 @@ service:
261283
exporters: [debug]
262284
EOF
263285

264-
echo "Step 11: Running collector in Docker container..."
286+
echo "Step 9: Running collector in Docker container..."
265287
cd opentelemetry-collector-contrib
266288

267289
if [ -f "bin/otelcontribcol_linux_amd64" ]; then
@@ -316,13 +338,34 @@ if [ -f "bin/otelcontribcol_linux_amd64" ]; then
316338
fi
317339

318340
echo "Ensuring Redis is fully ready before starting collector..."
319-
sleep 3
341+
echo "Testing Redis connectivity from Docker network (same as collector will use)..."
320342

321-
if docker exec redis redis-cli ping 2>&1 | grep -q "PONG"; then
322-
echo "Redis is confirmed ready - starting collector in Docker..."
323-
else
324-
echo "Error: Redis is not responding! Cannot start collector."
343+
MAX_RETRIES=15
344+
RETRY_COUNT=0
345+
REDIS_NETWORK_READY=0
346+
347+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
348+
if docker exec redis redis-cli ping 2>&1 | grep -q "PONG"; then
349+
REDIS_TEST=$(docker run --rm --network otel-network debian:bookworm-slim sh -c "apt-get update -qq >/dev/null 2>&1 && apt-get install -y -qq redis-tools >/dev/null 2>&1 && timeout 10 redis-cli -h redis -p 6379 ping 2>&1 && timeout 10 redis-cli -h redis -p 6379 SET test_key test_value 2>&1 && timeout 10 redis-cli -h redis -p 6379 GET test_key 2>&1 && timeout 10 redis-cli -h redis -p 6379 DEL test_key 2>&1" 2>/dev/null)
350+
if echo "$REDIS_TEST" | grep -q "PONG" && echo "$REDIS_TEST" | grep -q "test_value"; then
351+
echo "Redis is accessible and fully functional from Docker network!"
352+
REDIS_NETWORK_READY=1
353+
break
354+
fi
355+
fi
356+
RETRY_COUNT=$((RETRY_COUNT + 1))
357+
echo "Waiting for Redis network connectivity... ($RETRY_COUNT/$MAX_RETRIES)"
358+
sleep 2
359+
done
360+
361+
if [ $REDIS_NETWORK_READY -eq 0 ]; then
362+
echo "Error: Could not verify Redis connectivity from Docker network!"
363+
echo "This will cause the collector to fail. Please check Redis container status."
364+
docker ps --filter "name=redis" --format "table {{.Names}}\t{{.Status}}"
325365
exit 1
366+
else
367+
echo "Redis connectivity verified! Waiting 5 seconds for Redis to fully stabilize..."
368+
sleep 5
326369
fi
327370

328371
echo "Creating collector Docker container..."
@@ -357,30 +400,85 @@ if [ -f "bin/otelcontribcol_linux_amd64" ]; then
357400
echo "Binary path (Windows): $BINARY_PATH_WIN"
358401
echo "Config path (Windows): $CONFIG_PATH_WIN"
359402

403+
echo "Using Redis endpoint from config: $REDIS_ENDPOINT"
404+
REDIS_HOST_FOR_WAIT=$(echo "$REDIS_ENDPOINT" | cut -d: -f1)
405+
REDIS_PORT_FOR_WAIT=$(echo "$REDIS_ENDPOINT" | cut -d: -f2)
406+
360407
MSYS_NO_PATHCONV=1 docker run -d --name otel-collector \
361408
--network otel-network \
362-
--entrypoint /otelcontribcol \
363409
-v "${BINARY_PATH_WIN}:/otelcontribcol:ro" \
364410
-v "${CONFIG_PATH_WIN}:/auditlog-config.yaml:ro" \
365411
-p 4318:4318 \
366412
debian:bookworm-slim \
367-
--config /auditlog-config.yaml
413+
sh -c "apt-get update -qq >/dev/null 2>&1 && apt-get install -y -qq netcat-openbsd >/dev/null 2>&1 && sleep 5 && for i in \$(seq 1 40); do if nc -z '$REDIS_HOST_FOR_WAIT' '$REDIS_PORT_FOR_WAIT' 2>/dev/null; then echo 'Redis is ready at $REDIS_ENDPOINT!'; break; fi; echo \"Waiting for Redis at $REDIS_ENDPOINT... (\$i/40)\"; sleep 1; done && /otelcontribcol --config /auditlog-config.yaml"
368414

369415
if [ $? -eq 0 ]; then
370416
echo "Collector container started successfully!"
417+
echo "Waiting for container to fully initialize and join network..."
371418
sleep 5
372419

373420
if docker ps --format '{{.Names}}' | grep -q "^otel-collector$"; then
374421
echo "Collector container is running"
422+
echo "Testing Redis connectivity from within collector container..."
423+
424+
echo "Waiting for container network to be ready..."
425+
sleep 3
426+
427+
echo "Testing DNS resolution..."
428+
if docker exec otel-collector sh -c "getent hosts redis 2>&1" 2>/dev/null | grep -q "redis"; then
429+
echo "✓ DNS resolution works (redis hostname resolves)"
430+
else
431+
echo "✗ DNS resolution failed (redis hostname does not resolve)"
432+
fi
433+
434+
echo "Testing port connectivity..."
435+
if docker exec otel-collector sh -c "timeout 5 sh -c 'while ! nc -z redis 6379 2>/dev/null; do sleep 0.1; done'" 2>/dev/null; then
436+
echo "✓ Port 6379 is reachable"
437+
else
438+
echo "✗ Port 6379 is NOT reachable"
439+
fi
440+
441+
echo "Testing Redis connection using endpoint from config: $REDIS_ENDPOINT"
442+
REDIS_TEST_HOST=$(echo "$REDIS_ENDPOINT" | cut -d: -f1)
443+
REDIS_TEST_PORT=$(echo "$REDIS_ENDPOINT" | cut -d: -f2)
444+
REDIS_TEST_OUTPUT=$(docker exec otel-collector sh -c "apt-get update -qq >/dev/null 2>&1 && apt-get install -y -qq redis-tools >/dev/null 2>&1 && timeout 15 redis-cli -h '$REDIS_TEST_HOST' -p '$REDIS_TEST_PORT' ping 2>&1" 2>&1)
445+
if echo "$REDIS_TEST_OUTPUT" | grep -q "PONG"; then
446+
echo "✓ Collector container can reach Redis at $REDIS_ENDPOINT!"
447+
else
448+
echo "✗ WARNING: Collector container cannot reach Redis at $REDIS_ENDPOINT!"
449+
echo "Redis test output: $REDIS_TEST_OUTPUT"
450+
echo "Checking if containers are on the same network..."
451+
COLLECTOR_NETWORK=$(docker inspect otel-collector --format '{{range $net, $conf := .NetworkSettings.Networks}}{{$net}}{{end}}' 2>/dev/null)
452+
REDIS_NETWORK=$(docker inspect redis --format '{{range $net, $conf := .NetworkSettings.Networks}}{{$net}}{{end}}' 2>/dev/null)
453+
echo "Collector network: $COLLECTOR_NETWORK"
454+
echo "Redis network: $REDIS_NETWORK"
455+
if [ "$COLLECTOR_NETWORK" != "$REDIS_NETWORK" ]; then
456+
echo "ERROR: Containers are on different networks!"
457+
else
458+
echo "Containers are on the same network, but connection still fails"
459+
echo "This might be a timing issue - waiting longer and retrying..."
460+
sleep 5
461+
if docker exec otel-collector sh -c "timeout 15 redis-cli -h '$REDIS_TEST_HOST' -p '$REDIS_TEST_PORT' ping 2>&1" 2>/dev/null | grep -q "PONG"; then
462+
echo "✓ Redis connection works after additional wait!"
463+
else
464+
echo "✗ Redis connection still fails after wait"
465+
fi
466+
fi
467+
fi
468+
375469
echo "Waiting for collector to initialize..."
376470
sleep 5
377471

378472
echo "Checking collector logs..."
379473
if docker logs otel-collector 2>&1 | grep -qi "Everything is ready\|Starting HTTP server"; then
380474
echo "Collector started successfully in Docker!"
381475
elif docker logs otel-collector 2>&1 | grep -qi "error.*redis\|failed.*redis"; then
382-
echo "Warning: Collector may have Redis connection issues. Checking logs..."
383-
docker logs otel-collector 2>&1 | tail -20
476+
echo "ERROR: Collector has Redis connection issues!"
477+
echo "Last 30 lines of collector logs:"
478+
docker logs otel-collector 2>&1 | tail -30
479+
echo ""
480+
echo "Testing Redis from collector container again..."
481+
docker exec otel-collector sh -c "apt-get update -qq >/dev/null 2>&1 && apt-get install -y -qq redis-tools >/dev/null 2>&1 && timeout 10 redis-cli -h redis -p 6379 ping 2>&1" 2>&1 || echo "Redis test failed"
384482
else
385483
echo "Collector is starting up..."
386484
docker logs otel-collector 2>&1 | tail -10
@@ -411,7 +509,33 @@ else
411509
exit 1
412510
fi
413511

414-
echo "Step 12: Changing to opentelemetry-go directory..."
512+
echo "Step 10: Changing to opentelemetry-go directory..."
415513
cd ../opentelemetry-go
416514

515+
echo "Step 11: Running stress test with -quick flag..."
516+
cd examples/audit-log-stress-test
517+
518+
if [ -f "main.go" ]; then
519+
echo "Starting quick stress test (10k logs)..."
520+
echo "This will send logs to the collector and verify they are processed."
521+
echo ""
522+
go run . -quick
523+
STRESS_TEST_EXIT_CODE=$?
524+
if [ $STRESS_TEST_EXIT_CODE -eq 0 ]; then
525+
echo ""
526+
echo "✅ Stress test completed successfully!"
527+
else
528+
echo ""
529+
echo "⚠️ Stress test completed with exit code: $STRESS_TEST_EXIT_CODE"
530+
echo "Check the collector logs to see if logs were received:"
531+
echo " docker logs otel-collector --tail 50"
532+
fi
533+
else
534+
echo "Warning: stress test main.go not found in examples/audit-log-stress-test"
535+
echo "Skipping stress test..."
536+
fi
537+
538+
cd ../../..
539+
540+
echo ""
417541
echo "Setup complete!"

0 commit comments

Comments
 (0)