The statistics API returns the DHCP mode, pool utilisation per scope, active leases over time, message rates and relayed traffic #118

Open
opened 2026-10-31 12:42:09 -04:00 by claude · 0 comments
Owner
  • Draft: PQ-39
  • Priority: high
  • Agent: coder
  • Depends on: #116, #117
  • Decisions: Q-PQ-12, R2-STATS-NODE, R2-DHCP-RELAY

Why

The console must know whether to show DHCP charts and which ones, and needs the DHCP series. Today it could only call GET api/dhcp/scopes/{id}/statistics once per scope.

What changes

In StatisticsController (#117):

  • GET dhcp/summary: { dhcpv4Mode, dhcpv6Mode, scopes[] }. The modes are Off, Local or Relay for this node, by the #116 rule (DhcpProtocolModeResolver). scopes[] is filled only for a protocol in Local mode. Each scope entry carries id, name, protocol, kind and the DhcpScopeStatistics fields from IDhcpScopeStatisticsService.ComputeAsync (slot counts as decimal strings, as DhcpScopesController.Statistics sends them, DhcpScopesController.cs:120-132), plus a utilisation percentage.
    • Pool utilisation is computed live from the lease table, which all nodes on one database share, so it takes no nodeId.
    • It reads the same service #167 changes, so excluded addresses stop counting as free once #167 lands; no change is needed here then.
  • GET dhcp/timeseries?protocol=IPv4|IPv6&fromUtc&toUtc&bucket=Minute|Hour&nodeId: per bucket the message counts by received and sent type, the relay counts (requests forwarded, replies forwarded, dropped) and the active-lease gauge in total and per scope.
  • Both require dhcpscopes:read (the permission of the existing scope statistics, DhcpScopesController.cs:109) and are [ReadFromReplica].
  • Range validation as in #117. Models plus Swagger examples.

Acceptance

  • src/dotnet/tests/Ninlil.Web.Tests fails first: with DHCP disabled in the shared host, GET dhcp/summary returns dhcpv4Mode: "Off" and dhcpv6Mode: "Off".
  • A second host (factory.CreateSecondHost) with the DHCPv4 engine enabled on a free port and one scope returns dhcpv4Mode: "Local" and that scope in scopes[] with totalSlots as a string.
  • A second host with the DHCPv4 relay enabled returns dhcpv4Mode: "Relay" and an empty scopes[]; after a forced flush of fake relay counts, dhcp/timeseries?protocol=IPv4 carries them.
  • 403 without dhcpscopes:read; 400 on reversed ranges.
  • API change (snapshot in #120).

Source

  • Owner decision 2026-10-31 (Q-PQ-12): "DHCP charts when DHCP is on".
  • Owner decisions 2026-10-31, round 2: R2-STATS-NODE (node parameter), R2-DHCP-RELAY (relay series; charts when a local engine or the relay runs).
  • DEDUPE.md A4 (pool utilisation follows #167's statistics).
- **Draft:** PQ-39 - **Priority:** high - **Agent:** coder - **Depends on:** #116, #117 - **Decisions:** Q-PQ-12, R2-STATS-NODE, R2-DHCP-RELAY ### Why The console must know whether to show DHCP charts and which ones, and needs the DHCP series. Today it could only call `GET api/dhcp/scopes/{id}/statistics` once per scope. ### What changes In `StatisticsController` (#117): - `GET dhcp/summary`: `{ dhcpv4Mode, dhcpv6Mode, scopes[] }`. The modes are `Off`, `Local` or `Relay` for this node, by the #116 rule (`DhcpProtocolModeResolver`). `scopes[]` is filled only for a protocol in `Local` mode. Each scope entry carries id, name, protocol, kind and the `DhcpScopeStatistics` fields from `IDhcpScopeStatisticsService.ComputeAsync` (slot counts as decimal strings, as `DhcpScopesController.Statistics` sends them, `DhcpScopesController.cs:120-132`), plus a utilisation percentage. - Pool utilisation is computed live from the lease table, which all nodes on one database share, so it takes no `nodeId`. - It reads the same service #167 changes, so excluded addresses stop counting as free once #167 lands; no change is needed here then. - `GET dhcp/timeseries?protocol=IPv4|IPv6&fromUtc&toUtc&bucket=Minute|Hour&nodeId`: per bucket the message counts by received and sent type, the relay counts (requests forwarded, replies forwarded, dropped) and the active-lease gauge in total and per scope. - Both require `dhcpscopes:read` (the permission of the existing scope statistics, `DhcpScopesController.cs:109`) and are `[ReadFromReplica]`. - Range validation as in #117. Models plus Swagger examples. ### Acceptance - [ ] `src/dotnet/tests/Ninlil.Web.Tests` fails first: with DHCP disabled in the shared host, `GET dhcp/summary` returns `dhcpv4Mode: "Off"` and `dhcpv6Mode: "Off"`. - [ ] A second host (`factory.CreateSecondHost`) with the DHCPv4 engine enabled on a free port and one scope returns `dhcpv4Mode: "Local"` and that scope in `scopes[]` with `totalSlots` as a string. - [ ] A second host with the DHCPv4 relay enabled returns `dhcpv4Mode: "Relay"` and an empty `scopes[]`; after a forced flush of fake relay counts, `dhcp/timeseries?protocol=IPv4` carries them. - [ ] 403 without `dhcpscopes:read`; 400 on reversed ranges. - [ ] API change (snapshot in #120). ### Source - Owner decision 2026-10-31 (Q-PQ-12): "DHCP charts when DHCP is on". - Owner decisions 2026-10-31, round 2: R2-STATS-NODE (node parameter), R2-DHCP-RELAY (relay series; charts when a local engine or the relay runs). - DEDUPE.md A4 (pool utilisation follows #167's statistics).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#118
No description provided.