# Safely re-generate report

## Background

What I confirmed from code (important)
- monthlyproportionsum is triggered in cmd/main.go via schedule.MonthlyProportionSumGlobally().
- It runs once immediately on startup, then hourly (pkg/schedule/monthlyproportionsum.go).
- Trigger condition is:
  - (4th day midnight UTC && monthlyProportion == true) OR
  - (renewMonthlyProportionTs > 0 && now > renewMonthlyProportionTs).
- It does not use checkpoint.yaml (schedule.Task checkpoint path is for other tasks).
- No HTTP API exists to directly trigger monthly proportion sum.
- DB insert is CreateInBatches into monthly_proportion_sum (no upsert logic in this path), so repeated reruns can duplicate rows.
- CSV upload target is fixed: s3://o11y-prod-shared-us-west-2/metering/split/o11y_usage_proportion_<YYYY-MM>.csv.


## Steps

1) Pre-check current data (avoid blind rerun)
-- report DB
SELECT COUNT(*) FROM monthly_proportion_sum WHERE month='2026-02';
2) Backup existing month rows if exists
CREATE TABLE monthly_proportion_sum_bak_202602 AS
SELECT * FROM monthly_proportion_sum WHERE month='2026-02';
3) Prevent duplicate rows on rerun
Since rerun is non-idempotent in current code path, clear target month first:
DELETE FROM monthly_proportion_sum WHERE month='2026-02';
4) Trigger rerun (supported operational path)
Because no direct API exists, use config + restart:
- Set us-west-2 metering-server's `scheduleConfig.renewMonthlyProportionTs` to a past unix ts (e.g. target month ts or 1) in meteringconfig.yaml.
- Ensure this key is actually present in the runtime config source (note: current Helm chart template renders monthlyProportion but not renewMonthlyProportionTs; you may need to patch configmap values/template pipeline).
- Restart metering pod/process.
K8s typical:
kubectl -n observability rollout restart statefulset/metering-server
kubectl -n observability logs -f statefulset/metering-server
Watch for logs:
- start to generate monthly proportion report
- generate monthly proportion sum report succeed

5) Immediately disable repeated reruns
Critical: if renewMonthlyProportionTs stays >0 and in the past, condition stays true every hour.
- Set renewMonthlyProportionTs: 0 (or remove it), apply config, restart once more.
6) Verify results
SELECT COUNT(*) FROM monthly_proportion_sum WHERE month='2026-02';
SELECT * FROM monthly_proportion_sum WHERE month='2026-02' LIMIT 20;
Check CSV:
aws s3 ls s3://o11y-prod-shared-us-west-2/metering/split/o11y_usage_proportion_2026-02.csv
7) Rollback if bad
DELETE FROM monthly_proportion_sum WHERE month='2026-02';
INSERT INTO monthly_proportion_sum SELECT * FROM monthly_proportion_sum_bak_202602;
