Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ with identical semantics upstream.
| `octavia/db/repositories` | `GetAllPools` | `PoolGetAll` |
| `octavia/db/repositories` | `GetAllLoadBalancersWithVip` | `LoadBalancerGetAllWithVIP` |
| `octavia/db/repositories` | `GetAllAmphora` | `AmphoraGetAll` |
| `octavia/db/repositories` | — | `QuotaGetAll` (`QuotaRepository.GetAll`) |
| `octavia/db/repositories` | — | `QuotaUsageGetAll` (`QuotaRepository.GetUsage`) |
| `placement/objects` | `GetResourceMetrics` | `GetResourceProviderInventories` |
| `placement/objects` | `GetAllocationsByProject` | `GetAllocationsByProject` |
| `placement/objects` | `GetConsumerCountByProject` | `GetConsumerCountByProject` |
Expand Down Expand Up @@ -80,7 +82,8 @@ with identical semantics upstream.
- The filtered APIs support exact membership and lifetime overlap, not every upstream regex, pagination, eager-loading, or authorization option.
- Current exporter queries retain their existing deleted/hidden/status predicates; they are not full upstream administrative listings.
- Errors are Go/database errors; absent single resources return `sql.ErrNoRows` rather than Python service-specific exceptions.
- Aggregate queries such as `QuotaGetAllWithUsage`, `GetResourceProviderInventories`, and `GetResourceCountsByProject` are explicitly library extensions.
- Aggregate queries such as `QuotaGetAllWithUsage`, `GetResourceProviderInventories`, `GetResourceCountsByProject`, and Octavia `QuotaUsageGetAll` are explicitly library extensions. Octavia `QuotaUsageGetAll` recounts objects with `check_quota_met`'s predicate; Octavia itself enforces against the cached `in_use_*` counters that `QuotaGetAll` returns.
- Owner filtering follows each service: Neutron keeps empty-string project IDs because Neutron creates real objects with them (for example L3 HA networks and ports), while Octavia excludes them because it rejects empty project IDs.
- Designate returns canonical zone and recordset UUIDs and excludes soft-deleted zones. `RecordsetCountByZone` includes zero-count zones and can run without reading individual records. `RecordsetGetAllWithStatus` uses the child precedence `ERROR`, `PENDING`, `ACTIVE`, `DELETED` and returns `ACTIVE` for an empty recordset. Recordsets with a NULL `zone_id` have no visible zone and are omitted.
- No cross-cell routing or historic schema negotiation is performed. Nova archive access is explicitly selected with `InstanceFilters.Archive`.

Expand All @@ -99,3 +102,39 @@ lifecycle metadata. Their fixed current-resource queries remain unchanged for
exporter consumers. Deleted volume types and legacy type tables are only read
when explicitly requested. Legacy table availability is a caller/deployment
concern; errors are propagated rather than hidden.

### Octavia quotas

