8686 GAME_STATS_WINDOW_DURATION : 20
8787 SUBMISSION_TIMEOUT_SECONDS : 120 # Timeout for the python submission script itself
8888 # --- 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- }
17289
17390 steps :
17491 - name : Checkout code at RC tag
@@ -347,11 +264,10 @@ jobs:
347264 - name : Validate Leaderboard Results (Direct Runner)
348265 run : |
349266 source beam_env/bin/activate
350- eval "$VALIDATE_TABLE_FUNC"
351267 echo "Validating BigQuery results for Leaderboard (DirectRunner)..."
352268 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
355271 echo "Leaderboard (Direct Runner) BQ validation finished successfully."
356272 shell : bash
357273
@@ -426,11 +342,10 @@ jobs:
426342 exit 0 # Exit step successfully to allow cancellation/cleanup
427343 fi
428344 source beam_env/bin/activate
429- eval "$VALIDATE_TABLE_FUNC"
430345 echo "Validating BigQuery results for Leaderboard (DataflowRunner)..."
431346 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
434349 echo "Leaderboard (Dataflow Runner) BQ validation finished successfully."
435350 shell : bash
436351
@@ -451,7 +366,7 @@ jobs:
451366 echo "leaderboard_dataflow_jobid.txt not found, cannot cancel job (it might have failed before ID extraction)."
452367 fi
453368 shell : bash
454-
369+
455370 # ================== GameStats Tests ==================
456371 - name : Run GameStats (Direct Runner) in Background
457372 run : |
@@ -471,12 +386,11 @@ jobs:
471386 - name : Validate GameStats Results (Direct Runner)
472387 run : |
473388 source beam_env/bin/activate
474- eval "$VALIDATE_TABLE_FUNC"
475389 echo "Validating BigQuery results for GameStats (DirectRunner)..."
476390 echo "* Sleeping for 25mins"
477391 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
480394 echo "GameStats (Direct Runner) BQ validation finished successfully."
481395 shell : bash
482396
@@ -552,12 +466,11 @@ jobs:
552466 exit 0 # Exit step successfully to allow cleanup
553467 fi
554468 source beam_env/bin/activate
555- eval "$VALIDATE_TABLE_FUNC"
556469 echo "Validating BigQuery results for GameStats (DataflowRunner)..."
557470 echo "* Sleeping for 25mins"
558471 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
561474 echo "GameStats (Dataflow Runner) BQ validation finished successfully."
562475 shell : bash
563476
0 commit comments