dwhat

For warehouse administrators

Reviewing a read-only access request for dwhat

Someone on your team would like to audit your warehouse's compute cost with dwhat, and needs you to create the account it reads with. This page says what that account can see, what dwhat keeps and for how long, how to take the access back, and what it costs to run — so you can decide before you run anything.

What the audit is for

dwhat reads the warehouse's query history and works out where compute spend went: by day, by user, by dbt model and by dashboard, with the 20 most expensive queries and a fix hint where the warehouse's own statistics support one. After the first read it keeps reading every few hours, emails the person who connected it when a day costs much more than usual, and builds a monthly report for finance.

Exactly what it reads

BigQuery

INFORMATION_SCHEMA.JOBS_BY_PROJECT, for one project and one region: finished query jobs that billed bytes or slot time. Script parent jobs and free cache hits are left out.

ColumnWhy
job_id, creation_timeto count each job once and put it on a UTC day
user_emailthe user or service account that ran it — cost by user
statement_typeSELECT, MERGE, CREATE TABLE AS…
query (first 20,000 characters)to group identical queries, find dbt and BI tool comments, and base fix hints on
labelsdbt and Looker Studio job labels — cost by model and dashboard
total_bytes_billed, total_bytes_processed, total_slot_msthe cost
elapsed time, cache_hitshown with the most expensive queries

Snowflake

SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY joined to QUERY_HISTORY, for the whole account.

ColumnWhy
query_id, start_timeto count each query once and put it on a UTC day
user_namethe Snowflake user that ran it — cost by user
warehouse_name, query_typewhere it ran, and what kind of statement it was
query_text (first 20,000 characters)to group identical queries, find dbt and BI tool comments, and base fix hints on
query_tagdbt and dashboard tags — cost by model and dashboard
credits_attributed_computethe cost
bytes_scanned, total_elapsed_time, bytes_spilled_to_remote_storage, partitions_scanned, partitions_totalthe evidence a fix hint needs

And from WAREHOUSE_METERING_HISTORY, each warehouse's compute credits per UTC day, so idle time can be shown next to what queries used.

These are the only queries dwhat runs. The roles below allow more than that: BigQuery Resource Viewer lets the account see the metadata of the project's other BigQuery resources, and the SNOWFLAKE database roles let the user read more of ACCOUNT_USAGE than these views. Neither grants a single row of your tables, or any change.

What that metadata can contain

Where the credentials are kept

How long the history is kept

Taking the access back

Remove the account on your side and dwhat can read nothing more; whoever connected it can also remove the connection in dwhat, which deletes what was read. With the default names:

Snowflake

USE ROLE ACCOUNTADMIN;

DROP USER IF EXISTS DWHAT_READER;
DROP ROLE IF EXISTS DWHAT_READER;
DROP WAREHOUSE IF EXISTS DWHAT_XS;

BigQuery

PROJECT=your-project-id

gcloud iam service-accounts delete dwhat-reader@$PROJECT.iam.gserviceaccount.com \
  --project=$PROJECT

What it costs to run, and its limits

The Snowflake setup

Run as ACCOUNTADMIN, or a role that can create roles, users and warehouses. It creates a role that can read account usage and nothing else, an X-Small warehouse for it that suspends after a minute idle, and a service user with no password. The key pair is generated by dwhat for each connection: the person who asked you will send this script with their connection's public key filled in. The public key is safe to forward; the private half never leaves dwhat.

USE ROLE ACCOUNTADMIN;

-- A role that can read account usage, and nothing else.
CREATE ROLE IF NOT EXISTS DWHAT_READER;
GRANT DATABASE ROLE SNOWFLAKE.USAGE_VIEWER TO ROLE DWHAT_READER;
GRANT DATABASE ROLE SNOWFLAKE.GOVERNANCE_VIEWER TO ROLE DWHAT_READER;

-- Its own X-Small warehouse, suspended after a minute idle,
-- so reading the history costs a few minutes of X-Small a day.
CREATE WAREHOUSE IF NOT EXISTS DWHAT_XS
  WAREHOUSE_SIZE = XSMALL AUTO_SUSPEND = 60 AUTO_RESUME = TRUE INITIALLY_SUSPENDED = TRUE;
GRANT USAGE ON WAREHOUSE DWHAT_XS TO ROLE DWHAT_READER;

-- A service user with no password: it signs in with a key pair only.
CREATE USER IF NOT EXISTS DWHAT_READER
  TYPE = SERVICE
  DEFAULT_ROLE = DWHAT_READER
  DEFAULT_WAREHOUSE = DWHAT_XS
  RSA_PUBLIC_KEY = '<the public key shown on your connection page>';
GRANT ROLE DWHAT_READER TO USER DWHAT_READER;

The BigQuery setup

A service account with two roles on the project — BigQuery Resource Viewer to see everybody's jobs, BigQuery Job User to run the query that reads them — and a JSON key for it. With the gcloud CLI:

PROJECT=your-project-id
SA=dwhat-reader@$PROJECT.iam.gserviceaccount.com

gcloud iam service-accounts create dwhat-reader \
  --project=$PROJECT --display-name="dwhat (read-only)"

# Sees everybody's job metadata in the project. No table data.
gcloud projects add-iam-policy-binding $PROJECT \
  --member="serviceAccount:$SA" --role=roles/bigquery.resourceViewer

# Runs the one query that reads that metadata.
gcloud projects add-iam-policy-binding $PROJECT \
  --member="serviceAccount:$SA" --role=roles/bigquery.jobUser

gcloud iam service-accounts keys create dwhat-key.json --iam-account=$SA

The JSON key is a credential. Hand it over through your team's approved secret-sharing process, never by email, chat or ticket. It is entered only in dwhat's signed-in connection form, by the person adding the connection.

Nothing to sign up for

You do not need a dwhat account to review or run any of this. The person who asked you adds the connection and presses "Test connection" once you tell them the setup has run. The same scripts, and the CSV route for teams that will not grant access at all, are on the free audit page.

Read the free audit pageSee a sample audit