| Go operation | Upstream naming source | Scope |
| --- | --- | --- |
| `QuotaGetAll` (`QuotaRepository.GetAll`) | [Octavia `QuotasRepository`](https://github.com/openstack/octavia/blob/master/octavia/db/repositories.py) | Stored limits and cached `in_use_*` counters for every project at once; NULL and empty project IDs excluded. |
| `QuotaUsageGetAll` (`QuotaRepository.GetUsage`) | Octavia `Repositories.check_quota_met` recount predicate | Library extension: recounts all seven quota resources for every project; scans seven unindexed object tables. |

`NewQuotaRepository(db).GetAll(ctx)` / `QuotaGetAll` returns one `Quota` row per
project with the stored limits for load balancers, listeners, pools, health
monitors, members, L7 policies and L7 rules, plus Octavia's cached `in_use_*`
counters. Each value is a `sql.NullInt32`. A NULL limit means no explicit
override, and zero and -1 remain distinct values; the caller resolves configured
defaults. The `in_use_*` counters are what Octavia's `check_quota_met` and
`decrement_quota` enforce against. A NULL or zero counter means Octavia will
recount on its next quota check for that project.

`QuotaRepository.GetUsage` / `QuotaUsageGetAll` rebuilds project counts for all
seven quota resources independently, using the same predicate Octavia uses when
it recounts: the object's own `project_id` and `provisioning_status != 'DELETED'`.
Counts include ERROR and pending statuses. Each object uses its own project and
status, including children of deleted parents or parents owned by another project,
and there are no parent joins to multiply counts. Results contain only nonzero
project/resource groups, including projects without quota rows, with int64 usage.

The two reads answer different questions. `in_use_*` is what Octavia enforces
today, and `GetUsage` is what those counters should be. Compare them to detect
counter drift, which persists until Octavia reconciles it. Octavia defines no
index on `project_id` or `provisioning_status`, so `GetUsage` scans all seven
object tables. `GetAll` reads only the `quotas` table and is cheap enough for
every scrape. Run `GetUsage` as a less frequent drift check on large deployments.

Both reads exclude NULL and empty project IDs. Octavia rejects empty project IDs
(`MissingProjectID`), so such rows can never hold quota. The schema fixtures
contain only fields needed for these tests, not a complete OpenStack migration.
The MariaDB integration test is `TestOctaviaQuotas` in `tests/` and requires Docker.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repository objects. Placement queries live under `placement/objects`.
| `magnum/db` | `GetClusterList` |
| `manila/db` | `ShareGetAllWithInstances` |
| `neutron/db` | `GetAgents`, `GetHARouterAgentPortBindingsWithAgents`, `GetRouters` |
| `octavia/db/repositories` | `PoolRepository`, `LoadBalancerRepository`, `AmphoraRepository` |
| `octavia/db/repositories` | `PoolRepository`, `LoadBalancerRepository`, `AmphoraRepository`, `QuotaRepository` |
| `placement/objects` | Resource provider inventory and allocation projections |

## Example
Expand Down
56 changes: 56 additions & 0 deletions octavia/db/repositories/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions octavia/db/repositories/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,73 @@ FROM
amphora
WHERE
status != 'DELETED';

-- name: QuotaGetAll :many
-- Per-project Octavia quota limits and the cached in_use_* counters that
-- Octavia's check_quota_met and decrement_quota enforce against. NULL limit
-- means no explicit override; a NULL or 0 counter is recounted by Octavia on
-- the next quota check. Octavia rejects empty project IDs (MissingProjectID),
-- so empty-string rows are excluded, matching QuotaUsageGetAll.
SELECT
project_id,
health_monitor,
listener,
load_balancer,
member,
pool,
l7policy,
l7rule,
in_use_health_monitor,
in_use_listener,
in_use_load_balancer,
in_use_member,
in_use_pool,
in_use_l7policy,
in_use_l7rule
FROM
quotas
WHERE
project_id != ''
ORDER BY
project_id;

-- name: QuotaUsageGetAll :many
-- Rebuild counts using Octavia check_quota_met's project/status predicate.
-- Each table is counted independently: no parent join can multiply rows.
-- Upstream defines no index on project_id or provisioning_status, so this
-- scans all seven tables; compare against QuotaGetAll's in_use_* counters to
-- detect drift rather than calling it on every scrape.
SELECT project_id, 'load_balancer' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM load_balancer
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id
UNION ALL
SELECT project_id, 'listener' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM listener
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id
UNION ALL
SELECT project_id, 'pool' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM pool
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id
UNION ALL
SELECT project_id, 'member' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM member
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id
UNION ALL
SELECT project_id, 'health_monitor' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM health_monitor
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id
UNION ALL
SELECT project_id, 'l7policy' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM l7policy
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id
UNION ALL
SELECT project_id, 'l7rule' AS resource, CAST(COUNT(*) AS SIGNED) AS in_use
FROM l7rule
WHERE provisioning_status != 'DELETED' AND project_id IS NOT NULL AND project_id != ''
GROUP BY project_id;
140 changes: 140 additions & 0 deletions octavia/db/repositories/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading