Track immutable telemetry ownership for reused device identifiers
- Dominant language
- Go
- Stars
- 55
- Forks
- 16
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 84
Description
🤖 Follow-up from #648 and #685.
## Problem
`device_metrics` rows currently carry `device_identifier` and row-stamped `site_id`, but not immutable `org_id` or `device_id`. Some org-scoped dashboard paths therefore reconstruct ownership later by joining through `device` using `device_identifier`.
Because `device.device_identifier` is only unique among non-deleted devices, a miner can be soft-deleted and later re-paired under another org with the same identifier. Historical metric rows for that identifier can then be attributed to the current device row instead of the org/device that owned the miner when the samples were written.
This was explicitly left out of #648, and #685 keeps the same limitation while adding faster org-scoped rollup/raw/hourly reads.
## Impact
- New owner may see prior-owner telemetry in org-wide dashboard history.
- Prior owner may lose historical org-wide dashboard data after identifier reuse.
- Fleet metric rollups can persist the reconstructed ownership until retention removes those rollup rows.
## Suggested Direction
Stamp immutable ownership on telemetry at write time:
- Add `org_id` and `device_id` to `device_metrics`.
- Populate those columns in `InsertDeviceMetrics` from the paired device row at ingest.
- Backfill existing hot telemetry where feasible, or clearly fall back for historical rows without ownership.
- Update raw, hourly/daily, and fleet-rollup reads to filter by stamped `org_id` / `device_id` instead of deriving ownership from the latest mutable `device` row.
## Acceptance Criteria
- Org-scoped raw combined-metrics reads do not include metrics from a prior owner after `device_identifier` reuse.
- Org-scoped hourly/daily aggregate reads do not include metrics from a prior owner after `device_identifier` reuse.
- Fleet metric rollup writes do not attribute historical samples to the current owner after `device_identifier` reuse.
- Regression test: org A writes metrics, device is soft-deleted, same identifier is paired in org B, and org B org-wide dashboard paths do not include org A samples.
Contributor guide
Research direction
Start at InsertDeviceMetrics and trace how device_metrics rows are written with ownership data. Then follow the raw, hourly/daily, and fleet-rollup reads and writes to identify where ownership is derived from device_identifier. Add the regression test described in the acceptance criteria and verify that reused identifiers do not expose prior-owner samples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend-api-design, databases
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100