Skip to content

Add Octavia quota limit and usage queries - #11

Merged
Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/octavia-quotas-2b2
Dec 4, 2026
Merged

Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/octavia-quotas-2b2

Conversation

@legit-ninja

@legit-ninja Jeremy Lee (legit-ninja) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add two read-only Octavia quota queries to octavia/db/repositories, plus a QuotaRepository that wraps them:

  • QuotaGetAll (QuotaRepository.GetAll): one row per project from the quotas table, with the stored limits for all seven quota resources and Octavia's cached in_use_* counters.
  • QuotaUsageGetAll (QuotaRepository.GetUsage): a per-project recount of load balancers, listeners, pools, members, health monitors, L7 policies and L7 rules.

Motivation

Octavia enforces quota against the cached in_use_* counters (check_quota_met, decrement_quota), and those counters can drift from the real objects. Exposing both reads lets a consumer report what Octavia enforces today and compare it with what the counters should be.

Behavior

  • QuotaGetAll returns limits and counters as sql.NullInt32. A NULL limit means no explicit override; zero and -1 remain distinct. Callers resolve configured defaults. A NULL or zero counter means Octavia recounts on its next quota check for that project.
  • QuotaUsageGetAll uses check_quota_met's predicate: the object's own project_id and provisioning_status != 'DELETED', so ERROR and pending objects count. Each table is counted independently, so no parent join multiplies or drops counts, and projects without quota rows are included. Only nonzero project/resource groups are returned.
  • Both reads exclude empty project IDs, which Octavia rejects (MissingProjectID).
  • Octavia defines no index on project_id or provisioning_status, so QuotaUsageGetAll scans all seven object tables. QuotaGetAll reads only quotas and is cheap enough for every scrape; the recount suits a less frequent drift check on large deployments.

Compatibility

The change is additive; existing Octavia repositories are unchanged. The quotas table and minimal object tables are added to the Octavia schema fixture for tests and code generation; they are not production migrations.

Tests and docs

  • Unit tests for the repository methods.
  • TestOctaviaQuotas (MariaDB integration) with a fixture covering matching and drifted counters, ERROR and pending objects, deleted parents and usage-only projects.
  • Smoke calls for both queries in TestOctaviaQueries.
  • Query semantics documented in API.md; README.md only adds QuotaRepository to the package table.

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL queries (QuotaGetAll, QuotaUsageGetAll), QuotaRepository wrapper, and sqlc generation look clean and fit right into octavia/db/repositories. Exposing both QuotaGetAll (with Octavia's cached in_use_* counters) and QuotaUsageGetAll (with clear caveats about the seven unindexed table scans) is great library design.

A few cleanup items before we run CI and merge:

  1. Rebase onto main to resolve the merge conflict in API.md (from Designate #9).
  2. Update the PR title and description to match the final code, and squash the two commits into one clean commit (keeping DCO sign-off). The title is currently the raw branch name (Contrib/octavia quotas 2b2) and the description still references commit 1's removed per-resource count methods, Python SQL tests, CI discovery, and testutil driver registration.
  3. Move the detailed Octavia quota docs from README.md into API.md: Please keep README.md to the package summary table entry (matching #13 and Designate #9) and put the detailed semantics in API.md.

Add two read-only Octavia quota queries and a QuotaRepository that wraps
them:

- QuotaGetAll (QuotaRepository.GetAll): one row per project from the
  quotas table, with the stored limits for all seven quota resources
  and Octavia's cached in_use_* counters, which check_quota_met and
  decrement_quota enforce against. Limits and counters are nullable;
  NULL, zero and -1 limits are returned as stored.
- QuotaUsageGetAll (QuotaRepository.GetUsage): recounts load balancers,
  listeners, pools, members, health monitors, L7 policies and L7 rules
  per project with check_quota_met's predicate (the object's own
  project_id and provisioning_status != 'DELETED'). Each table is
  counted independently, so no parent join can multiply or drop
  counts, and projects without quota rows are included.

Comparing the two reads shows counter drift. Octavia defines no index on
project_id or provisioning_status, so the recount scans all seven
object tables and suits a less frequent drift check rather than every
scrape. Both reads exclude empty project IDs, which Octavia rejects.

Add the quota and object tables to the Octavia schema fixture, unit
tests, a MariaDB integration test with a fixture covering matching and
drifted counters, smoke calls in TestOctaviaQueries, 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>

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates—CI is green, approving and merging.

@mnaser
Mohammed Naser (mnaser) merged commit d8357e8 into vexxhost:main Dec 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants