Skip to content

Cost attribution: the unbuilt half of the telemetry programme (P16/P17) #667

Done

Description

@athvin

The unbuilt half of the telemetry programme · release mvp · estimate 3.0 eng-weeks

Tracing is done; cost attribution is not started. This is telemetry plan P16 + P17 — two Postgres entities, a roll-up job, and five derived alarms. The owner named it as co-equal with tracing: "what is absolutely critical is understanding costs and being able to attribute every single sql statement". The statement half is built and persisted; the dollars half is not.

Note: issue #579, the closed shipped card, is titled "Observability — OpenTelemetry with cost attribution". Its body claims only tracing and statement attribution, which is accurate. The title overstates. This issue is the missing half.

Two blockers, both outside the code

  1. Split cost allocation is not switched on. Measured 2026-11-05: 0 of 19,770 November CUR rows carry split-allocation columns. It is a Billing console toggle, and it does not backfill — every day of delay is permanently unattributable pod-level spend. Tracked separately as Cost allocation tags + CUR verification #563, which is currently labelled post-appexchange while this is mvp. That contradiction needs resolving — this cannot ship ahead of its blocker.
  2. There is no runner workload to cost. October billed 0.3 hours of runner compute. A cost model calibrated against nothing converges on nothing, so this needs the batch orchestration work to be running real jobs first.

Decisions already taken — do not re-derive these

