Diwali in the Cloud | GSP651

Solution for Diwali in the Cloud | GSP651. 1 lab: GSP651. Fast copy-paste commands for Google Cloud.

GSP651 — Setting Up Cost Control with Quota

Estimated time: 10 minutes

# 🚀 Setting Up Cost Control with Quota | GSP651 > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created for educational purposes, hands-on practice, and Google Cloud certification preparation. This guide helps learners understand BigQuery cost management, custom API quotas, and query usage restrictions. Always attempt the lab yourself first and follow Google Cloud Skills Boost / Qwiklabs Terms of Service. This walkthrough is not affiliated with or endorsed by Google, Go

clear
ORANGE=

\033[38;5;208m'
CYAN=

\033[0;36m'
GREEN=

\033[0;32m'
YELLOW=

\033[0;33m'
MAGENTA=

\033[0;35m'
BLUE=

\033[0;34m'
BOLD=

\033[1m'
RESET=

\033[0m'

echo "${CYAN}${BOLD}"
echo "   ____        _   _ _            __   ___              "
echo "  / __ \      | | (_) |          / _| / _ \             "
echo " | |  | |_ __| |__  _| |_  ___   | |_ | | | |_ __ ___  "
echo " | |  | | '__| '_ \| | __| / _ \ |  _|| | | | '_ \ / __| "
echo " | |__| | |  | |_) | | |_ | (_) || |  | |_| | |_) \__ \ "
echo "  \____/|_|  |_.__/|_|\__| \___/ |_|   \___/| .__/|___/ "
echo "                                            | |         "
echo "                                            |_|         "
echo "${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"
echo "${MAGENTA}${BOLD} STAGE 1: BigQuery Custom Quota & Cost Control            ${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"

echo "${YELLOW}▶ Checking project configuration...${RESET}"
export PROJECT_ID=$(gcloud config get-value project 2>/dev/null)
echo "${CYAN}Project ID : ${PROJECT_ID}${RESET}"

echo "${YELLOW}▶ Running initial query on WISE All-Sky public dataset (Task 1)...${RESET}"
bq query --use_legacy_sql=false "SELECT w1mpro_ep, mjd, load_id, frame_id FROM \`bigquery-public-data.wise_all_sky_data_release.mep_wise\` ORDER BY mjd ASC LIMIT 500" >/dev/null

echo "${GREEN}✓ Initial query completed (1.36 TB processed).${RESET}"

echo "${YELLOW}▶ Checking current BigQuery usage quotas (Task 3)...${RESET}"
gcloud alpha services quota list --service=bigquery.googleapis.com --consumer=projects/${PROJECT_ID} --filter="usage"

echo "${YELLOW}▶ Updating per-user query quota to 0.25 TiB (262144 MiB) per day...${RESET}"
gcloud alpha services quota update --consumer=projects/${PROJECT_ID} --service=bigquery.googleapis.com --metric=bigquery.googleapis.com/quota/query/usage --value=262144 --unit=1/d/{project}/{user} --force

echo "${YELLOW}▶ Verifying updated consumerQuotaLimits...${RESET}"
gcloud alpha services quota list --service=bigquery.googleapis.com --consumer=projects/${PROJECT_ID} --filter="usage"

echo "${YELLOW}▶ Waiting 15 seconds for quota override propagation...${RESET}"
sleep 15

echo "${YELLOW}▶ Rerunning query with cache disabled to trigger custom quota limit (Task 4)...${RESET}"
bq query --use_legacy_sql=false --nouse_cache "SELECT w1mpro_ep, mjd, load_id, frame_id FROM \`bigquery-public-data.wise_all_sky_data_release.mep_wise\` ORDER BY mjd ASC LIMIT 500" >/dev/null 2>&1 || true

bq query --use_legacy_sql=false --nouse_cache "SELECT w1mpro_ep, mjd, load_id, frame_id FROM \`bigquery-public-data.wise_all_sky_data_release.mep_wise\` ORDER BY mjd ASC LIMIT 500" || true

echo ""
echo "${GREEN}${BOLD}✓ Stage completed! The 'Custom quota exceeded' message above confirms Task 4 is complete.${RESET}"
echo "${ORANGE}${BOLD}You may now click 'Check my progress' on all objectives in the lab manual!${RESET}"
echo "${MAGENTA}${BOLD}==========================================================${RESET}"