Skip to content

Commit b93c802

Browse files
author
Aleksander Błaszkiewicz
committed
feat: add better package check script
1 parent ae3772a commit b93c802

File tree

3 files changed

+126
-8
lines changed

3 files changed

+126
-8
lines changed

check-deployed-package/check.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
print()
1818

1919
api_key = os.environ.get('LOGDASH_API_KEY')
20+
logs_seed = os.environ.get('LOGS_SEED', 'default')
21+
metrics_seed = os.environ.get('METRICS_SEED', '1')
2022
print(f"Using API Key: {api_key}")
23+
print(f"Using Logs Seed: {logs_seed}")
24+
print(f"Using Metrics Seed: {metrics_seed}")
2125

2226
logdash = create_logdash({
2327
"api_key": api_key,
@@ -29,13 +33,20 @@
2933
# Get the metrics instance
3034
metrics = logdash.metrics
3135

32-
# Log some messages
33-
logger.log('This is an info log')
34-
logger.error('This is an error log')
36+
# Log some messages with seed appended
37+
logger.log('This is an info log', logs_seed)
38+
logger.error('This is an error log', logs_seed)
39+
logger.warn('This is a warning log', logs_seed)
40+
logger.debug('This is a debug log', logs_seed)
41+
logger.http('This is a http log', logs_seed)
42+
logger.silly('This is a silly log', logs_seed)
43+
logger.info('This is an info log', logs_seed)
44+
logger.verbose('This is a verbose log', logs_seed)
45+
46+
# Set and mutate metrics with seed
47+
metrics.set('users', metrics_seed)
48+
metrics.mutate('users', 1)
3549

36-
# Set and mutate metrics
37-
metrics.set('demo_users', 42)
38-
metrics.mutate('demo_counter', 1)
3950

4051
# Wait to ensure data is sent
4152
time.sleep(1)

check-deployed-package/run.sh

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/bin/sh
22
set -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+
412
echo "Building LogDash demo Docker image (using published package)..."
513
docker build --no-cache -t logdash-python-demo -f check-deployed-package/Dockerfile .
614

@@ -11,7 +19,106 @@ echo
1119
# Run in non-interactive mode which works everywhere
1220
docker 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

1626
echo
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!"

logdash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from logdash.metrics import MetricOperation
44

55
__all__ = ["create_logdash", "Logger", "MetricOperation"]
6-
__version__ = "1.0.2"
6+
__version__ = "1.0.4"

0 commit comments

Comments
 (0)