The design work is done and is worth carrying forward verbatim, because each of these was reasoned against a specific blocked alternative:

  • compute_price is self-calibrated from the CUR, not the Pricing API. The obvious path is architecturally closed: rbac-dispatcher.yaml lists nodes as deliberately absent, and nodes is cluster-scoped so granting it means a ClusterRole against D-TENANCY; IMDS is closed by the §5.6 hop limit. A blended rate per (class, billing_period) also folds the family mix, the spot/on-demand mix and the Auto Mode ~12% fee in automatically, and converges rather than drifting.
  • wait_seconds is part of the cost. allocated_usd = (wait_seconds + run_seconds) / 3600 * usd_per_pod_hour. A node was provisioned for that attempt — real money. Dropping the ~30s provision-dominated cold start understates a 120s run by 25%.
  • S and M carry the same rate, and that is not a bug. With the runner taint, do-not-disrupt and inFlightCap: 1, a 2-vCPU S pod holds a whole node exactly as a 6-vCPU M pod does. The cost lever is duration, not class. Say so in the docs or somebody will "optimize" by downgrading a class and change nothing.
  • run_cost is an entity, not a view. The CUR arrives 24–48h late and is revised, so the row carries both allocated_usd and billed_usd/billed_as_of. task_instances.live goes NULL on archive, so a view would lose exactly the retried attempts the failure-spend query needs.
  • The pod→CUR join is line_item_resource_id tail → task_instances.pod_uid (unique across namespaces and restarts, unlike pod_name). resource_tags exposes only the six AWS-generated aws:eks:* tags, so the er.dupezero.com/* pod labels will not be CUR columns.
  • Per-statement cost is normalised by attempt WALL time, not by the statement sum. Normalising by the sum makes shares total 100% and hides the residual — DuckDB parallelism outside statement boundaries, the cold start, inter-statement latency. Publish coverage on every roll-up; if it is 61%, say 61%.
  • Never quote a per-statement dollar figure below $0.01. Present a share of wall time with dollars derived. The failure to avoid: someone reads "golden_record.upsert costs $0.42/run", spends a week optimising, and finds nothing, because its 30% wall share was 90% waiting on something the SQL cannot influence.
  • Do not build per-statement S3 attribution. 10,000 GETs per run is $0.004 and S3→EC2 in-region is $0. Emit s3_get_requests per attempt and alarm above 1M GETs/run, which is a partition-layout bug worth paging on.

The alarms (P17)

Aggregate scalars with no tenant dimension — the tenant's identity rides in the report payload, never a label. MaxTenantSpendShare > 0.5; MaxTenantDisproportion ≥ 3 for 2 of 3 periods; FailedRunSpendShare > 0.20; MaxCostPerMillionMoMChange > 0.5 twice consecutively; CurStalenessHours > 48.

disproportion = share_of_spend / share_of_records is the one scalar expressing "a small tenant costing like a big one". It is a max over (org, dataset) pairs, which is how it reaches a CloudWatch alarm without breaking the cardinality rule.

Cost-per-million must be per dataset, not per org: one org now runs several datasets concurrently and its org-level figure is a blend that hides the degrading one.

Current independent delivery

#1050 / merged PR #1051 implements the pending-runner and oldest-queued-job age alerts below, extending #552's operational snapshot/module. Post-merge/live-readback evidence is recorded in that PR ledger. Existing child #877 tracks the standalone alarm programme, including the remaining three signals and confirmation of the live alert path. The cost model remains on this parent; neither this parent nor #877 is complete.

Also unbuilt, and higher value per unit of effort than the model

None of these exist and none need the cost model:

  • runner pod pending > 600s — the vCPU quota leaving a pod pending forever is a documented trap that has already cost real time
  • oldest queued job age > 900s
  • attempt failure rate > 25%/h
  • spot interruption rate — how the spot assumption gets verified rather than trusted
  • impersonation volume — free the moment erweb.audit has rows, and the most security-valuable item in the set

Consider doing these first; they are independent of both blockers above.

Tasks

  • Resolve the mvp / post-appexchange contradiction with Cost allocation tags + CUR verification #563 and switch on split cost allocation.
  • infra/terraform/envs/core/athena.tf — Glue database, partition projection on BILLING_PERIOD, a 10 GiB bytes_scanned_cutoff_per_query so a forgotten WHERE fails instead of billing. (Plan P1; also unbuilt.)
  • The three CUR probe queries in docs/runbook.md, answered against one real month.
  • The two entities, the er-server cost-roll CronJob, the five alarms.
  • The five standalone alarms above, which can land first.

Measurements dated 2026-11-05. The design decisions are from the telemetry plan and were each reasoned against a specific blocked alternative; the blockers were probed, not assumed.


Product context (2026-11-26)

Why this matters for the API product: This is indirect. It doesn't change any API step, but it gives cost per dataset and a runaway-tenant alarm. Both are needed to price the API and to operate safely with many tenants.

Current state:

Definition of done: As above, for task 4 only.

Dependencies / sequencing: It's blocked on the owner console action. After that, wait one day of data. Move the card back to Todo or mark it blocked until then.

Open product decision: The owner has to enable Billing → Cost Management preferences → Split cost allocation data → Amazon EKS. It can only be done in the console, and it doesn't backfill.

Size: About 2 engineer-weeks remaining, down from 3. This is unverified.

Activity

  1. added
    mvp
    obs-backlog
    on Nov 6, 2026
  2. athvin commented on Nov 8, 2026

    @athvin
    OwnerAuthor

    Filed #877 for the five standalone alarms — the part of this issue that is independent of both blockers, per this issue's own 'consider doing these first'.

  3. athvin commented on Nov 27, 2026

    @athvin
    OwnerAuthor

    Status 2026-11-27 (autonomous board pass).

    Still blocked on one owner action, and it is the only blocker left for the data: the account-level Billing → Cost Management preferences → Split cost allocation data → Amazon EKS opt-in. It is console-only (no API/CLI — confirmed against the CUR user guide), free, and does not backfill.

    Re-probed today with er-builder: the CUR 2.0 export still has INCLUDE_SPLIT_COST_ALLOCATION_DATA = TRUE, and 0 of 147,646 November rows (2026-11-01 → 2026-11-26) carry a split_line_item_split_cost. Project/Environment/ManagedBy are active; Developer is on no resource; aws:eks:cluster-name inactive.

    Done meanwhile:

    Remaining here once the opt-in has produced a day of data: the two entities, the cost-roll CronJob and the five cost alarms.

  4. self-assigned this
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

mvpobs-backlog

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions