Repository navigation
Add Neutron active quota reservations and filter invalid owners - #4
Conversation
ConnectContext pings and closes the pool when the database does not answer, so a caller that starts during a database outage has no pool at all. The OpenStack database exporter then reports its services as down until it is restarted, even after the database is back. Open does the parsing and pool setup without contacting the server, and ConnectContext becomes Open plus the ping, so existing callers behave as before. The pool connects on first use and reconnects after a lost connection. Tested with go test -race, go vet, gofmt and the integration suite. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Timon Schnell <timon.schnell@btc-it-services.com>
adamhackl
left a comment
There was a problem hiding this comment.
Thanks for this. The SQL looks correct, and the boundary coverage in both the SQLite and MariaDB tests is thorough. I’m reviewing from the observability side, since these numbers will eventually feed our quota metrics. A few things before merge:
- Compute the cutoff in the database instead of taking it from the caller (neutron/db/queries.sql, GetActiveReservationsByProject)
WHERE r.expiration >= sqlc.arg(cutoff) makes the result depend on the caller’s clock matching the clocks of the Neutron servers that wrote the expirations. Reservations are short-lived, so a few seconds of skew between the exporter host and the controllers is enough to change what counts as active. Could this use UTC_TIMESTAMP() instead? That keeps the comparison on the database’s clock, drops the parameter, and removes the need for the “callers supply UTC” note in API.md. If there’s a reason to keep it caller-supplied (for example, reproducible queries in tests), the skew risk should at least be documented.
- Owner filtering is now inconsistent across the quota reads
After this change, GetResourceCountsByProject and GetActiveReservationsByProject exclude empty-string project IDs, but GetQuotas still returns them. API.md documents this, but it leaves every consumer that combines limits with usage to handle the mismatch itself. Is there a reason GetQuotas shouldn’t get the same project_id <> '' filter? If the difference is intentional, a sentence on why would help. Also, since the change to GetResourceCountsByProject alters existing results, please call it out in the release notes.
- Has the query plan been checked against a real Neutron schema?
The fixture reservations table has no index on expiration, which is fine for tests. In production, though, this query will run on every scrape. Normally the table is tiny, but it grows if Neutron’s cleanup of expired reservations stalls. Has anyone run EXPLAIN against a real Neutron schema to confirm it doesn’t turn into a full scan plus join on each collection?
- Nit: deterministic ordering for GetQuotas (optional, not introduced by this PR)
The new docs say GetQuotas keeps duplicate project/resource rows, but with no ORDER BY, consumers that collapse duplicates get whichever row comes last. That row can change between calls when duplicates have different limits. Adding an ORDER BY, or a note in API.md, would make that behavior predictable.
The handling of negative sums, the InvalidAmounts count, separate reads without a shared snapshot, and error propagation all look good and are clearly documented.
874632e to
b9f1100
Compare
Open adds no dial timeout, so a pool held through a database outage does not fail fast. Say so in the Open doc comment and the README, and move the Open note into its own README paragraph. Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
Add Open for a pool without the startup ping
b9f1100 to
d3a59e4
Compare
Add three read-only Designate queries for openstack_database_exporter: - ZoneGetAll: non-deleted zones with status and type. - RecordsetCountByZone: recordset count per non-deleted zone, including zones with no recordsets, without reading individual records. - RecordsetGetAllWithStatus: recordsets with the status the Designate API reports (worst child record status in the order ERROR, PENDING, ACTIVE, DELETED; ACTIVE when a recordset has no records). Zone and recordset IDs are returned as dashed UUIDs, matching the API. Splitting the queries lets the exporter skip the per-recordset status query when that metric is disabled. Signed-off-by: Tadas Sutkaitis <tadas.sutkaitis@vexxhost.com>
Add GetReservationsForResources, which follows Neutron's get_reservations_for_resources(expired=False) for every project at once. It returns one row per active reservation delta (reservation ID, project ID, expiration, resource and amount), ordered by project, resource and reservation ID. Amounts are returned as stored, including NULL and negative values, rather than summed. A reservation is active when expiration >= UTC_TIMESTAMP(), the same inclusive boundary Neutron uses. The comparison runs on the database clock in UTC, so caller clock skew and session time zones do not affect the result. The resources to read are a positional argument; an empty list matches nothing, as upstream. NULL owners are excluded and empty-string owners are kept, matching GetQuotas and GetResourceCountsByProject, so limits, usage and reservations join on project ID without special cases. GetResourceCountsByProject is unchanged. GetQuotas now orders by project, resource and quota ID so callers that collapse duplicate rows get a stable result. Add the reservations and resourcedeltas tables to the Neutron schema fixture, without indexes on expiration or project_id as upstream. Add unit tests, MariaDB integration tests for reservations and quota owner handling and ordering, and API.md documentation. Co-authored-by: David Hulick <dave.hulick@gmail.com> Signed-off-by: David Hulick <dave.hulick@gmail.com> Signed-off-by: Jeremy Lee <jeremy.lee1664@gmail.com>
d3a59e4 to
75cf35c
Compare
Summary
Add Neutron quota reservation accounting for nine supported resource types, preserving the existing downstream implementation.
Changes
GetActiveReservationsByProjectwith inclusive expiration filtering, signed aggregation, and detection of NULL/negative reservation amounts.GetResourceCountsByProject.GetQuotasbehavior.Compatibility
GetResourceCountsByProjectnow excludes empty-project-ID records across all nine resource types. Previously, these records were returned by upstream.This intentionally changes existing query results. Valid project counts and the existing Go API remain unchanged.