The statistics API returns a summary, the queries-over-time series, top-N lists, the answer mix and upstream latency for a time range, for all nodes or one node #117

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

Why

The console's four DNS chart sets need these reads, and the node filter needs the list of nodes.

What changes

  • New Ninlil.Web/Controllers/StatisticsController.cs, [Route("api/statistics")]. Every action below takes an optional nodeId; without it the answer covers all nodes (#111 rules: counters summed, gauges by maximum).
    • GET nodes?fromUtc&toUtc: the nodes with statistics in the range, each { nodeId, name, isThisNode }. The name comes from the peer registry (ClusterNodeEntity.Name where RemoteNodeId matches, src/dotnet/src/Ninlil.Dns.Data.Abstractions/Entity/ClusterNodeEntity.cs:25,34), "this node" for ClusterOptions.NodeId, and the id otherwise.
    • GET summary?fromUtc&toUtc: total, blocked, cached, NXDOMAIN, SERVFAIL, average latency.
    • GET timeseries?fromUtc&toUtc&bucket=Minute|Hour: per bucket total, blocked, cached.
    • GET top?kind=Domain|BlockedDomain|Client&fromUtc&toUtc&take, with take capped at 100.
    • GET mix?fromUtc&toUtc: queryTypes[], responseCodes[], answerSources[], each { key, count }, from hour rows.
    • GET upstreams?fromUtc&toUtc&bucket=Minute|Hour: per upstream the average latency and count over the range, and a series of per-bucket averages (sum divided by count).
  • All actions are [ReadFromReplica] and require querylog:read. Technical call: top domains and clients reveal the same data as the query log, so they use the same permission, and no new permission is needed that existing roles lack.
  • Range validation: from ≤ to; minute buckets at most 48 h (the minute retention); mix and hour buckets align the range to whole hours. An unknown nodeId returns empty results, not 404 (a node may simply have no rows yet).
  • Models plus Swagger examples.

Acceptance

  • src/dotnet/tests/Ninlil.Web.Tests: fails first; after some answered queries plus a forced flush, GET summary returns totalQueries >= n, and GET summary?nodeId=<this node> returns the same total. Do not assert an exact count, because the host is shared.
  • GET nodes lists this node with isThisNode: true.
  • GET mix after an MX query returns an MX entry with count ≥ 1; GET upstreams returns one entry per upstream with a series.
  • 400 on reversed ranges and on a minute range over 48 h; 403 without querylog:read.
  • API change (snapshot in #120).

Source

  • audit-feature-parity.md §2A #1.
  • Owner decision 2026-10-31 (Q-PQ-12): all four DNS chart sets.
  • Owner decision 2026-10-31, round 2 (R2-STATS-NODE): "API gets a node parameter".
- **Draft:** PQ-15 - **Priority:** high - **Agent:** coder - **Depends on:** #112 - **Decisions:** Q-PQ-12, R2-STATS-NODE ### Why The console's four DNS chart sets need these reads, and the node filter needs the list of nodes. ### What changes - New `Ninlil.Web/Controllers/StatisticsController.cs`, `[Route("api/statistics")]`. Every action below takes an optional `nodeId`; without it the answer covers all nodes (#111 rules: counters summed, gauges by maximum). - `GET nodes?fromUtc&toUtc`: the nodes with statistics in the range, each `{ nodeId, name, isThisNode }`. The name comes from the peer registry (`ClusterNodeEntity.Name` where `RemoteNodeId` matches, `src/dotnet/src/Ninlil.Dns.Data.Abstractions/Entity/ClusterNodeEntity.cs:25,34`), "this node" for `ClusterOptions.NodeId`, and the id otherwise. - `GET summary?fromUtc&toUtc`: total, blocked, cached, NXDOMAIN, SERVFAIL, average latency. - `GET timeseries?fromUtc&toUtc&bucket=Minute|Hour`: per bucket `total`, `blocked`, `cached`. - `GET top?kind=Domain|BlockedDomain|Client&fromUtc&toUtc&take`, with take capped at 100. - `GET mix?fromUtc&toUtc`: `queryTypes[]`, `responseCodes[]`, `answerSources[]`, each `{ key, count }`, from hour rows. - `GET upstreams?fromUtc&toUtc&bucket=Minute|Hour`: per upstream the average latency and count over the range, and a series of per-bucket averages (sum divided by count). - All actions are `[ReadFromReplica]` and require `querylog:read`. **Technical call:** top domains and clients reveal the same data as the query log, so they use the same permission, and no new permission is needed that existing roles lack. - Range validation: from ≤ to; minute buckets at most 48 h (the minute retention); `mix` and hour buckets align the range to whole hours. An unknown `nodeId` returns empty results, not 404 (a node may simply have no rows yet). - Models plus Swagger examples. ### Acceptance - [ ] `src/dotnet/tests/Ninlil.Web.Tests`: fails first; after some answered queries plus a forced flush, `GET summary` returns `totalQueries >= n`, and `GET summary?nodeId=<this node>` returns the same total. Do not assert an exact count, because the host is shared. - [ ] `GET nodes` lists this node with `isThisNode: true`. - [ ] `GET mix` after an MX query returns an `MX` entry with count ≥ 1; `GET upstreams` returns one entry per upstream with a series. - [ ] 400 on reversed ranges and on a minute range over 48 h; 403 without `querylog:read`. - [ ] API change (snapshot in #120). ### Source - `audit-feature-parity.md` §2A #1. - Owner decision 2026-10-31 (Q-PQ-12): all four DNS chart sets. - Owner decision 2026-10-31, round 2 (R2-STATS-NODE): "API gets a node parameter".
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#117
No description provided.