Enrichments are in beta. Each one is a lookup file you keep in git and publish through the API. The Dimensions page reviews and publishes them. It does not edit the files.
cos_namespace, and writes one or more columns, such as owner_org. A file can hold thousands of keys. After you publish, Costory applies the files on the next billing update, including history, and the output columns are available in Explorer, dashboards, alerts, and reports.
Use an enrichment when the allocation is a table you want in git. Use a virtual dimension when someone should read and change the rules in the app.
The Enrichments section on Dimensions appears once the organization has a file. There is no Add enrichment action.
Example files
One YAML file is one enrichment. Thename in the file is the name you upload. priority sets the run order: a lower number runs first. targetColumns lists the columns the file writes.
mergekeeps a value the row already has, and fills the column only when it is empty.replaceoverwrites the column with the value from the file.
conditions is optional. When you set it, it is a CEL expression, and every field starts with input..
Upload the document as JSON. The body below is that JSON, shown as YAML so it stays readable in git. A GET of the file is a valid upload body.
Map billing column values to business columns
A static lookup maps values in one billing column to fixed values in one or more business columns. For example, map the Kubernetes namespacepayments to the responsible team and engineering manager.
- Set
keyFieldto the source billing column, herecos_namespace. - Declare the output columns in
targetColumnsand choosemergeorreplacefor each one. - Add an entry for each source value.
keyis the value to match;thenmaps target column names to the values to write.
cos_namespace = payments and empty target columns gets owner_team = Commerce and engineering_manager = Thomas. Each merge target keeps its existing value when populated. A namespace with no entry is left unchanged.
The source column stays on the row. In this lookup, owner_team: cos_namespace would write the literal text cos_namespace. To map a returned external metric field to a differently named target, use metric column mapping.
Static allocation
A static allocation splits one key across several values. You write the shares in the file. The weights of one entry sum to 1.111122223333 is reported as 60% Platform and 40% Data. The shares stay as written until you change the file and publish again.
Dynamic allocation
A splits one key’s cost per day using an external metric instead of weights in the file. Enrichments support every external metric provider and format accepted by the query API, including S3 Parquet, CloudWatch, Datadog, and Tsuga. Connect your source using Metrics Correlation, then setintegrationId to an active integration in your organization. Get its id from GET /integrations/external-metrics. Use GET /integrations/external-metrics/{id}/metrics to discover its metrics. Costory identifies the provider from the integration.
BigQuery table
For a BigQuery table, keep the existing table format:table is project.dataset.table, dateColumn is the day, and metricColumn is the measure. propagates lists the target columns the table fills. static stamps constants that the table does not supply.
This file splits the shared ML platform by CPU hours. Each row of the metric table carries cost_center and business_capability, and that day’s cost follows cpu_hours. Every share also gets component: cloud-landing-zone.
integrationId and table with your integration and your metric table. propagates can list a subset of targetColumns. A column you leave out of both propagates and static stays unset for that entry.
The metric supplies the columns selected by propagates. static is not read from the metric source. The constant is written on every allocated row, including days with no metric data and days when the metric fill fails. On those days, propagated columns stay unset.
Write static as a map of column name to string. A list of one-key maps is also accepted (- component: cloud-landing-zone). An empty static does nothing. Each key must be a targetColumns name, and must not also appear in propagates.
External metric configuration
For an external metric, put the provider’s metric settings insidethen.metric. Keep integrationId, propagates, and optional static alongside it. Use the same metric settings that work for that provider in POST /queries/run; the enrichment identifies the provider through integrationId.
Use the fields your provider requires. Enrichments use the query API’s provider and grouping capabilities, with the same provider-specific requirements and limits.
Map metric columns to target columns
Usethen.propagates to map fields returned by an external metric to the enrichment’s target columns. For example, a metric grouped by team can fill a billing output named owner_team.
Write the mapping as
{source: team, target: owner_team} under then.propagates, alongside metric. Keep the source name team in groupByFields and in the provider query. Only the enrichment output uses owner_team.
When names match, propagates: [team] is shorthand for propagates: [{source: team, target: team}]. In the object form, omitting target also defaults it to source. Declare every propagated target in targetColumns. A static key must not also be a propagated target.
Mapping copies the returned dimension value to each allocated share. The daily metric measure determines the share’s weight. On days with no metric data or when the metric fill fails, propagated columns stay unset. For external metrics, propagates: [] produces one whole share per day with positive metric data.
The examples below show same-name mappings for S3, BucketName to bucket_name for CloudWatch, and team to owner_team for Datadog.
- S3 Parquet
- CloudWatch
- Datadog
This example splits shared storage by service and region. Replace the placeholder integration ID and
metricName with values from your integration’s catalog.Transform group-by values with regex
Addregex to a then.propagates object to extract part of a metric’s group-by value before writing it to a target column. For example, extract payments from payments-prod so you can allocate costs by team without changing the metric source.
Regex transformations support external metrics only. A legacy BigQuery metric.table entry does not accept regex.
- Keep the original source field in
metric.groupByFieldsand in the provider query when required. - Declare the output columns in
targetColumns. - Set
source, optionaltarget, andregexon each propagated field. Omittargetwhen the output has the same name as the source.
payments-prod produces team = payments and environment = prod. Each target can use a different regex on the same source.
Pattern rules
Patterns use RE2 syntax, as used by BigQuery’s REGEXP_EXTRACT. They extract a value; there is no replacement template.
Use single-quoted YAML strings to preserve backslashes. For example, YAML
regex: '\d+' is JSON "regex": "\\d+". Both extract 123 from worker-123. Costory validates the pattern and capture count when you save the draft.
Other useful mappings:
Declare the corresponding target columns and request the source fields in your metric grouping. Plain strings and objects without
regex continue to copy the source value unchanged.
Allocation shares and unmatched values
Costory computes daily shares at the metric’s full original grouping, then transforms the propagated values. Rows with the same complete set of output values merge by summing their shares.
For a team-only allocation, keep just the team target and its propagation from the example above, plus the static component. A $100 daily cost splits as follows:
The final allocation is $80 to
payments and $20 to search. With both team and environment propagated, the three output combinations stay separate. For AVG, MIN, and MAX metrics, Costory sums the calculated shares without recomputing those aggregations over transformed groups.
An unmatched value keeps its cost with an unset target; the allocation weights still sum to 1. On days with no metric data or when the metric source fails, the existing fallback applies: one share with weight 1, unset propagated columns, and
static values kept.
Upload, test, and publish the changed file to apply a new pattern on the next billing update. Changing the regex updates the enrichment version and can reuse existing metric data. The row trace identifies the metric source and pattern without computing transformed allocation shares.
The same split, edited as rules in the app, is shared cost allocation. Use that when the rule belongs on the Dimensions page. Use this file when the split belongs in git with the rest of the enrichments.
Upload, test, and publish
In the app, Admin and Integration Admin can publish enrichment drafts from Dimensions. Integration Admin can publish enrichments even when label changes are restricted to Admins. See organization roles for the permissions comparison. API writes require an organization admin and a bearer token from the Costory app. See API overview for the token, and the Enrichments API for each call. To keep the files in git and publish them with Terraform, use Publish with Terraform.1
Upload each file as a draft
PUT /enrichments/{name} stores that file as a draft. The {name} in the path matches name in the file. Uploading the live file again clears its draft.DELETE /enrichments/{name} drafts the removal of a live file.2
Test one row
Open Dimensions. In Enrichments, click Test enrichments, fill the columns for one billed row, and click Test.Costory runs that row through the live files with the drafts applied, and shows each file’s hit or miss and the resulting values. A dynamic allocation identifies the metric source. The test does not compute the shares. Those appear after publish, on the next billing update.
3
Publish
Click Publish on the Dimensions page and include the enrichment drafts, or call
POST /enrichments/draft/publish.Publish stores every draft in one step and starts a billing update. A file set that does not fit together is refused, and the live files stay as they are.Publish with Terraform
Keep one YAML file per enrichment in anenrichments/ directory next to your Terraform configuration. The Costory provider (0.3.1 or later) reads each file with costory_enrichment and stores it as a draft. costory_enrichments_publish then compiles that set and makes it live in the same apply.
The file basename must match the name field inside the file. namespace.yaml requires name: namespace. Both .yml and .yaml are included.
terraform.tfvars or as TF_VAR_costory_api_token, then run terraform init and terraform apply.
terraform apply writes the drafts and publishes them. Costory compiles the live set with every draft applied and starts a billing update. A set that fails to compile is refused, and the live files stay as they are.
Removing a file and applying again drops that enrichment in the same publish. Destroying an enrichment resource drafts its removal. The live enrichment stays until publish runs.
Test a row on Dimensions before you rely on the result. In Enrichments, click Test enrichments, fill the columns for one billed row, and click Test. The test runs the live files with the drafts from the last apply.
Next steps
Dimensions
Merge tags and write rules in the app
Shared Cost Allocation
Split a shared cost from a usage metric, as a rule
API overview
Authenticate an admin token for uploads
Enrichments API
Upload a draft and publish the set
Explorer
Group costs by the columns an enrichment writes
