PageSourceSearch

https://app.leadcognition.io/assets/bigquery-budget-quota-setup-DKCgtdDO.js

js leadcognition.io collected 2026-10-08 23:16:00 UTC 12,590 bytes, 353 lines download raw bytes

1const e=`# Research: BigQuery Budget Alerts & Custom Quotas Setup
2
3> **Date**: 2026-02-16
4> **Status**: complete
5> **Project**: leadcognition (ID: 591907953825)
6> **Billing Account**: 019FBE-BFD415-379CFC
7
8## Question
9
10How to programmatically set up:
111. **Budget alert**: $1/month budget on BigQuery with email notifications at 50%, 90%, 100% thresholds
122. **Custom per-user daily query quota**: Limit BigQuery query bytes to ~50 GB/day per user (instead of default 200 TiB/day)
13
14## Findings
15
16### 1. Budget Alerts via \`gcloud billing budgets create\`
17
18**Command Structure:**
19
20\`\`\`bash
21gcloud billing budgets create \\
22  --billing-account=019FBE-BFD415-379CFC \\
23  --display-name="BigQuery Monthly Budget - $1" \\
24  --budget-amount=1.00USD \\
25  --filter-services=services/24E6-581D-38E5-BEE2-8A60-5171-B814 \\
26  --threshold-rule=percent=0.50 \\
27  --threshold-rule=percent=0.90 \\
28  --threshold-rule=percent=1.00
29\`\`\`
30
31**Key Parameters:**
32- \`--billing-account\`: Your GCP billing account ID (required)
33- \`--display-name\`: Human-readable budget name (max 60 chars)
34- \`--budget-amount\`: Amount with currency (e.g., \`1.00USD\`, \`100.75EUR\`)
35- \`--filter-services\`: Filter to specific service(s) like BigQuery
36  - Format: \`services/{service_id}\`
37  - BigQuery service ID: \`24E6-581D-38E5-BEE2-8A60-5171-B814\` (standard across GCP)
38  - If omitted, budget applies to all services
39- \`--threshold-rule\`: Can be specified multiple times for different thresholds
40  - Format: \`percent=0.50\` (triggers at 50% of budget)
41  - Optional \`basis\` parameter: \`basis=forecasted-spend\` (default is actual spend)
42- \`--calendar-period\`: Time period (default: \`MONTH\`). Options: \`MONTH\`, \`QUARTER\`, \`YEAR\`
43- \`--disable-default-iam-recipients\`: Prevents emails to Billing Account Admins (not recommended)
44
45**Email Notifications:**
46- By default, emails go to users with "Billing Account Administrator" or "Billing Account User" IAM roles
47- User email ([email protected]) should already receive alerts if assigned one of these roles
48- For custom recipients, use \`--notifications-rule-monitoring-notification-channels\` (requires setting up Cloud Monitoring channels first)
49
50**Verification:**
51
52\`\`\`bash
53# List all budgets
54gcloud billing budgets list --billing-account=019FBE-BFD415-379CFC
55
56# Describe specific budget
57gcloud billing budgets describe BUDGET_ID --billing-account=019FBE-BFD415-379CFC
58\`\`\`
59
60**Important Notes:**
61- Budget alerts are **informational only** — they don't stop spending
62- Alerts trigger when actual OR forecasted spend exceeds threshold
63- Daily quotas are reset at midnight Pacific Time
64- Budget periods reset based on calendar period (monthly = 1st of each month)
65
66---
67
68### 2. Custom Per-User Query Quota via \`gcloud alpha services quota update\`
69
70**Command for ~50 GB/day per user:**
71
72\`\`\`bash
73gcloud alpha services quota update \\
74  --service=bigquery.googleapis.com \\
75  --consumer=projects/591907953825 \\
76  --metric=bigquery.googleapis.com/quota/query/usage \\
77  --unit=1/d/{project}/{user} \\
78  --value=51200 \\
79  --force
80\`\`\`
81
82**Key Parameters:**
83- \`--service\`: Always \`bigquery.googleapis.com\`
84- \`--consumer\`: Project in format \`projects/{PROJECT_ID}\` (can use project number OR project ID)
85- \`--metric\`: \`bigquery.googleapis.com/quota/query/usage\` for query bytes scanned
86- \`--unit\`: 
87  - \`1/d/{project}\` = project-level daily quota (all users combined)
88  - \`1/d/{project}/{user}\` = per-user daily quota (each user/service account separately)
89- \`--value\`: Quota in **megabytes (MB)**
90  - 50 GB = 51,200 MB
91  - 10 TiB = 10,485,760 MB (default example from docs)
92  - 200 TiB (current default) = 209,715,200 MB
93- \`--force\`: Skip confirmation prompt (optional but recommended for automation)
94
95**Value Calculations:**
96
97| Target Quota | Value (MB) | Command Example |
98|--------------|-----------|-----------------|
99| 50 GB/day | 51200 | \`--value=51200\` |
100| 100 GB/day | 102400 | \`--value=102400\` |
101| 1 TB/day | 1048576 | \`--value=1048576\` |
102| 10 TB/day | 10485760 | \`--value=10485760\` |
103
104**Quota Types:**
105
1061. **QueryUsagePerUserPerDay** (per-user quota):
107   - Applied separately to each user and service account
108   - Unit: \`1/d/{project}/{user}\`
109   - Recommended for cost control by user
110
1112. **QueryUsagePerDay** (project-level quota):
112   - Aggregate limit for all users in project
113   - Unit: \`1/d/{project}\`
114   - Note: Total project usage can never exceed this, regardless of per-user limits
115
116**Verification:**
117
118\`\`\`bash
119# List current quotas
120gcloud alpha services quota list \\
121  --service=bigquery.googleapis.com \\
122  --consumer=projects/591907953825 \\
123  --filter="metric.name:query/usage"
124
125# Get specific quota details
126gcloud alpha services quota describe \\
127  --service=bigquery.googleapis.com \\
128  --consumer=projects/591907953825 \\
129  --metric=bigquery.googleapis.com/quota/query/usage \\
130  --unit=1/d/{project}/{user}
131\`\`\`
132
133**Important Notes:**
134- Quotas are **proactive** — queries are blocked before running if they would exceed quota
135- Daily quotas reset at midnight Pacific Time
136- If you set both per-user AND project-level quotas, the more restrictive one applies
137- User queries that would exceed quota return error: \`Quota exceeded: Your project exceeded quota for query bytes per day per user\`
138- The \`gcloud alpha\` command is in preview and may change without notice
139
140---
141
142### 3. Alternative: Service Usage API (curl/REST)
143
144For automation via API instead of \`gcloud\`:
145
146**Budget Creation API:**
147- Endpoint: \`https://billingbudgets.googleapis.com/v1/billingAccounts/{BILLING_ACCOUNT_ID}/budgets\`
148- Method: POST
149- Auth: Bearer token from \`gcloud auth print-access-token\`
150
151**Quota Update API:**
152- Endpoint: \`https://serviceusage.googleapis.com/v1beta1/projects/591907953825/services/bigquery.googleapis.com/consumerQuotaMetrics\`
153- Method: PATCH
154- Auth: Bearer token
155
156Example curl for quota (from research):
157
158\`\`\`bash
159curl -X PATCH \\
160  -H "Authorization: Bearer $(gcloud auth print-access-token)" \\
161  -H "Content-Type: application/json" \\
162  -d '{
163    "overrideValue": "51200",
164    "dimensions": {
165      "quota_id": "QueryUsagePerUserPerDay"
166    }
167  }' \\
168  "https://serviceusage.googleapis.com/v1beta1/projects/591907953825/services/bigquery.googleapis.com/consumerQuotaMetrics/bigquery.googleapis.com%2Fquota%2Fquery%2Fusage/limits/1%2Fd%2F%7Bproject%7D%2F%7Buser%7D"
169\`\`\`
170
171---
172
173### 4. Terraform Alternative
174
175For infrastructure-as-code approach:
176
177**Budget:**
178
179\`\`\`hcl
180resource "google_billing_budget" "bigquery_budget" {
181  billing_account = "019FBE-BFD415-379CFC"
182  display_name    = "BigQuery Monthly Budget - $1"
183
184  amount {
185    specified_amount {
186      currency_code = "USD"
187      units         = "1"
188    }
189  }
190
191  budget_filter {
192    services = ["services/24E6-581D-38E5-BEE2-8A60-5171-B814"]
193  }
194
195  threshold_rules {
196    threshold_percent = 0.5
197  }
198  threshold_rules {
199    threshold_percent = 0.9
200  }
201  threshold_rules {
202    threshold_percent = 1.0
203  }
204
205  all_updates_rule {
206    disable_default_iam_recipients = false
207  }
208}
209\`\`\`
210
211**Quota:**
212
213\`\`\`hcl
214resource "google_service_usage_consumer_quota_override" "bigquery_user_quota" {
215  project        = "leadcognition"
216  service        = "bigquery.googleapis.com"
217  metric         = "bigquery.googleapis.com%2Fquota%2Fquery%2Fusage"
218  limit          = "%2F1%2Fd%2F%7Bproject%7D%2F%7Buser%7D"
219  override_value = "51200"
220  force          = true
221}
222\`\`\`
223
224---
225
226## Recommendations
227
228### Immediate Actions
229
2301. **Set up budget alert** (informational safety net):
231   \`\`\`bash
232   gcloud billing budgets create \\
233     --billing-account=019FBE-BFD415-379CFC \\
234     --display-name="BigQuery Monthly Budget - $1" \\
235     --budget-amount=1.00USD \\
236     --filter-services=services/24E6-581D-38E5-BEE2-8A60-5171-B814 \\
237     --threshold-rule=percent=0.50 \\
238     --threshold-rule=percent=0.90 \\
239     --threshold-rule=percent=1.00
240   \`\`\`
241
2422. **Set per-user query quota** (hard enforcement):
243   \`\`\`bash
244   gcloud alpha services quota update \\
245     --service=bigquery.googleapis.com \\
246     --consumer=projects/591907953825 \\
247     --metric=bigquery.googleapis.com/quota/query/usage \\
248     --unit=1/d/{project}/{user} \\
249     --value=51200 \\
250     --force
251   \`\`\`
252
2533. **Verify IAM roles** for [email protected]:
254   \`\`\`bash
255   gcloud billing accounts get-iam-policy 019FBE-BFD415-379CFC \\
256     --filter="bindings.members:[email protected]"
257   \`\`\`
258   - Ensure user has \`roles/billing.admin\` or \`roles/billing.user\` to receive budget alerts
259
260### Quota Strategy
261
262**Current State:**
263- Default: 200 TiB/day per user (209,715,200 MB)
264- Free tier: 1 TB/month across all queries
265- Actual usage: ~14 GB for 3-month backfill (well under free tier)
266
267**Recommended Quota: 50 GB/day per user**
268- Reasoning:
269  - 50 GB/day × 30 days = 1,500 GB/month = 1.5 TB/month
270  - Covers current usage (14 GB for 3 months = ~5 GB/month) with 300x headroom
271  - Still within free tier if used daily
272  - Prevents accidental runaway queries (e.g., full table scan on \`githubarchive.year.*\` tables)
273  
274**Adjust if needed:**
275- For development/testing: Start with 10 GB/day (\`--value=10240\`)
276- For production with multiple users: 100 GB/day (\`--value=102400\`)
277- Monitor actual usage via BigQuery INFORMATION_SCHEMA.JOBS
278
279### Budget vs Quota Trade-offs
280
281| Method | Enforcement | Visibility | Use Case |
282|--------|------------|-----------|----------|
283| **Budget Alert** | None (alerts only) | Email at thresholds | Early warning system |
284| **Custom Quota** | Hard limit (blocks queries) | Error on exceed | Prevent runaway costs |
285
286**Best practice: Use both**
287- Budget alert at $1/month = early warning
288- Per-user quota at 50 GB/day = hard safety net
289- Together: defense-in-depth cost control
290
291---
292
293## Next Steps
294
2951. **Execute both commands** (copy-paste ready below)
2962. **Test quota enforcement** by running a dry-run query that exceeds 50 GB
2973. **Monitor for alerts** — check email for budget notifications
2984. **Document in MEMORY.md** — add quota value and budget ID for future reference
2995. **Add to deployment checklist** — ensure quota is set for any new GCP projects
300
301---
302
303## Copy-Paste Commands
304
305\`\`\`bash
306# 1. Create budget alert ($1/month, 50%/90%/100% thresholds, BigQuery only)
307gcloud billing budgets create \\
308  --billing-account=019FBE-BFD415-379CFC \\
309  --display-name="BigQuery Monthly Budget - $1" \\
310  --budget-amount=1.00USD \\
311  --filter-services=services/24E6-581D-38E5-BEE2-8A60-5171-B814 \\
312  --threshold-rule=percent=0.50 \\
313  --threshold-rule=percent=0.90 \\
314  --threshold-rule=percent=1.00
315
316# 2. Set per-user daily query quota (50 GB/day)
317gcloud alpha services quota update \\
318  --service=bigquery.googleapis.com \\
319  --consumer=projects/591907953825 \\
320  --metric=bigquery.googleapis.com/quota/query/usage \\
321  --unit=1/d/{project}/{user} \\
322  --value=51200 \\
323  --force
324
325# 3. Verify budget was created
326gcloud billing budgets list --billing-account=019FBE-BFD415-379CFC
327
328# 4. Verify quota was updated
329gcloud alpha services quota list \\
330  --service=bigquery.googleapis.com \\
331  --consumer=projects/591907953825 \\
332  --filter="metric.name:query/usage"
333
334# 5. Check IAM roles for budget notifications
335gcloud billing accounts get-iam-policy 019FBE-BFD415-379CFC \\
336  --filter="bindings.members:[email protected]"
337\`\`\`
338
339---
340
341## Sources
342
343- [Create, edit, or delete budgets and budget alerts | Cloud Billing](https://docs.cloud.google.com/billing/docs/how-to/budgets)
344- [gcloud billing budgets create | Google Cloud SDK](https://cloud.google.com/sdk/gcloud/reference/billing/budgets/create)
345- [Create custom query quotas | BigQuery](https://docs.cloud.google.com/bigquery/docs/custom-quotas)
346- [Quotas and limits | BigQuery](https://docs.cloud.google.com/bigquery/quotas)
347- [Use gcloud to set up Google Cloud BigQuery quotas | GitHub Gist](https://gist.github.com/derrickqin/2f85e0bcd3b32cf6b397fa2109b3cd89)
348- [How to set limits on BigQuery costs with custom quota | Medium](https://medium.com/google-cloud/how-to-set-hard-limits-on-bigquery-costs-with-custom-quota-f8c26df0b2b8)
349- [Manage BigQuery costs with custom quotas | Google Cloud Blog](https://cloud.google.com/blog/products/data-analytics/manage-bigquery-costs-with-custom-quotas)
350- [View and manage quotas | Cloud Quotas](https://docs.cloud.google.com/docs/quotas/view-manage)
351- [BigQuery: Set up limits and custom quotas through API | Medium](https://medium.com/google-cloud/bigquery-set-up-limits-and-custom-quotas-through-api-629f77438b7e)
352`;export{e as default};
353//# sourceMappingURL=bigquery-budget-quota-setup-DKCgtdDO.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.