Connect a source

Connect Databricks

Create a Databricks service principal that can read the system billing tables on one SQL warehouse, enter its workspace URL, warehouse ID, client ID and OAuth secret, and Costfluent imports your account's daily usage at list price per workspace, SKU and compute resource.

Costfluent reads your Databricks spend from the account's system billing tables, as a service principal you create for it, through one SQL warehouse of one workspace. One connection is one Databricks account, and the usage of every AWS and Google Cloud workspace in it.

How Costfluent connects

Costfluent stores the service principal's OAuth secret encrypted and never sends it anywhere but the workspace's own token endpoint: it exchanges the secret there for a token with the sql scope, valid for an hour, and runs read-only SQL statements with that token through Databricks' Statement Execution API on the warehouse you name. The statements read system.billing.usage, priced with system.billing.list_prices, and never the identity columns that name the users who ran or own the usage. The account ID is the connection's identity, so you do not enter it.

Every statement runs on your warehouse, and the warehouse uses DBUs while it runs. Use a serverless warehouse of size 2X-Small with a short auto stop, so a sync costs a few minutes of the smallest warehouse (What syncing costs).

Prerequisites

  1. The Owner or Integration owner organization role in Costfluent.
  2. A Databricks account on AWS or Google Cloud with a workspace enabled for Unity Catalog. Azure Databricks is not supported: Microsoft bills its usage on the Azure invoice, which an Azure connection already reads.
  3. An admin who can create service principals and SQL warehouses in that workspace, and a user who holds both the account admin and the metastore admin roles to grant read on the system billing tables.
  4. A workspace that admits requests from any address. Costfluent does not publish the addresses it calls from, so a workspace whose IP access list admits only your own addresses refuses it.

Prepare Databricks

Create the service principal

  1. In the workspace, click your username, select Settings, open Identity and access, and select Manage next to Service principals. Add a service principal named for Costfluent. Created there, it is assigned to the workspace.
  2. Open the service principal and give it the "Databricks SQL access" entitlement, and no other.
  3. Open its Secrets tab, select Generate secret, set a lifetime of 365 days and the sql scope, and generate it. Copy the secret and the client ID: Databricks shows the secret only once. The client ID is the service principal's application ID. Note the date to replace the secret before it expires.

Create a SQL warehouse

Create a SQL warehouse for Costfluent alone, or use one you already have. A serverless warehouse of size 2X-Small is enough, and the shortest auto stop keeps it from idling: 5 minutes in the workspace, or 1 minute when the warehouse is created through Databricks' SQL warehouses API. Then open the warehouse's Permissions and give the service principal "Can use". Copy the warehouse ID, the last part of the HTTP path in the warehouse's Connection details, such as 1234567890abcdef.

Grant read on the billing tables

As a user who holds the account admin and metastore admin roles, run these statements in a SQL editor of the workspace, with the service principal's application ID in place of <APPLICATION_ID>:

Code
GRANT USE CATALOG ON CATALOG system TO `<APPLICATION_ID>`; GRANT USE SCHEMA ON SCHEMA system.billing TO `<APPLICATION_ID>`; GRANT SELECT ON SCHEMA system.billing TO `<APPLICATION_ID>`;

These grants let the service principal read the billing tables and nothing more of your data, and nothing in them writes. Give it no other privilege.

What syncing costs

This is an estimate from Databricks' published SQL pricing, not a measurement. A serverless warehouse of size 2X-Small uses 4 DBUs an hour while it runs, and keeps running until it has been idle for its auto stop. Each sync runs one short statement per day it reads, which is the running month and, until the 15th, the month before. If those statements take a few minutes and the warehouse then idles for a 5-minute auto stop, a sync keeps it running about 10 minutes: about 0.7 DBU, or about 20 DBUs a month at the daily default. Syncing more often costs more in proportion.

Your price per DBU depends on your cloud, region and tier. Databricks' pricing page lists it, and this statement returns the list price of the SQL serverless SKUs your account can use:

Code
SELECT sku_name, currency_code, pricing.effective_list.default AS price_per_dbu FROM system.billing.list_prices WHERE sku_name LIKE '%SERVERLESS%' AND sku_name LIKE '%SQL%' AND price_end_time IS NULL;

Once connected, the warehouse's own usage arrives in Costfluent with the rest: filter Resource ID by the warehouse ID to see what syncing really costs.

Connect

  1. Open Settings, then Integrations, select Databricks, and open the Connect tab.
  2. Select "Add service principal", keep the suggested Display name or enter your own, and enter the workspace's address into Workspace URL, the warehouse ID into Warehouse ID, the client ID into Client ID and the secret into OAuth secret. The bare host works as the URL too, capitals are sent in lowercase, and spaces around each value are removed.
  3. Select "Test connection" to see each check, or "Connect" to save.

The workspace URL is an AWS workspace's https://<workspace>.cloud.databricks.com or a Google Cloud workspace's https://<workspace ID>.<digit>.gcp.databricks.com, with nothing after the host. An Azure Databricks address is refused, and so are AWS GovCloud workspaces, Google Cloud's regional addresses and the account console.

Before storing anything, Costfluent exchanges the secret for a token, reads the account ID from the price list and runs its usage statement for yesterday, so a connection that saves can read your usage. A second connection of the same account is refused. If Databricks does not answer during that check, the connection is saved anyway and checked again automatically.

Data and freshness

Connecting imports as far back as your plan's backfill reaches, and at most six months (Manage connections). Cost arrives by UTC day, in the currency of Databricks' price list.

Databricks typically writes a day's usage records within 12 hours of the usage, so a day arrives with a sync on the next day. Each sync reads the running month again, and the previous month until the 15th of the month after it.

