11#! /bin/sh
22set -e
33
4+ # Generate random 5-character seed
5+ LOGS_SEED=$( openssl rand -hex 2 | cut -c1-5)
6+ echo " Generated seed: $LOGS_SEED "
7+
8+ # Generate random metrics seed (1-1,000,000)
9+ METRICS_SEED=$( jot -r 1 1 1000000)
10+ echo " Generated metrics seed: $METRICS_SEED "
11+
412echo " Building LogDash demo Docker image (using published package)..."
513docker build --no-cache -t logdash-python-demo -f check-deployed-package/Dockerfile .
614
1119# Run in non-interactive mode which works everywhere
1220docker run --rm \
1321 -e LOGDASH_API_KEY=" ${LOGDASH_API_KEY} " \
22+ -e LOGS_SEED=" ${LOGS_SEED} " \
23+ -e METRICS_SEED=" ${METRICS_SEED} " \
1424 logdash-python-demo
1525
1626echo
17- echo " Demo completed!"
27+ echo " Demo completed!"
28+
29+ echo
30+ echo " Authenticating with LogDash API..."
31+
32+ # Authenticate with API using the API key
33+ AUTH_RESPONSE=$( curl -s -X ' POST' \
34+ ' https://api.logdash.io/auth/api-key' \
35+ -H ' accept: application/json' \
36+ -H ' Content-Type: application/json' \
37+ -d " {
38+ \" apiKey\" : \" ${LOGDASH_API_KEY} \"
39+ }" )
40+
41+ # Extract token and projectId from response
42+ TOKEN=$( echo " $AUTH_RESPONSE " | grep -o ' "token":"[^"]*"' | sed ' s/"token":"\(.*\)"/\1/' )
43+ PROJECT_ID=$( echo " $AUTH_RESPONSE " | grep -o ' "projectId":"[^"]*"' | sed ' s/"projectId":"\(.*\)"/\1/' )
44+
45+ if [ -z " $TOKEN " ] || [ -z " $PROJECT_ID " ]; then
46+ echo " Error: Failed to authenticate with LogDash API"
47+ echo " Response: $AUTH_RESPONSE "
48+ exit 1
49+ fi
50+
51+ echo " Authentication successful. Project ID: $PROJECT_ID "
52+
53+ echo
54+ echo " Fetching logs from LogDash API..."
55+
56+ # Fetch logs from the API
57+ LOGS_RESPONSE=$( curl -s -X ' GET' \
58+ " https://api.logdash.io/projects/${PROJECT_ID} /logs?limit=10" \
59+ -H ' accept: application/json' \
60+ -H " Authorization: Bearer ${TOKEN} " )
61+
62+ echo " Logs fetched successfully"
63+
64+ echo
65+ echo " Validating log messages..."
66+
67+ # Expected log messages with seed
68+ EXPECTED_MESSAGES=" This is an info log ${LOGS_SEED}
69+ This is an error log ${LOGS_SEED}
70+ This is a warning log ${LOGS_SEED}
71+ This is a debug log ${LOGS_SEED}
72+ This is a http log ${LOGS_SEED}
73+ This is a silly log ${LOGS_SEED}
74+ This is an info log ${LOGS_SEED}
75+ This is a verbose log ${LOGS_SEED} "
76+
77+ # Check if all expected messages are present in the logs
78+ echo " $EXPECTED_MESSAGES " | while IFS= read -r expected_msg; do
79+ if ! echo " $LOGS_RESPONSE " | grep -q " $expected_msg " ; then
80+ echo " Error: Expected log message not found: '$expected_msg '"
81+ echo " Logs response: $LOGS_RESPONSE "
82+ exit 1
83+ fi
84+ echo " ✓ Found: '$expected_msg '"
85+ done
86+
87+ echo
88+ echo " Fetching metrics from LogDash API..."
89+
90+ # Fetch metrics from the API
91+ METRICS_RESPONSE=$( curl -s -X ' GET' \
92+ " https://api.logdash.io/projects/${PROJECT_ID} /metrics" \
93+ -H ' accept: application/json' \
94+ -H " Authorization: Bearer ${TOKEN} " )
95+
96+ echo " Metrics fetched successfully"
97+
98+ echo
99+ echo " Validating metrics..."
100+
101+ # Expected users metric value (metrics_seed + 1)
102+ EXPECTED_USERS_VALUE=$(( METRICS_SEED + 1 ))
103+
104+ # Check if users metric exists with correct value
105+ if ! echo " $METRICS_RESPONSE " | grep -q ' "name":"users"' ; then
106+ echo " Error: Users metric not found"
107+ echo " Metrics response: $METRICS_RESPONSE "
108+ exit 1
109+ fi
110+
111+ # Extract the value of the users metric and check if it matches expected value
112+ USERS_VALUE=$( echo " $METRICS_RESPONSE " | grep -A 10 ' "name":"users"' | grep -o ' "value":[0-9]*' | sed ' s/"value"://' )
113+
114+ if [ " $USERS_VALUE " != " $EXPECTED_USERS_VALUE " ]; then
115+ echo " Error: Users metric value mismatch. Expected: $EXPECTED_USERS_VALUE , Found: $USERS_VALUE "
116+ echo " Metrics response: $METRICS_RESPONSE "
117+ exit 1
118+ fi
119+
120+ echo " ✓ Found users metric with correct value: $USERS_VALUE "
121+
122+ echo
123+ echo " All expected log messages and metrics found successfully!"
124+ echo " Validation completed!"
0 commit comments