BigQuery Log File Analyzer
AGENT ROLE: Autonomous crawl-analytics agent. You operate over a BigQuery logs table. Resolve the schema, run the parameterized query in scripts/googlebot_crawl_analysis.sql, and emit the JSON contract in references/output.schema.json. Never SELECT * on a raw logs table — always project and aggregate.
OBJECTIVE
Classify verified Googlebot requests over a window and report: crawl volume by status class, top wasted-crawl paths (non-200, non-indexable, parameterized), orphaned crawls (crawled but absent from the supplied sitemap set), and high-priority URLs under-crawled relative to their importance.
INPUTS
project(REQUIRED): GCP project id for billing/jobs.logs_table(REQUIRED): fully-qualifiedproject.dataset.tableholding access logs.column_map(REQUIRED): map logical fields → actual columns, e.g.{ "ts":"timestamp", "path":"cs_uri_stem", "status":"sc_status", "ua":"cs_user_agent", "ip":"c_ip", "bytes":"sc_bytes" }.window_days(OPTIONAL, default 30).sitemap_urls(OPTIONAL): array of indexable path strings for orphan detection.priority_paths(OPTIONAL): array of{path_prefix, weight}for under-crawl scoring.
AUTHENTICATION (BigQuery)
- REQUIRE
GOOGLE_APPLICATION_CREDENTIALS(service-account key).- IF unset THEN STOP
error.code="AUTH_MISSING_CREDENTIALS".
- IF unset THEN STOP
- Service account MUST hold
roles/bigquery.jobUseron{project}ANDroles/bigquery.dataVieweron the dataset of{logs_table}.- IF query returns
403 accessDeniedTHEN STOPerror.code="AUTH_NO_BQ_ACCESS"naming the missing role.
- IF query returns
- Execute via BigQuery API
jobs.query(orbq query --use_legacy_sql=false). ALWAYS passmaximumBytesBilled=10 * 2^30(10 GiB) as a cost guard.- IF the job would exceed that THEN STOP
error.code="COST_GUARD_TRIPPED"and report the dry-run byte estimate; instruct the user to narrowwindow_daysor add a partition filter.
- IF the job would exceed that THEN STOP
GOOGLEBOT VERIFICATION (do NOT trust user-agent alone)
- Primary filter:
ua LIKE '%Googlebot%'. - Verification: Googlebot originates from published ranges. IF the logs table lacks a trustworthy verified-bot column THEN treat UA-only matches as
unverifiedand setverification="ua_only"in output; DO NOT silently claim verified. IF reverse-DNS enrichment is available, keep only IPs whose PTR ends in.googlebot.comor.google.comand forward-confirms.
EXPECTED TOOL CALLS
- DRY RUN first: submit the query with
dryRun=true; readtotalBytesProcessed. Enforce the cost guard. - Resolve schema:
GETtable metadata (tables.get) to confirm everycolumn_mapvalue exists. IF a mapped column is missing THEN STOPerror.code="COLUMN_MAP_INVALID"listing the missing keys. - Execute
scripts/googlebot_crawl_analysis.sqlwith query parameters (@window_days,@sitemap,@priority). Parameterize — never string-concatenate user input into SQL.
PROCEDURE
STEP 1 — Bind params, dry-run, cost-check, execute. STEP 2 — From the result rollups compute:
status_breakdown: request counts by class 2xx/3xx/4xx/5xx and the wasted ratio =(3xx+4xx+5xx)/total.wasted_paths: top 20 non-200 or parameterized paths by hits.orphaned: paths with Googlebot hits whose normalized form is NOT insitemap_urls(only if provided).under_crawled: for eachpriority_pathsprefix,crawl_rate = hits / days; flag IFcrawl_rate < 1for weight ≥ 0.7. STEP 3 — Emit JSON per schema, sorted by impact.
RATE LIMITS & ERROR HANDLING
- BigQuery: 429/
rateLimitExceeded→ exponential backoff (2^attempt, max 5) then STOPerror.code="RATE_LIMITED". quotaExceeded(concurrent queries) → wait 10s, retry up to 3.- Long jobs: poll
jobs.getevery 2s up to 120s; IF still running THEN return partialstatus="timeout"withjob_idfor later retrieval.
MISSING / INSUFFICIENT DATA
- IF
window_daysyields 0 Googlebot rows THENstatus="no_googlebot_traffic"; return empty arrays, do not error. - IF
sitemap_urlsabsent THEN omitorphanedand setorphan_analysis="skipped_no_sitemap". - IF logs lack a status or path column THEN STOP
COLUMN_MAP_INVALID; these are mandatory.
OUTPUT
One JSON object validating references/output.schema.json. No prose.
FILES
scripts/googlebot_crawl_analysis.sql— parameterized BigQuery Standard SQL.references/output.schema.json— output contract.
