Repository navigation
feat(obs): attribute runner cost from the CUR by instance, with five cost alarms (#667) - #1332
Merged
Merged
Conversation
…cost alarms (#667) The dollars half of the telemetry programme, without waiting on split cost allocation (still 0 of 149,479 November CUR rows). - The join: EKS Auto Mode names a node by its instance id, task_instances records it, and the CUR keys BoxUsage, SpotUsage and the Auto Mode fee by the same line_item_resource_id. A runner pod holds its node alone, so an instance's cost splits across the attempts it hosted by wait + run. - run_costs (one per attempt): allocated_usd = hours × the class rate, billed_usd = its share of the instance's CUR cost (NULL until covered), billed_as_of. compute_rates per (class, YYYY-MM): self-calibrated usd_per_pod_hour. Each roll re-rolls the current and previous period in place; the previous rate prices the current period until billed. - Five scalars to CloudWatch ER/Cost, no tenant dimension, alarmed: MaxTenantSpendShare, MaxTenantDisproportion (spend ÷ records share, per dataset), FailedRunSpendShare, MaxCostPerMillionMoMChange (per dataset), CurStalenessHours. - er-server cost-roll, the er-cost-roll CronJob (dev ci only), and a read-only cost policy on the er-api Pod Identity role: the er-cost Athena workgroup (10 GiB scan cap), the er_cur Glue database, the CUR bucket, the results prefix, and PutMetricData limited to ER/Cost. - aws-sdk-athena and aws-sdk-cloudwatch (default-features = false); BlueOak-1.0.0 joins the Rust licence allowlist, as npm's already has it (minicbor, via the CloudWatch SDK's CBOR protocol). Follow-ups: per-statement shares #1330, prod #1331. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
terraform plan
dev — 6 to add, 0 to changedata.aws_iam_policy_document.efs_csi_trust: Reading...
data.aws_iam_policy_document.er_api_cost_roll: Reading...
data.aws_iam_policy_document.efs_csi_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.er_api_cost_roll: Read complete after 0s [id=3548580374]
module.network.data.aws_region.current: Reading...
data.aws_region.current: Reading...
data.aws_iam_policy_document.obs_pod_trust: Reading...
data.aws_iam_openid_connect_provider.github: Reading...
data.aws_iam_policy_document.eso_trust: Reading...
module.network.data.aws_region.current: Read complete after 0s [id=us-east-2]
data.aws_iam_policy_document.obs_pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.eso_trust: Read complete after 0s [id=819195744]
data.aws_region.current: Read complete after 0s [id=us-east-2]
data.aws_iam_policy_document.eso: Reading...
module.network.data.aws_availability_zones.available: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Reading...
data.aws_iam_policy_document.eso: Read complete after 0s [id=1725605485]
module.eks.data.aws_iam_policy_document.cluster_trust: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Read complete after 0s [id=2851119427]
module.eks.data.aws_iam_policy_document.cluster_trust: Read complete after 0s [id=1029077455]
data.aws_rds_engine_version.aurora_pg: Reading...
data.aws_iam_policy_document.er_api_pod_trust: Reading...
data.aws_caller_identity.current: Reading...
data.aws_iam_policy_document.er_api_pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.fluent_bit: Reading...
data.aws_iam_policy_document.fluent_bit: Read complete after 0s [id=4006586444]
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
module.lake.data.aws_iam_policy_document.lake_tls_only: Reading...
module.lake.data.aws_iam_policy_document.lake_tls_only: Read complete after 0s [id=4017345831]
data.aws_iam_policy_document.otel_collector: Reading...
data.aws_iam_policy_document.otel_collector: Read complete after 0s [id=3111493560]
data.aws_iam_policy_document.bedrock_invoke: Reading...
data.aws_iam_policy_document.lake_access: Reading...
data.aws_iam_policy_document.bedrock_invoke: Read complete after 0s [id=3601248236]
data.aws_iam_policy_document.lake_access: Read complete after 0s [id=2921565705]
data.aws_rds_engine_version.aurora_pg: Read complete after 0s [id=17.9]
module.network.data.aws_availability_zones.available: Read complete after 0s [id=us-east-2]
data.aws_iam_openid_connect_provider.github: Read complete after 0s [id=arn:aws:iam::797781631727:oidc-provider/token.actions.githubusercontent.com]
data.aws_iam_policy_document.ci_deploy_dev_trust: Reading...
data.aws_iam_policy_document.ci_deploy_dev_trust: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.ci_deploy_dev: Reading...
data.aws_iam_policy_document.ci_deploy_dev: Read complete after 0s [id=1754478413]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_cloudwatch_metric_alarm.cost["cost-per-million-mom"] will be created
+ resource "aws_cloudwatch_metric_alarm" "cost" {
+ actions_enabled = true
+ alarm_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ alarm_description = "A dataset's cost per million records rose more than 50% month over month on two consecutive rolls. Per dataset, not per org: an org's blend hides the degrading dataset."
+ alarm_name = "er-dev-cost-cost-per-million-mom"
+ arn = (known after apply)
+ comparison_operator = "GreaterThanThreshold"
+ datapoints_to_alarm = 2
+ dimensions = {
+ "Environment" = "dev"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 2
+ id = (known after apply)
+ metric_name = "MaxCostPerMillionMoMChange"
+ namespace = "ER/Cost"
+ ok_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ period = 86400
+ region = "us-east-2"
+ statistic = "Maximum"
+ tags_all = {
+ "Environment" = "dev"
+ "ManagedBy" = "terraform"
+ "Project" = "entity-resolution"
}
+ threshold = 0.5
+ treat_missing_data = "notBreaching"
}
# aws_cloudwatch_metric_alarm.cost["cur-staleness"] will be created
+ resource "aws_cloudwatch_metric_alarm" "cost" {
+ actions_enabled = true
+ alarm_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ alarm_description = "The CUR's newest line is more than 48h old: billed_usd is going stale and attribution is falling back to allocated. Check the core/cur.tf export."
+ alarm_name = "er-dev-cost-cur-staleness"
+ arn = (known after apply)
+ comparison_operator = "GreaterThanThreshold"
+ datapoints_to_alarm = 1
+ dimensions = {
+ "Environment" = "dev"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 1
+ id = (known after apply)
+ metric_name = "CurStalenessHours"
+ namespace = "ER/Cost"
+ ok_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ period = 86400
+ region = "us-east-2"
+ statistic = "Maximum"
+ tags_all = {
+ "Environment" = "dev"
+ "ManagedBy" = "terraform"
+ "Project" = "entity-resolution"
}
+ threshold = 48
+ treat_missing_data = "notBreaching"
}
# aws_cloudwatch_metric_alarm.cost["failed-run-spend-share"] will be created
+ resource "aws_cloudwatch_metric_alarm" "cost" {
+ actions_enabled = true
+ alarm_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ alarm_description = "More than 20% of runner spend went to attempts that failed, timed out or were retried. Check the failing task class and its error_class."
+ alarm_name = "er-dev-cost-failed-run-spend-share"
+ arn = (known after apply)
+ comparison_operator = "GreaterThanThreshold"
+ datapoints_to_alarm = 1
+ dimensions = {
+ "Environment" = "dev"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 1
+ id = (known after apply)
+ metric_name = "FailedRunSpendShare"
+ namespace = "ER/Cost"
+ ok_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ period = 86400
+ region = "us-east-2"
+ statistic = "Maximum"
+ tags_all = {
+ "Environment" = "dev"
+ "ManagedBy" = "terraform"
+ "Project" = "entity-resolution"
}
+ threshold = 0.2
+ treat_missing_data = "notBreaching"
}
# aws_cloudwatch_metric_alarm.cost["max-tenant-disproportion"] will be created
+ resource "aws_cloudwatch_metric_alarm" "cost" {
+ actions_enabled = true
+ alarm_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ alarm_description = "A dataset's share of spend is at least 3x its share of records on 2 of the last 3 days: a small tenant costing like a big one. The report names the (org, dataset)."
+ alarm_name = "er-dev-cost-max-tenant-disproportion"
+ arn = (known after apply)
+ comparison_operator = "GreaterThanOrEqualToThreshold"
+ datapoints_to_alarm = 2
+ dimensions = {
+ "Environment" = "dev"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 3
+ id = (known after apply)
+ metric_name = "MaxTenantDisproportion"
+ namespace = "ER/Cost"
+ ok_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ period = 86400
+ region = "us-east-2"
+ statistic = "Maximum"
+ tags_all = {
+ "Environment" = "dev"
+ "ManagedBy" = "terraform"
+ "Project" = "entity-resolution"
}
+ threshold = 3
+ treat_missing_data = "notBreaching"
}
# aws_cloudwatch_metric_alarm.cost["max-tenant-spend-share"] will be created
+ resource "aws_cloudwatch_metric_alarm" "cost" {
+ actions_enabled = true
+ alarm_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ alarm_description = "One org is more than half of the period's runner spend. Read the er-cost-roll job's report for which org; a single tenant dominating cost is a pricing or runaway-job signal."
+ alarm_name = "er-dev-cost-max-tenant-spend-share"
+ arn = (known after apply)
+ comparison_operator = "GreaterThanThreshold"
+ datapoints_to_alarm = 1
+ dimensions = {
+ "Environment" = "dev"
}
+ evaluate_low_sample_count_percentiles = (known after apply)
+ evaluation_periods = 1
+ id = (known after apply)
+ metric_name = "MaxTenantSpendShare"
+ namespace = "ER/Cost"
+ ok_actions = [
+ "arn:aws:sns:us-east-2:797781631727:er-alerts",
]
+ period = 86400
+ region = "us-east-2"
+ statistic = "Maximum"
+ tags_all = {
+ "Environment" = "dev"
+ "ManagedBy" = "terraform"
+ "Project" = "entity-resolution"
}
+ threshold = 0.5
+ treat_missing_data = "notBreaching"
}
# aws_iam_role_policy.er_api_cost_roll will be created
+ resource "aws_iam_role_policy" "er_api_cost_roll" {
+ id = (known after apply)
+ name = "er-dev-api-cost-roll"
+ name_prefix = (known after apply)
+ policy = jsonencode(
{
+ Statement = [
+ {
+ Action = [
+ "athena:StartQueryExecution",
+ "athena:GetWorkGroup",
+ "athena:GetQueryResults",
+ "athena:GetQueryExecution",
]
+ Effect = "Allow"
+ Resource = "arn:aws:athena:us-east-2:797781631727:workgroup/er-cost"
+ Sid = "AthenaCostWorkgroup"
},
+ {
+ Action = [
+ "glue:GetTables",
+ "glue:GetTable",
+ "glue:GetPartitions",
+ "glue:GetPartition",
+ "glue:GetDatabase",
]
+ Effect = "Allow"
+ Resource = [
+ "arn:aws:glue:us-east-2:797781631727:table/er_cur/*",
+ "arn:aws:glue:us-east-2:797781631727:database/er_cur",
+ "arn:aws:glue:us-east-2:797781631727:catalog",
]
+ Sid = "GlueCurCatalog"
},
+ {
+ Action = [
+ "s3:ListBucket",
+ "s3:GetObject",
+ "s3:GetBucketLocation",
]
+ Effect = "Allow"
+ Resource = [
+ "arn:aws:s3:::er-cur-797781631727/*",
+ "arn:aws:s3:::er-cur-797781631727",
]
+ Sid = "CurRead"
},
+ {
+ Action = [
+ "s3:PutObject",
+ "s3:ListBucket",
+ "s3:GetObject",
+ "s3:GetBucketLocation",
+ "s3:AbortMultipartUpload",
]
+ Effect = "Allow"
+ Resource = [
+ "arn:aws:s3:::er-athena-results-797781631727/q/*",
+ "arn:aws:s3:::er-athena-results-797781631727",
]
+ Sid = "AthenaResults"
},
+ {
+ Action = "cloudwatch:PutMetricData"
+ Condition = {
+ StringEquals = {
+ "cloudwatch:namespace" = "ER/Cost"
}
}
+ Effect = "Allow"
+ Resource = "*"
+ Sid = "CostMetrics"
},
]
+ Version = "2012-10-17"
}
)
+ role = "er-dev-api-pod"
}
Plan: 6 to add, 0 to change, 0 to destroy.
|
athvin
temporarily deployed
to
marketing-preview
November 28, 2026 00:30 — with
GitHub Actions
Inactive
This was referenced Nov 28, 2026
Merged
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #667
src/cost_roll.rs(pure allocation + scalars + the roll),src/cost_aws.rs(Athena source, CloudWatch sink), entitiesrun_costandcompute_rate,er-server cost-roll, theer-cost-rollCronJob,infra/terraform/envs/dev/cost-roll.tf(read-only cost policy on the er-api role + five alarms), and the as-built section in theer-engine-opsrunbook.#667: "understanding costs and being able to attribute" — the statement half was built; the dollars half was not. Its blocker (split cost allocation, an account opt-in) is still off, so this attributes by instance instead, which is exact for runner pods because each holds its node alone.
Proof
kubectl get nodesnames every nodei-…(=spec.providerID); the CUR'sBoxUsage,SpotUsageandEKS-Auto:*-management-hourslines all carry that instance id inline_item_resource_id.cost_rollunit tests: an instance's cost splits by wait + run; an uncovered instance's attempt is allocated at the prior rate and not billed; rates per class; each of the five scalars computed on a worked example; periods and instance-id validation.pg_cost_roll: two tenants, five attempts across two periods against Postgres with a fake CUR — billed shares, the not-yet-billed attempt allocated at the class rate, rates stored per (class, period), a re-roll that replaces rows in place once the CUR covers the last instance, and scalars reaching the sink with no tenant in them.terraform validate(envs/dev);cargo deny checkok;make checkexit 0; Postgres suite 162 passed. Theterraform planis in this PR's infra job: it adds one role policy and five alarms and destroys nothing.Risk & rollback
Read-only billing access and one metric namespace; a daily CronJob that only writes its own two tables.
git revert <merge-sha>.Post-merge ledger
Closed by: agent · session
Claude Code:24d16c2e-fec6-49d8-9797-060338df4848onMac· 2026-11-28T21:34:59Zmainis green with this change on it — the merge SHA, and the runthat proves it. A later head SHA with this commit as an ancestor counts;
a cancelled run with zero jobs does not: — a117903, rust 46088187740 + frontend 46088187684 success
imagesbuilt, or correctly never ran because nothing that goes intoan image changed: — success, run 46088187728
deployconverged — proved by a line the running process emitted, notby the image digest and not by the workflow conclusion: — run 46088895445 success; the CronJob it created was then deleted by the cutover (fixed forward by fix(deploy): the cutover keeps costRoll.enabled, so the cost-roll CronJob survives (#1334) #1335), and the first live run needed fix(obs): cost-roll gets an HTTP client and an honest staleness read (#1339) #1341's HTTP client. After both,
kubectl -n ci create job --from=cronjob/er-cost-rollprinted a report of 125 attempts, 85 billed, 3 rates, staleness 16.5hdeploy,drift,kind's nightly leg) is green, or knowingly red for a reason that is notthis change: — infra success (the plan: 6 to add, 0 to destroy), devcontainer success on a117903
Donethrough the automation rather than byhand, and the issue closed: — Cost attribution: the unbuilt half of the telemetry programme (P16/P17) #667 CLOSED by feat(obs): attribute runner cost from the CUR by instance, with five cost alarms (#667) #1332 via automation
(a skill, a reference, memory) — or nothing new was learned: — a unit-tested AWS client still needs a LIVE call to prove it can dispatch: default-features=false drops the HTTP client, which no test caught; and a CUR monthly line's usage_end is the month's end
Specific to this change
er-cost-rollJob succeeds on dev — er-cost-roll-verify-2 Complete in 12s after fix(deploy): the cutover keeps costRoll.enabled, so the cost-roll CronJob survives (#1334) #1335 and fix(obs): cost-roll gets an HTTP client and an honest staleness read (#1339) #1341 (attempts 125, billed 85, rates 3); its scalars were put to ER/CostContext — plan, discoveries, measurements, files
Plan
Discoveries
split_line_item→pod_uid) is blocked on the opt-in, but runner pods are exclusive on their nodes, so the instance join is exact for them and needs no opt-in.minicboris BlueOak-1.0.0, which npm's allowlist already carried.Measurements
Files
🤖 Generated with Claude Code