Every amount is at list price: each day's usage times the SKU's list price, or its promotional price while Databricks runs one, as system.billing.list_prices states it, and the billed and effective cost are that same amount. Your invoice can be lower, for a commitment or a negotiated discount, which the system tables do not expose.

Databricks bought through the AWS or Google Cloud marketplace is billed on that cloud's invoice, and nothing in the billing tables tells it apart. If you also connect that cloud, its usage would be counted twice, so connect only one of the two.

Databricks corrects usage by adding records dated on the original day. A correction written after the 15th of the month following that day is not collected, because no sync reads the day again.

A SKU that system.billing.list_prices does not price yet, usually one Databricks has just introduced, is held back rather than stored at zero. A later sync stores its usage once the price appears, as long as that sync still reads the day.

Classic compute also runs instances and storage in your own AWS or Google Cloud account. Those charges are on that cloud's bill, which its own connection reads, and are not part of the Databricks usage.

Reporting dimensions

  • Billing account is the Databricks account and Sub-account the workspace, each by its ID.
  • Service is the product the usage came from, as Databricks names it, such as ALL_PURPOSE, JOBS or SQL. Service category is Storage for stored data, the usage type STORAGE_SPACE, and Analytics for everything else.
  • SKU is Databricks' SKU, such as STANDARD_ALL_PURPOSE_COMPUTE.
  • Resource ID is the ID of the cluster, SQL warehouse, job, pipeline or serving endpoint the usage ran on; storage has none. Databricks names no resource, so Resource stays empty.
  • The quantity is in the usage's unit, such as DBUs. The usage type, such as COMPUTE_TIME or STORAGE_SPACE, follows the SKU in Charge description, as in STANDARD_ALL_PURPOSE_COMPUTE (COMPUTE_TIME), and is the x_UsageType column of a bucket export.
  • Charge category is Usage.
  • The usage's custom tags are kept as tags, except the tag whose key is exactly Creator, which Databricks sets to the email address of the user who created the compute. A tag of your own named creator or x_Creator is kept.

Update or disconnect

After connecting

The Manage tab lists the connection by its display name, with its account ID under Account. Open the gear icon beside it to see whether the usage is still readable, which workspaces the connection feeds, and which months have been imported. Run checks runs the checks again on request.

Rotating or removing access

A service principal holds up to five OAuth secrets, so a secret is rotated without a gap. Generate a new secret with the sql scope as above, select Update credentials on the connection page and enter the same workspace URL, warehouse ID and client ID with the new secret. Once the checks pass, delete the old secret in Databricks. Another account's service principal is refused.

Databricks deletes a secret that is not used for 90 days. A connection that syncs only on request and is not synced for that long loses its secret, and needs a new one.

To retire the connection, remove it in Costfluent, then delete the service principal in Databricks, and the warehouse if you created it for Costfluent alone. Removing the connection erases the cost it imported (Remove a connection).

Troubleshooting

  • A Databricks workspace URL, SQL warehouse ID, OAuth client ID and client secret are required. One of the four fields is empty. Fill in all four.
  • This is an Azure Databricks workspace. Microsoft bills its usage on the Azure invoice, which an Azure connection already reads, so connect the Azure subscription instead. The workspace URL ends in azuredatabricks.net or databricks.azure.cn. Its usage is already in the Azure connection's cost.
  • A Databricks workspace URL is written https://<workspace>.cloud.databricks.com on AWS, or https://<workspace id>.<digit>.gcp.databricks.com on Google Cloud. GovCloud, regional and account console addresses are not supported. The field holds another address, or a path or query after the host, such as /?o= and the workspace ID. Copy the address up to the host.
  • A Databricks SQL warehouse ID is the hexadecimal ID in the warehouse's connection details, such as 1234567890abcdef. The field holds the whole HTTP path or the warehouse's name. Copy only its last part.
  • No Databricks workspace answers at ... Check the workspace URL. The message names the host. No workspace exists there; check the URL for a typo.
  • Databricks refused this OAuth client ID and secret. Check the service principal's client ID, and that the secret is current and was created for it. The client ID is wrong, or the secret has expired, was deleted, or belongs to another service principal. Generate a new secret and select Update credentials.
  • Databricks issued a token for this service principal but refused it for SQL. Create the OAuth secret with the sql scope, or with no scope, and enter it again. The secret was created with other scopes, which cannot be changed afterwards. Generate a new secret with the sql scope.
  • The service principal may not use SQL warehouse ... Give it CAN USE on the warehouse, and the Databricks SQL access entitlement. The message names the warehouse and Databricks' error code. Give the service principal "Can use" on that warehouse and the "Databricks SQL access" entitlement, then select Run checks.
  • The service principal cannot read the system billing tables. Grant it USE CATALOG on the system catalog, and USE SCHEMA and SELECT on system.billing. Run the grants above, then select Run checks.
  • Databricks refused the billing read on SQL warehouse ... Databricks refused the statement for a reason its codes, which the message names, do not tell apart. Check that the warehouse exists, that the service principal has "Can use" on it, and that the grants above ran.
  • Databricks did not name the account of this workspace, so the connection cannot be identified. The price list returned no account ID. Check that the workspace is enabled for Unity Catalog.
  • Databricks answered ... in a shape Costfluent cannot read (...). Test the connection again later; if it persists, contact Costfluent. Nothing you entered is at fault. If it persists, tell us through the contact form, naming the message.
  • The supplied Databricks service principal belongs to another account than the one this connection was validated against. Shown when updating credentials. Connect that account as a new connection.