Skip to content

feat: M3 DigitalOcean driver and request budgets - #82

Merged
somethingwithproof merged 6 commits into
mainfrom
feat/m3-digitalocean
Nov 15, 2026
Merged

somethingwithproof merged 6 commits into
mainfrom
feat/m3-digitalocean

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Milestone 3, first part: the DigitalOcean driver, request budgets, and the decision on how resources appear in Cacti. The Cacti objects (#42 to #45) and the cost preview (#41), which belongs on their graph screens, follow in separate PRs.

Closes #40
Closes #10
Refs #39
Refs #3

DigitalOcean driver (#39)

  • Bearer token. Droplets and load balancers are listed 100 a page. The driver counts pages itself instead of following links.pages.next, so no URL from a response is ever requested. A list longer than 1,000 pages fails instead of retiring the resources it didn't reach.
  • Metrics: one GET each under /v2/monitoring/metrics. CPU percent busy comes from the two newest per-mode samples, read as cumulative seconds as the API example suggests. Bandwidth is converted from Mbit/s to bit/s. Load balancer metrics with several series are reported as malformed, because their label sets are undocumented.
  • The operation list allows only GET under /v2/droplets, /v2/load_balancers and /v2/monitoring/metrics (REQ-DO-006). Every URL is built from the fixed host, a catalog path, and a stored ID that has to match its type's pattern.
  • 401 means the credential was rejected, 403 a missing scope, 429 throttling, and 5xx a transient failure. A credential, scope or rate failure stops the run.
  • Verify reads each scope it needs. It checks the monitoring scope against the first Droplet.
  • CLOUD_OFFLINE=1 makes every driver refuse all provider requests. CI sets it in the jobs that drive the real pages and collector.

Still open for #39: live graphs and the facts only a live account can settle (sample spacing, whether CPU values really are cumulative, 403 behaviour, load balancer labels), all tracked on #16. REQ-DO-004's "graphs not offered" part needs the graph screens.

Request budgets and throttling (#40)

  • Each run may use the account's share of the hourly limit, spread over its interval, and never more than its share of the per-minute limit. Discovery requests count against it, and a monthly cost ceiling can cut it further. Series are read in stored order, and the rest are marked budget.
  • 500 Droplets at the default 50 percent share and five-minute interval read 119 of 2,500 series per run. That is at most 125 requests a run and 1,625 an hour, against a share of 125 a minute and 2,500 an hour.
  • A 429's Retry-After (seconds or a date, at most an hour) sets the new plugin_cloud_health.retry_at. The collector skips the account until then, and the health page shows the wait. The driver also stops when ratelimit-remaining reaches the part of the limit left for the token's other users.
  • Schema version 2 adds retry_at. Keeping tables on uninstall now also untracks columns that migrations added, because core drops tracked columns.

How resources appear in Cacti (#10)

ADR 0010: one device per account and scope, with a script server data query per resource type whose indexes are provider resource IDs. The plugin owner decided it so the Cacti objects can be built; the upstream proposal (#15) is not being pursued for now.

Style

After the rebase onto #83, the new lines over 120 characters are wrapped, and the DigitalOcean metric catalog is one row per metric. A token comparison shows no other change, and metric(), defaults() and paths() return the same results for every metric. SonarQube Cloud reports no open issues on this PR.

Testing

  • The fixtures are DigitalOcean's example responses from its OpenAPI spec (Apache 2.0, annotated in REUSE.toml). Paging, errors and odd bodies are built from them in the tests. None were recorded from a live account.
  • Mutation checks: breaking the CPU formula, the stored-ID check, the per-minute cap or the share threshold each fails a test.
  • Integration covers budget order and status, Retry-After skipping, and a version 1 database upgrading and keeping retry_at through a kept-tables uninstall.
  • Local runs on PHP 8.2 against Cacti 1.2.31 and 1.2.x: 235 unit tests, 15 integration tests, and 21 HTTP permission checks, all passing. PHPStan level 9 and REUSE are clean.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0be75f83-4c86-4f1f-b9f5-56aa6b2c9ebf
Commits

Reviewing files that changed from the base of the PR and between d53d9ad and 01f56e8.

Files selected for processing: 30

  • .github/workflows/plugin-ci-workflow.yml
  • LICENSES/Apache-2.0.txt
  • REUSE.toml
  • docs/PLAN.md
  • docs/decisions/0010-scope-devices-with-resource-data-queries.md
  • docs/decisions/README.md
  • include/unbooted-uninstall.php
  • lib/AccountHealth.php
  • lib/CollectResult.php
  • lib/Collector.php
  • lib/DigitalOceanCatalog.php
  • lib/DigitalOceanDriver.php
  • lib/DriverError.php
  • lib/Drivers.php
  • lib/HealthPage.php
  • lib/HealthRepository.php
  • lib/RequestBudget.php
  • lib/Schema.php
  • locales/po/cacti.pot
  • tests/Integration/LifecycleTest.php
  • tests/Unit/DigitalOceanDriverTest.php
  • tests/Unit/RequestBudgetTest.php
  • tests/bin/collector-flow.php
  • tests/bin/lifecycle.php
  • tests/bin/page-permissions.php
  • tests/fixtures/digitalocean/droplet_bandwidth.json
  • tests/fixtures/digitalocean/droplet_cpu.json
  • tests/fixtures/digitalocean/droplets.json
  • tests/fixtures/digitalocean/error_401.json
  • tests/fixtures/digitalocean/load_balancers.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@gitar-bot

gitar-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Gitar is working

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

Gitar

The first provider driver. It authenticates with a bearer token, lists
Droplets and load balancers 100 a page, and reads the catalog's metrics
with one GET each under /v2/monitoring/metrics. Its operation list
allows only GET under /v2/droplets, /v2/load_balancers, and
/v2/monitoring/metrics.

- Every URL is built from the fixed host, a catalog path, and a stored
  resource id that must match its type's pattern. Paging counts pages
  instead of following links.pages.next, so no URL from a response is
  requested, and a list past 1,000 pages fails rather than retire the
  resources it did not reach.
- 401 is a rejected credential, 403 a missing scope, 429 throttling,
  and 5xx a transient failure. A credential, scope, or rate failure
  stops the collection run.
- CPU is percent busy between the two newest samples, reading the
  per-mode series as cumulative seconds as the API example suggests.
  Bandwidth is converted from megabits to bits per second. A metric
  with no data, as without the metrics agent, gives no observation.
- Load balancer label sets are undocumented, so a response with several
  series is reported as malformed rather than combined.
- The estimate counts one request per series per collection. No charge
  is documented for DigitalOcean API calls.

The driver is registered in production. CLOUD_OFFLINE=1 makes every
driver's transport refuse all requests; CI sets it, so the real pages
and collector run without reaching a provider.

Tests use DigitalOcean's example responses from its API specification
(Apache 2.0, annotated in REUSE.toml). The facts only a live account
can settle, such as sample spacing and the 403 behaviour, still wait
on #16.

Refs #39

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Before reading, the collector splits an account's series into those
that fit its request budget and those that do not (REQ-BUDGET-001,
REQ-BUDGET-002). A run may use the account's share of the provider's
hourly limit spread over its interval, and never more than its share of
the per-minute limit; discovery requests count against it, and a
monthly cost ceiling cuts it further. Series are read in their stored
order; the rest are marked unread with reason budget and the run's
collection state is budget. With DigitalOcean's 5,000 an hour and 250 a
minute at the default 50 percent share, 500 Droplets read 119 of 2,500
series in a five-minute run.

Throttling (REQ-BUDGET-003): a 429 stops the account for the run and
its Retry-After, in seconds or as a date and at most an hour, becomes
the health row's new retry_at. The collector skips the account until
then, and the health page shows the wait. The DigitalOcean driver also
stops once ratelimit-remaining is down to the part of the token's limit
left for its other users, until ratelimit-reset; discovery fails rather
than return a cut-off list.

Schema version 2 adds plugin_cloud_health.retry_at. Keeping tables on
uninstall now also untracks columns that migrations added, since core
drops tracked columns.

Refs #40

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Same treatment as the main-branch wrap: tabs, braces on the same line,
one argument or array element per line, SQL broken at whitespace. The
DigitalOcean metric catalog entries become multi-line arrays with the
same keys and values. A token comparison against the previous commit
matches for every file.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Wrapping each catalog entry into a multi-line keyed array made the
entries near-identical blocks, and SonarQube Cloud counted 190
duplicated lines (10.5% of new code against a 3% gate). Each metric
is now a positional row on one line, and metric(), defaults() and
paths() name the fields. Their results are unchanged for every metric
and resource type.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
One device per account and scope, with a script server data query per
resource type whose indexes are provider resource IDs. The plugin
owner decided it so milestone 3 can build the Cacti objects; the
upstream proposal is not being pursued for now.

Closes #10

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

Request budgets and throttling Decision: how cloud resources appear in Cacti

1 participant