feat(metering): send the month's peak of extra targets (t72) #929

Merged
sharang merged 1 commits from feat/t72-extra-event into main 2026-11-06 15:55:44 +00:00
Owner

Part (c), item 1 of t72. This sends the extra-target line to the registry, following the contract agreed for tenant-registry #114.

  • After each billing refresh (before a scan, and when a target is created), the agent stores the month's peak number of extra active targets in metering_months.extra_peak. Months are Europe/Berlin calendar months.
  • When the peak rises, it sends target.extra with quantity = peak and key target-extra:{tenant}:{YYYY-MM}:{peak}.
  • Once a day it re-sends the current peak. The registry drops that as a duplicate of its key, so ERP usage records stay append-only.
  • Billing takes the highest quantity per tenant-month.
  • The event carries a count only (properties: month), never target names.
  • Hardening: the quota filter also matches a month document that has no pruefungen counter yet. The peak can create that document before the first Prüfung is charged.

Tests

tests/extra_peak.rs (Mongo) covers:

  • a rise is sent;
  • a second send the same day is not;
  • archiving an extra target leaves the peak unchanged;
  • a re-send happens the next day;
  • a new month starts from the current count;
  • the quota still counts on a month document the peak created.

Not built locally, per the CI-only rule.

🤖 Generated with Claude Code

Part (c), item 1 of t72. This sends the extra-target line to the registry, following the contract agreed for tenant-registry #114. - After each billing refresh (before a scan, and when a target is created), the agent stores the month's peak number of extra active targets in `metering_months.extra_peak`. Months are Europe/Berlin calendar months. - When the peak rises, it sends `target.extra` with quantity = peak and key `target-extra:{tenant}:{YYYY-MM}:{peak}`. - Once a day it re-sends the current peak. The registry drops that as a duplicate of its key, so ERP usage records stay append-only. - Billing takes the highest quantity per tenant-month. - The event carries a count only (properties: `month`), never target names. - **Hardening:** the quota filter also matches a month document that has no `pruefungen` counter yet. The peak can create that document before the first Prüfung is charged. ## Tests `tests/extra_peak.rs` (Mongo) covers: - a rise is sent; - a second send the same day is not; - archiving an extra target leaves the peak unchanged; - a re-send happens the next day; - a new month starts from the current count; - the quota still counts on a month document the peak created. Not built locally, per the CI-only rule. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-06 15:21:30 +00:00
feat(metering): send the month's peak of extra targets (t72)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m5s
CI / Check (pull_request) Successful in 17m8s
3e376ba6b0
The 5,99 € line bills the highest number of extra targets at once in
the calendar month (Europe/Berlin), with no proration.

- After each billing refresh (before a scan, when a target is created)
  the agent records how many active targets are extra as the month's
  peak, in metering_months.
- When the peak rises it sends `target.extra` with quantity = peak and
  the key target-extra:{tenant}:{YYYY-MM}:{peak}; once a day it sends
  the current peak again, which the registry drops as a duplicate of
  its key. Count only: no target names leave Prüfwerk.
- The quota filter also matches a month document without the counter,
  since the peak can create that document first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit 9ce3b868bb into main 2026-11-06 15:55:44 +00:00
Sign in to join this conversation.