Skip to content
Open
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
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,133 @@ These metrics require the public [openstackdb Octavia quota APIs](https://github
That contribution is awaiting acceptance upstream; the tracked v0.2.1 dependency
does not contain these APIs. Builds and tests currently require a temporary Go
workspace selecting that public library source alongside this exporter.

## Cinder quotas

Cinder quota collection uses SELECT-only `openstackdb` repository reads. Supply
Cinder and Keystone database URLs with read-only credentials for project names
and `domain_id` labels. Without Keystone metadata, `tenant` falls back to
the project ID and `domain_id` is empty. All DB-discovered projects, including
usage-only projects, and cached Keystone projects are included.

Set `--cinder.quota-query-timeout` / `CINDER_QUOTA_QUERY_TIMEOUT` (default `5s`)
shorter than the scrape timeout. All quota SQL reads share this deadline.
`openstack_cinder_quota_up=1` indicates successful collection, not necessarily
complete coverage of every individual quota scope. Isolated malformed records
are logged and omitted as described below. Database query failures, timeouts,
and unrecoverable global errors fail closed: quota_up is 0 with no quota data.
The existing `openstack_cinder_up` inventory health gauge remains separate.
The existing resolver's Keystone refresh is separate from this SQL deadline.

Add a complete `cinder` section to `--quota.defaults-file` / `QUOTA_DEFAULTS_FILE`:

```json
{
"cinder": {
"volumes": 10,
"snapshots": 10,
"backups": 10,
"groups": 10,
"gigabytes": 1000,
"backup_gigabytes": 1000,
"per_volume_gigabytes": -1,
"use_default_quota_class": true
}
}
```

These are upstream 2025.2 configuration defaults; mirror any customized Cinder
settings (`per_volume_gigabytes` corresponds to `per_volume_size_limit`). Existing
Octavia files remain valid: absent Cinder settings select upstream defaults
with a warning. `use_default_quota_class` is optional and defaults to true.
Project overrides take precedence over the active `default` quota-class entries,
then deployment defaults. Set the switch false to mirror Cinder's corresponding
option. Type resources default independently to -1, rather than inheriting the
aggregate project limit. Request-context custom quota classes and alternative
quota drivers cannot be inferred from the database; this collector models the
standard DbQuotaDriver with no custom request-context quota class.

All quota data has `tenant,tenant_id,domain_id`; type data also has `volume_type`
(the full type name). **Compatibility:** `domain_id` is added to existing Cinder
quota/capacity metrics, preserving `tenant` and `tenant_id`; inventory labels are
unchanged. The metric families below have the `openstack_cinder_` prefix:

| Families | Measurements |
| --- | --- |
| `quota_volumes`, `quota_snapshots`, `quota_backups`, `quota_groups` | `type=limit,in_use,reserved` |
| `quota_per_volume_bytes` | `type=limit` only |
| `limits_volume_max_bytes`, `limits_volume_used_bytes`, `limits_volume_reserved_bytes` | Aggregate byte limit, in-use and reserved |
| `limits_backup_max_bytes`, `limits_backup_used_bytes`, `limits_backup_reserved_bytes` | Backup byte limit, in-use and reserved |
| `volume_type_quota_volumes`, `volume_type_quota_snapshots` | `type=limit,in_use,reserved` |
| `volume_type_quota_bytes` | Type byte limit |
| `volume_type_quota_in_use_bytes`, `volume_type_quota_reserved_bytes` | Type byte usage and reservations |

No duplicate project capacity quota families are emitted. New type measurements
cover project/type scopes observed in active overrides or accounting; only the
existing type gigabyte limit preserves its legacy project × active-type series.
For P projects, T active types and S observed project/type scopes, the maximum
series count is `19P + P*T + 8S + 1`. Active type names are resolved without
splitting underscores; deleted types are excluded. No type ID label is added,
which preserves the existing type identity label contract.

Usage and reservations are the recorded enforcement accounting, not physical
backend consumption. Aggregate bytes normally include volumes **and**
snapshots; `no_snapshot_gb_quota` changes Cinder's accounting, which the exporter
reads as maintained. Type and aggregate measurements overlap: do not add them.
Reservations are not additionally summed from reservation records or expired by
the exporter. Independent SQL reads are not an atomic quota-check transaction.

Zero limits are preserved; -1 means unlimited. The project's NULL override falls
through to defaults, as in `DbQuotaDriver.get_project_quotas`; a NULL default-class
limit cannot supply a valid inherited limit. Invalid or duplicate default-class
records omit only dependent limits; explicit valid project overrides and recorded
accounting remain available. NULL or empty default resource names are ignored.
NULL/empty volume-type names and duplicate active names omit the affected types.
No ambiguous record is selected and no invalid limit is replaced by zero or a
configuration fallback. Duplicate project/resource limits or usage omit only the
affected scope; other valid metrics remain available. Negative `in_use` and
`reserved` counters remain signed and capacity values scale to bytes. Malformed project identities and
project limits below -1 still fail collection.
Active rows use Cinder's Boolean `deleted=0`.

For alerts, use `(in_use + reserved) / limit` only for positive finite limits,
and gate on quota health; zero and unlimited limits need separate handling.
Aggregate project usage by domain once, choosing a single exporter source where
API and DB exporters expose identical capacity names. Summed project limits are
allocated project quotas, not a shared domain enforcement limit.

Semantics were checked against release-tagged Cinder 27.0.0 (2025.2):
[quota engines/defaults](https://github.com/openstack/cinder/blob/27.0.0/cinder/quota.py),
[accounting and synchronization](https://github.com/openstack/cinder/blob/27.0.0/cinder/db/sqlalchemy/api.py),
and [models](https://github.com/openstack/cinder/blob/27.0.0/cinder/db/sqlalchemy/models.py).
Model comments calling NULL unlimited conflict with the actual driver path;
the behavior above follows that path. Quota values are never repaired.


### Cinder capacity migration

This change removes six existing capacity family names without aliases or dual
emission. Update dashboards, recording rules and alerts to the following names.
All numeric capacities use bytes: source GiB × 1073741824 (2^30). Conversion
uses floating point before multiplication. Only unlimited quota **limits** retain
`-1`; signed usage, reservations and inventory values scale normally.

| Previous family | Byte family |
| --- | --- |
| `openstack_cinder_limits_volume_max_gb` | `openstack_cinder_limits_volume_max_bytes` |
| `openstack_cinder_limits_volume_used_gb` | `openstack_cinder_limits_volume_used_bytes` |
| `openstack_cinder_limits_backup_max_gb` | `openstack_cinder_limits_backup_max_bytes` |
| `openstack_cinder_limits_backup_used_gb` | `openstack_cinder_limits_backup_used_bytes` |
| `openstack_cinder_volume_type_quota_gigabytes` | `openstack_cinder_volume_type_quota_bytes` |
| `openstack_cinder_volume_gb` | `openstack_cinder_volume_bytes` |

The first five families also gain `domain_id` alongside their existing identity
labels. This changes series identity; adjust aggregations and joins accordingly.
The new capacity families `openstack_cinder_limits_volume_reserved_bytes`,
`openstack_cinder_limits_backup_reserved_bytes`,
`openstack_cinder_quota_per_volume_bytes`,
`openstack_cinder_volume_type_quota_in_use_bytes` and
`openstack_cinder_volume_type_quota_reserved_bytes` are introduced directly in
bytes. Configuration and SQL resource keys still use `gigabytes`, and the
`openstack_cinder_volume_status` **size label stays in GiB**. Volume inventory
keeps its existing labels and attachment-row behavior.
23 changes: 23 additions & 0 deletions cmd/openstack-database-exporter/cinder_startup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"github.com/stretchr/testify/require"
"io"
"log/slog"
"testing"
"time"
)

func TestCinderQuotaConfig(t *testing.T) {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
d, err := loadCinderQuotaConfig("", "missing", -time.Second, logger)
require.NoError(t, err)
require.Nil(t, d)
_, err = loadCinderQuotaConfig("mysql://enabled", "", 0, logger)
require.Error(t, err)
_, err = loadCinderQuotaConfig("mysql://enabled", "missing", time.Second, logger)
require.Error(t, err)
d, err = loadCinderQuotaConfig("mysql://enabled", "", time.Second, logger)
require.NoError(t, err)
require.NoError(t, d.Validate())
}
28 changes: 26 additions & 2 deletions cmd/openstack-database-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log/slog"
"net/http"
"os"
"time"
Expand All @@ -15,12 +16,14 @@ import (
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"

"github.com/vexxhost/openstack_database_exporter/internal/collector"
"github.com/vexxhost/openstack_database_exporter/internal/collector/cinder"
"github.com/vexxhost/openstack_database_exporter/internal/collector/octavia"
)

var (
quotaQueryTimeout = kingpin.Flag("octavia.quota-query-timeout", "Shared deadline for Octavia quota database queries; must be positive and shorter than the scrape timeout.").Default("5s").Envar("OCTAVIA_QUOTA_QUERY_TIMEOUT").Duration()
quotaDefaultsFile = kingpin.Flag("quota.defaults-file", "Optional JSON file containing all seven Octavia quota defaults; otherwise upstream unlimited defaults are assumed.").Envar("QUOTA_DEFAULTS_FILE").String()
cinderQuotaQueryTimeout = kingpin.Flag("cinder.quota-query-timeout", "Shared deadline for Cinder quota SQL reads; must be positive and shorter than the scrape timeout.").Default("5s").Envar("CINDER_QUOTA_QUERY_TIMEOUT").Duration()
quotaQueryTimeout = kingpin.Flag("octavia.quota-query-timeout", "Shared deadline for Octavia quota database queries; must be positive and shorter than the scrape timeout.").Default("5s").Envar("OCTAVIA_QUOTA_QUERY_TIMEOUT").Duration()
quotaDefaultsFile = kingpin.Flag("quota.defaults-file", "Optional JSON file containing complete quota defaults for enabled Octavia and Cinder services; otherwise each service's upstream 2025.2 defaults are assumed.").Envar("QUOTA_DEFAULTS_FILE").String()

metricsPath = kingpin.Flag(
"web.telemetry-path",
Expand Down Expand Up @@ -104,8 +107,15 @@ func main() {
if *octaviaDatabaseURL != "" && *quotaDefaultsFile == "" {
logger.Warn("No Octavia quota defaults file configured; assuming Octavia 2025.2 upstream unlimited (-1) defaults")
}
cinderDefaults, err := loadCinderQuotaConfig(*cinderDatabaseURL, *quotaDefaultsFile, *cinderQuotaQueryTimeout, logger)
if err != nil {
logger.Error("Invalid Cinder quota configuration", "error", err)
os.Exit(1)
}
reg := collector.NewRegistry(collector.Config{
CinderDatabaseURL: *cinderDatabaseURL,
CinderQuotaDefaults: cinderDefaults,
CinderQuotaQueryTimeout: *cinderQuotaQueryTimeout,
GlanceDatabaseURL: *glanceDatabaseURL,
HeatDatabaseURL: *heatDatabaseURL,
IronicDatabaseURL: *ironicDatabaseURL,
Expand Down Expand Up @@ -161,3 +171,17 @@ func loadOctaviaQuotaConfig(databaseURL, defaultsFile string, timeout time.Durat
}
return defaults, nil
}

func loadCinderQuotaConfig(databaseURL, defaultsFile string, timeout time.Duration, logger *slog.Logger) (*cinder.QuotaDefaults, error) {
if databaseURL == "" {
return nil, nil
}
if timeout <= 0 {
return nil, fmt.Errorf("cinder quota query timeout must be positive")
}
defaults, err := cinder.LoadQuotaDefaults(defaultsFile, logger)
if err != nil {
return nil, fmt.Errorf("cinder quota defaults file %q: %w", defaultsFile, err)
}
return defaults, nil
}
129 changes: 126 additions & 3 deletions cmd/openstack-database-exporter/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ func TestIntegration_E2E_FullExporter(t *testing.T) {
`INSERT INTO quota_usages (project_id, resource, in_use, reserved, deleted) VALUES
('proj-001', 'gigabytes', 250, 0, 0)`,
)
// Persisted quota accounting is independent of the inventory above.
itest.SeedSQL(t, cinderRes.DB,
`INSERT INTO volume_types (id, name, deleted) VALUES
('vtype-fast', 'fast_ssd', 0), ('vtype-deleted', 'old', 1)`,
`INSERT INTO quota_classes (class_name, resource, hard_limit, deleted) VALUES
('default', 'volumes', 22, 0), ('default', 'gigabytes', 400, 0),
('default', 'snapshots_fast_ssd', 13, 0), ('default', 'volumes', 999, 1)`,
`INSERT INTO quotas (project_id, resource, hard_limit, deleted) VALUES
('proj-001', 'volumes', NULL, 0), ('proj-001', 'snapshots', -1, 0),
('proj-001', 'backups', 0, 0), ('proj-001', 'groups', 8, 0),
('proj-001', 'backup_gigabytes', 80, 0), ('proj-001', 'per_volume_gigabytes', 12, 0),
('proj-001', 'volumes_fast_ssd', 4, 0), ('proj-001', 'snapshots_fast_ssd', NULL, 0),
('proj-001', 'gigabytes_fast_ssd', 30, 0), ('proj-001', 'volumes', 999, 1),
('cinder-idle', 'groups', NULL, 0)`,
`INSERT INTO quota_usages (project_id, resource, in_use, reserved, deleted) VALUES
('proj-001', 'volumes', 2, 1, 0), ('proj-001', 'snapshots', -1, 2, 0),
('proj-001', 'backups', 0, -1, 0), ('proj-001', 'groups', 4, 0, 0),
('proj-001', 'backup_gigabytes', 6, 2, 0),
('proj-001', 'volumes_fast_ssd', 1, 2, 0), ('proj-001', 'snapshots_fast_ssd', 3, 1, 0),
('proj-001', 'gigabytes_fast_ssd', 9, -1, 0),
('usage-only', 'backups', 7, 4, 0), ('proj-001', 'volumes', 999, 999, 1)`,
)

// Glance: images
itest.SeedSQL(t, glanceRes.DB,
Expand Down Expand Up @@ -340,11 +362,112 @@ func TestIntegration_E2E_FullExporter(t *testing.T) {
assertMetricExists(t, families, "openstack_cinder_agent_state")
assertGaugeValue(t, families, "openstack_cinder_volumes", 2)
assertGaugeValue(t, families, "openstack_cinder_snapshots", 2)
assertMetricExists(t, families, "openstack_cinder_volume_gb")
assertMetricExists(t, families, "openstack_cinder_volume_bytes")
assertMetricExists(t, families, "openstack_cinder_volume_status")
assertMetricExists(t, families, "openstack_cinder_volume_status_counter")
assertMetricExists(t, families, "openstack_cinder_limits_volume_max_gb")
assertMetricExists(t, families, "openstack_cinder_limits_volume_used_gb")
assertMetricExists(t, families, "openstack_cinder_limits_volume_max_bytes")
assertMetricExists(t, families, "openstack_cinder_limits_volume_used_bytes")
// Match complete label sets, metric types and values after DB-to-HTTP collection.
assertCinderSample := func(name string, labels map[string]string, want float64) {
t.Helper()
family := families["openstack_cinder_"+name]
if family == nil || family.GetType() != dto.MetricType_GAUGE {
t.Errorf("missing Cinder gauge %s", name)
return
}
matches := 0
for _, metric := range family.Metric {
if len(metric.Label) != len(labels) {
continue
}
match := true
for _, label := range metric.Label {
value, exists := labels[label.GetName()]
if !exists || value != label.GetValue() {
match = false
}
}
if match {
matches++
if metric.Gauge == nil || metric.GetGauge().GetValue() != want {
t.Errorf("%s %v: got %v, want %v", name, labels, metric.GetGauge(), want)
}
}
}
if matches != 1 {
t.Errorf("%s %v: got %d samples, want 1", name, labels, matches)
}
}
assertCinderSample("quota_up", nil, 1)
for _, quota := range []struct {
name string
typed, states bool
limit, inUse, reserved float64
}{
{"quota_volumes", false, true, 22, 2, 1},
{"quota_snapshots", false, true, -1, -1, 2},
{"quota_backups", false, true, 0, 0, -1},
{"quota_groups", false, true, 8, 4, 0},
{"quota_per_volume_bytes", false, true, 12 * (1 << 30), 0, 0},
{"limits_volume_max_bytes", false, false, 1000 * (1 << 30), 0, 0},
{"limits_volume_used_bytes", false, false, 250 * (1 << 30), 0, 0},
{"limits_volume_reserved_bytes", false, false, 0, 0, 0},
{"limits_backup_max_bytes", false, false, 80 * (1 << 30), 0, 0},
{"limits_backup_used_bytes", false, false, 6 * (1 << 30), 0, 0},
{"limits_backup_reserved_bytes", false, false, 2 * (1 << 30), 0, 0},
{"volume_type_quota_volumes", true, true, 4, 1, 2},
{"volume_type_quota_snapshots", true, true, 13, 3, 1},
{"volume_type_quota_bytes", true, false, 30 * (1 << 30), 0, 0},
{"volume_type_quota_in_use_bytes", true, false, 9 * (1 << 30), 0, 0},
{"volume_type_quota_reserved_bytes", true, false, -(1 << 30), 0, 0},
} {
labels := map[string]string{"tenant": "test-project-1", "tenant_id": "proj-001", "domain_id": "domain-001"}
if quota.typed {
labels["volume_type"] = "fast_ssd"
}
if quota.states {
labels["type"] = "limit"
}
assertCinderSample(quota.name, labels, quota.limit)
if quota.states && quota.name != "quota_per_volume_bytes" {
labels["type"] = "in_use"
assertCinderSample(quota.name, labels, quota.inUse)
labels["type"] = "reserved"
assertCinderSample(quota.name, labels, quota.reserved)
}
}
for _, projectID := range []string{"usage-only", "cinder-idle"} {
labels := map[string]string{"tenant": projectID, "tenant_id": projectID, "domain_id": ""}
assertCinderSample("limits_volume_max_bytes", labels, 400*(1<<30))
labels["type"] = "limit"
assertCinderSample("quota_backups", labels, 10)
labels["type"] = "in_use"
usage := float64(0)
if projectID == "usage-only" {
usage = 7
}
assertCinderSample("quota_backups", labels, usage)
}
assertCinderSample("volume_bytes", map[string]string{
"id": "vol-001", "name": "boot-vol", "status": "in-use", "availability_zone": "nova",
"bootable": "true", "tenant_id": "proj-001", "user_id": "user-001", "volume_type": "SSD", "server_id": "server-001",
}, 40*(1<<30))
assertCinderSample("volume_bytes", map[string]string{
"id": "vol-002", "name": "data-vol", "status": "available", "availability_zone": "nova",
"bootable": "false", "tenant_id": "proj-001", "user_id": "user-001", "volume_type": "SSD", "server_id": "",
}, 100*(1<<30))
assertCinderSample("volume_status", map[string]string{
"id": "vol-001", "name": "boot-vol", "status": "in-use", "bootable": "true", "tenant_id": "proj-001",
"size": "40", "volume_type": "SSD", "server_id": "server-001",
}, 5)
for _, retired := range []string{
"volume_gb", "limits_volume_max_gb", "limits_volume_used_gb", "limits_backup_max_gb",
"limits_backup_used_gb", "volume_type_quota_gigabytes",
} {
if _, exists := families["openstack_cinder_"+retired]; exists {
t.Errorf("retired Cinder metric %s remains", retired)
}
}

// Glance
assertGaugeValue(t, families, "openstack_glance_images", 2)
Expand Down
Loading
Loading