86
86
GAME_STATS_WINDOW_DURATION : 20
87
87
SUBMISSION_TIMEOUT_SECONDS : 120 # Timeout for the python submission script itself
88
88
# --- Define the validation function with enhanced debugging (FIXED QUOTING) ---
89
- VALIDATE_TABLE_FUNC : |
90
- validate_table() {
91
- local table_name=$1
92
- echo "DEBUG: ===== Starting validate_table for table: $table_name ====="
93
- # Ensure required env vars are set (GCP_PROJECT_ID, BQ_DATASET are inherited)
94
- if [[ -z "$GCP_PROJECT_ID" || -z "$BQ_DATASET" ]]; then
95
- echo "ERROR: GCP_PROJECT_ID and BQ_DATASET must be set in the environment."
96
- exit 1
97
- fi
98
-
99
- local full_table_id="${GCP_PROJECT_ID}.${BQ_DATASET}.${table_name}"
100
- local full_table_id_show="${GCP_PROJECT_ID}:${BQ_DATASET}.${table_name}"
101
- local count=""
102
- local exit_code=1
103
- local retries=10
104
- local delay=60 # Default seconds between retries
105
-
106
- # Allow overriding delay via second argument (optional)
107
- if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then
108
- delay=$2
109
- echo "DEBUG: Using custom retry delay: ${delay}s for table ${table_name}"
110
- else
111
- echo "DEBUG: Using default retry delay: ${delay}s for table ${table_name}"
112
- fi
113
- echo "DEBUG: Full table ID: ${full_table_id}, Max retries: ${retries}"
114
-
115
- for i in $(seq 1 $retries); do
116
- echo "DEBUG: Starting attempt $i/$retries..."
117
- local query_output
118
-
119
- echo "DEBUG: Executing: bq query --project_id=${GCP_PROJECT_ID} --use_legacy_sql=false --format=sparse --max_rows=1 \"SELECT COUNT(*) FROM \`${full_table_id}\`\""
120
- query_output=$(bq query --project_id=${GCP_PROJECT_ID} \
121
- --use_legacy_sql=false \
122
- --format=sparse \
123
- --max_rows=1 \
124
- "SELECT COUNT(*) FROM \`${full_table_id}\`" 2>&1)
125
- exit_code=$?
126
-
127
- echo "DEBUG: bq query exit code: $exit_code"
128
- echo "DEBUG: bq query raw output: [$query_output]"
129
-
130
- if [ $exit_code -eq 0 ]; then
131
- echo "DEBUG: bq query exited successfully (code 0)."
132
- count=$(echo "$query_output" | tail -n 1 | tr -d '[:space:]')
133
- echo "DEBUG: Processed count after removing whitespace (from last line): [$count]"
134
- if [[ "$count" =~ ^[0-9]+$ ]] && [ "$count" -gt 0 ]; then
135
- echo "DEBUG: Count [$count] is a positive integer. Validation successful for this attempt."
136
- break # Success! Found non-zero rows
137
- else
138
- echo "DEBUG: Count [$count] is zero or not a positive integer."
139
- if [[ "$count" == "0" ]]; then
140
- echo "DEBUG: Explicit count of 0 received."
141
- fi
142
- fi
143
- else
144
- echo "DEBUG: bq query failed (exit code: $exit_code)."
145
- echo "DEBUG: Checking table existence with bq show..."
146
- if ! bq show --project_id=${GCP_PROJECT_ID} "${full_table_id_show}" > /dev/null 2>&1; then
147
- echo "DEBUG: Table ${full_table_id_show} appears not to exist (bq show failed)."
148
- else
149
- echo "DEBUG: Table ${full_table_id_show} appears to exist (bq show succeeded), but query failed."
150
- fi
151
- fi
152
-
153
- if [ $i -lt $retries ]; then
154
- echo "DEBUG: Validation condition not met on attempt $i. Retrying in $delay seconds..."
155
- sleep $delay
156
- else
157
- echo "DEBUG: Final attempt ($i) failed."
158
- fi
159
- done
160
-
161
- echo "DEBUG: ===== Final validation check for table: $table_name ====="
162
- if [[ "$count" =~ ^[0-9]+$ ]] && [ "$count" -gt 0 ]; then
163
- echo "SUCCESS: Table ${table_name} has ${count} rows. Final validation OK."
164
- echo "DEBUG: validate_table returning 0 (success)."
165
- return 0 # Indicate success
166
- else
167
- echo "ERROR: Failed to get a non-zero row count for table ${table_name} after $retries retries (Last exit code: $exit_code, Last processed count: '$count')."
168
- echo "DEBUG: validate_table returning 1 (failure)."
169
- return 1 # Indicate failure
170
- fi
171
- }
172
89
173
90
steps :
174
91
- name : Checkout code at RC tag
@@ -347,11 +264,10 @@ jobs:
347
264
- name : Validate Leaderboard Results (Direct Runner)
348
265
run : |
349
266
source beam_env/bin/activate
350
- eval "$VALIDATE_TABLE_FUNC"
351
267
echo "Validating BigQuery results for Leaderboard (DirectRunner)..."
352
268
sleep 90
353
- validate_table "leader_board_users" || exit 1
354
- validate_table "leader_board_teams" || exit 1
269
+ ./scripts/tools/ validate_table.sh "leader_board_users" || exit 1
270
+ ./scripts/tools/ validate_table.sh "leader_board_teams" || exit 1
355
271
echo "Leaderboard (Direct Runner) BQ validation finished successfully."
356
272
shell : bash
357
273
@@ -426,11 +342,10 @@ jobs:
426
342
exit 0 # Exit step successfully to allow cancellation/cleanup
427
343
fi
428
344
source beam_env/bin/activate
429
- eval "$VALIDATE_TABLE_FUNC"
430
345
echo "Validating BigQuery results for Leaderboard (DataflowRunner)..."
431
346
sleep 240
432
- validate_table "leader_board_users" 15 || exit 1 # Use 15s retry delay
433
- validate_table "leader_board_teams" 15 || exit 1 # Use 15s retry delay
347
+ ./scripts/tools/ validate_table.sh "leader_board_users" 15 || exit 1 # Use 15s retry delay
348
+ ./scripts/tools/ validate_table.sh "leader_board_teams" 15 || exit 1 # Use 15s retry delay
434
349
echo "Leaderboard (Dataflow Runner) BQ validation finished successfully."
435
350
shell : bash
436
351
@@ -451,7 +366,7 @@ jobs:
451
366
echo "leaderboard_dataflow_jobid.txt not found, cannot cancel job (it might have failed before ID extraction)."
452
367
fi
453
368
shell : bash
454
-
369
+
455
370
# ================== GameStats Tests ==================
456
371
- name : Run GameStats (Direct Runner) in Background
457
372
run : |
@@ -471,12 +386,11 @@ jobs:
471
386
- name : Validate GameStats Results (Direct Runner)
472
387
run : |
473
388
source beam_env/bin/activate
474
- eval "$VALIDATE_TABLE_FUNC"
475
389
echo "Validating BigQuery results for GameStats (DirectRunner)..."
476
390
echo "* Sleeping for 25mins"
477
391
sleep 25m
478
- validate_table "game_stats_teams" || exit 1
479
- validate_table "game_stats_sessions" || exit 1
392
+ ./scripts/tools/ validate_table.sh "game_stats_teams" || exit 1
393
+ ./scripts/tools/ validate_table.sh "game_stats_sessions" || exit 1
480
394
echo "GameStats (Direct Runner) BQ validation finished successfully."
481
395
shell : bash
482
396
@@ -552,12 +466,11 @@ jobs:
552
466
exit 0 # Exit step successfully to allow cleanup
553
467
fi
554
468
source beam_env/bin/activate
555
- eval "$VALIDATE_TABLE_FUNC"
556
469
echo "Validating BigQuery results for GameStats (DataflowRunner)..."
557
470
echo "* Sleeping for 25mins"
558
471
sleep 25m
559
- validate_table "game_stats_teams" 15 || exit 1 # Use 15s retry delay
560
- validate_table "game_stats_sessions" 15 || exit 1 # Use 15s retry delay
472
+ ./scripts/tools/ validate_table.sh "game_stats_teams" 15 || exit 1 # Use 15s retry delay
473
+ ./scripts/tools/ validate_table.sh "game_stats_sessions" 15 || exit 1 # Use 15s retry delay
561
474
echo "GameStats (Dataflow Runner) BQ validation finished successfully."
562
475
shell : bash
563
476
0 commit comments