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
108 changes: 108 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,111 @@ 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.

## Manila quotas and logical share inventory

The Manila collector exports project quota gauges with `tenant`, `tenant_id`,
`domain_id` and `type` labels. The twelve families are:

- `openstack_sharev2_quota_shares`
- `openstack_sharev2_quota_bytes`
- `openstack_sharev2_quota_snapshots`
- `openstack_sharev2_quota_snapshot_bytes`
- `openstack_sharev2_quota_share_networks`
- `openstack_sharev2_quota_share_replicas`
- `openstack_sharev2_quota_replica_bytes`
- `openstack_sharev2_quota_share_groups`
- `openstack_sharev2_quota_share_group_snapshots`
- `openstack_sharev2_quota_backups`
- `openstack_sharev2_quota_backup_bytes`
- `openstack_sharev2_quota_per_share_bytes`

Six corresponding `openstack_sharev2_share_type_quota_` families use suffixes
`shares`, `bytes`, `snapshots`, `snapshot_bytes`, `share_replicas` and
`replica_bytes`. They add `share_type` (UUID) and `share_type_name` labels.
All quota families expose `type="limit"`, `type="in_use"` and `type="reserved"`,
except `quota_per_share_bytes`, which exposes only `limit`. There is no user
label. Only the limit value `-1` means unlimited; zero prohibits allocation.

Usage comes from Manila's persisted quota accounting, including signed usage
and reservations, rather than reconstructing usage from shares. Project totals
sum per-user rows with no share-type scope; share-type totals are kept separate
because they describe the same allocations. Reservations already in accounting
are not added again. These values describe provisioned quota consumption, not
physical backend consumption. The reads share a deadline but are not a single
transactional snapshot.

Limits use configured defaults, then the persisted `default` quota class, then
project overrides, then share-type overrides. Share-type limits inherit project
limits where no type override exists. User overrides discover project owners
but never replace project limits. Usage-only and override-only owners remain
visible. Configure Keystone for project names, domains and idle projects;
without metadata the owner ID becomes `tenant` and `domain_id` is empty.
Share-type scopes are discovered from limits or usage for active share types.
A SQL NULL share-type name omits that type's quota series, since the database
API also uses NULL for deleted or missing types. This includes active types
whose name is NULL. An empty but non-NULL name remains valid. This omission
does not fail quota collection or remove independent project accounting.

Use the existing `--quota.defaults-file` / `QUOTA_DEFAULTS_FILE` for effective
Manila `[quota]` settings. Source capacity settings remain in GiB:

```json
{
"manila": {
"shares": 50,
"gigabytes": 1000,
"snapshots": 50,
"snapshot_gigabytes": 1000,
"share_networks": 10,
"share_replicas": 100,
"replica_gigabytes": 1000,
"share_groups": 50,
"share_group_snapshots": 50,
"backups": 10,
"backup_gigabytes": 1000,
"per_share_gigabytes": -1
}
}
```

A supplied Manila section must contain all twelve integer values, each at least
`-1`; unknown fields, NULLs, fractions and overflow fail startup. No file, or a
file containing only another service section, uses the Manila 2025.2 defaults
above and logs a warning. Keep customized defaults synchronized with
`manila.conf`. Disabled Manila ignores its defaults and timeout validation.
`--manila.quota-query-timeout` / `MANILA_QUOTA_QUERY_TIMEOUT` sets the shared
deadline for the six quota reads (default `5s`, positive Go duration). Leave
room within the scrape timeout for inventory and project metadata collection.

`openstack_sharev2_quota_up` is an unlabeled gauge: `1` for complete quota
collection, including an empty database, and `0` on failure. Query failures or
invalid shared defaults omit quota data. Invalid project or share-type limits
omit the affected scope (and types inheriting an invalid project) while retaining
valid scopes with `quota_up=0`. Gate quota alerts on this gauge. Inventory health
remains `openstack_sharev2_up`; a quota failure can leave inventory and other
services available through HTTP 200. An initial connection failure reports both
health gauges as zero.

Inventory uses `ShareGetInventory` to emit one record per logical share,
including zero-instance shares and retained soft-deleted shares whose row is
still nondeleted. Instance status priority and active-replica preference select
one representative instance, with the replication-change/reverting exception
and instance ID tie-breaking. Status, type and availability zone come from that
same instance; missing instances leave that metadata empty. Status and count
metric names and label keys remain unchanged. The `size` label remains in GiB.

The existing inventory family `openstack_sharev2_share_gb` is renamed to
`openstack_sharev2_share_bytes`, preserving its labels. Update dashboards and
recording rules to the new name. All Manila capacity values now multiply source
GiB by `2^30`, including negative usage, reservations and inventory values;
only an unlimited quota **limit** of `-1` stays unscaled. No legacy alias is
exported.

This contribution also requires compatible public
[openstackdb Manila APIs](https://github.com/samaritanark/openstackdb/pull/3),
including the raw project/share-type quota queries and `ShareGetInventory`,
alongside the inherited Octavia APIs. The tracked v0.2.1 module lacks them.
A temporary external Go workspace is needed for pre-merge validation; verify
API compatibility of the selected library revisions before building. Library
acceptance and dependency reconciliation remain prerequisites for ordinary CI.
31 changes: 29 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/manila"
"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()
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 Manila services; otherwise upstream service defaults are assumed.").Envar("QUOTA_DEFAULTS_FILE").String()
manilaQuotaQueryTimeout = kingpin.Flag("manila.quota-query-timeout", "Shared deadline for Manila quota database queries; must be positive and shorter than the scrape timeout.").Default("5s").Envar("MANILA_QUOTA_QUERY_TIMEOUT").Duration()

metricsPath = kingpin.Flag(
"web.telemetry-path",
Expand Down Expand Up @@ -104,6 +107,14 @@ func main() {
if *octaviaDatabaseURL != "" && *quotaDefaultsFile == "" {
logger.Warn("No Octavia quota defaults file configured; assuming Octavia 2025.2 upstream unlimited (-1) defaults")
}
manilaDefaults, err := loadManilaQuotaConfig(*manilaDatabaseURL, *quotaDefaultsFile, *manilaQuotaQueryTimeout, logger)
if err != nil {
logger.Error("Invalid Manila quota configuration", "error", err)
os.Exit(1)
}
if *manilaDatabaseURL != "" && *quotaDefaultsFile == "" {
logger.Warn("No Manila quota defaults file configured; assuming Manila 2025.2 upstream defaults")
}
reg := collector.NewRegistry(collector.Config{
CinderDatabaseURL: *cinderDatabaseURL,
GlanceDatabaseURL: *glanceDatabaseURL,
Expand All @@ -112,6 +123,8 @@ func main() {
KeystoneDatabaseURL: *keystoneDatabaseURL,
MagnumDatabaseURL: *magnumDatabaseURL,
ManilaDatabaseURL: *manilaDatabaseURL,
ManilaQuotaDefaults: manilaDefaults,
ManilaQuotaQueryTimeout: *manilaQuotaQueryTimeout,
NeutronDatabaseURL: *neutronDatabaseURL,
OctaviaDatabaseURL: *octaviaDatabaseURL,
OctaviaQuotaDefaults: quotaDefaults,
Expand Down Expand Up @@ -161,3 +174,17 @@ func loadOctaviaQuotaConfig(databaseURL, defaultsFile string, timeout time.Durat
}
return defaults, nil
}

func loadManilaQuotaConfig(databaseURL, defaultsFile string, timeout time.Duration, logger *slog.Logger) (manila.QuotaDefaults, error) {
if databaseURL == "" {
return nil, nil
}
if timeout <= 0 {
return nil, fmt.Errorf("manila quota query timeout must be positive")
}
defaults, err := manila.LoadQuotaDefaults(defaultsFile, logger)
if err != nil {
return nil, fmt.Errorf("manila quota defaults file %q: %w", defaultsFile, err)
}
return defaults, nil
}
139 changes: 131 additions & 8 deletions cmd/openstack-database-exporter/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"io"
"maps"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -108,15 +109,56 @@ func TestIntegration_E2E_FullExporter(t *testing.T) {
('ng-002', 'worker-prod', 'clust-001', 'proj-001', 'worker', 5, 1)`,
)

// Manila: shares, instances
// Manila: logical shares, representative instances and persisted quota accounting.
itest.SeedSQL(t, manilaRes.DB,
`INSERT INTO availability_zones (id, name, deleted) VALUES ('az-001', 'nova', 'False')`,
`INSERT INTO share_types (id, name, deleted) VALUES ('stype-001', 'default_share_type', 'False')`,
`INSERT INTO shares (id, display_name, project_id, size, share_proto, deleted) VALUES
('share-001', 'my-share', 'proj-001', 100, 'NFS', 'False')`,
`INSERT INTO share_instances (id, share_id, status, share_type_id, availability_zone_id, deleted, cast_rules_to_readonly) VALUES
('si-001', 'share-001', 'available', 'stype-001', 'az-001', 'False', 0)`,
`INSERT INTO shares (id, display_name, project_id, size, share_proto, deleted, is_soft_deleted) VALUES
('share-001', 'my-share', 'proj-001', 100, 'NFS', 'False', 0),
('share-zero', 'no-instance', 'proj-001', 20, 'NFS', 'False', 0),
('share-retained', 'retained', 'proj-001', 5, 'NFS', 'False', 1)`,
`INSERT INTO share_instances (id, share_id, status, replica_state, share_type_id, availability_zone_id, deleted, cast_rules_to_readonly) VALUES
('si-001', 'share-001', 'available', 'active', 'stype-001', 'az-001', 'False', 0),
('si-002', 'share-001', 'error', 'in_sync', 'stype-001', 'az-001', 'False', 0),
('si-003', 'share-001', 'available', 'active', 'stype-001', 'az-001', 'False', 0)`,
`INSERT INTO project_user_quotas (project_id, user_id, resource, hard_limit, deleted) VALUES
('user-only', 'u1', 'shares', 1, 0)`,
)
manilaResources := []struct {
source, metric string
typed, capacity bool
}{
{"shares", "shares", true, false},
{"gigabytes", "bytes", true, true},
{"snapshots", "snapshots", true, false},
{"snapshot_gigabytes", "snapshot_bytes", true, true},
{"share_networks", "share_networks", false, false},
{"share_replicas", "share_replicas", true, false},
{"replica_gigabytes", "replica_bytes", true, true},
{"share_groups", "share_groups", false, false},
{"share_group_snapshots", "share_group_snapshots", false, false},
{"backups", "backups", false, false},
{"backup_gigabytes", "backup_bytes", false, true},
{"per_share_gigabytes", "per_share_bytes", false, true},
}
for i, resource := range manilaResources {
limit := 200 + i
if resource.source == "per_share_gigabytes" {
limit = 64
}
itest.SeedSQL(t, manilaRes.DB,
fmt.Sprintf(`INSERT INTO quota_classes (class_name, resource, hard_limit, deleted) VALUES ('default','%s',%d,0)`, resource.source, 100+i),
fmt.Sprintf(`INSERT INTO quotas (project_id, resource, hard_limit, deleted) VALUES ('proj-001','%s',%d,0)`, resource.source, limit),
fmt.Sprintf(`INSERT INTO quota_usages (project_id,user_id,share_type_id,resource,in_use,reserved,deleted) VALUES
('proj-001','u1',NULL,'%s',%d,2,0), ('proj-001','u2',NULL,'%s',%d,%d,0)`, resource.source, i+1, resource.source, 2*i+2, i-1),
)
if resource.typed {
itest.SeedSQL(t, manilaRes.DB,
fmt.Sprintf(`INSERT INTO project_share_type_quotas (project_id,share_type_id,resource,hard_limit,deleted) VALUES ('proj-001','stype-001','%s',%d,0)`, resource.source, 300+i),
fmt.Sprintf(`INSERT INTO quota_usages (project_id,user_id,share_type_id,resource,in_use,reserved,deleted) VALUES ('proj-001',NULL,'stype-001','%s',%d,-2,0)`, resource.source, 101+i),
)
}
}

// Neutron: agents, router bindings, routers, floating IPs, networks, subnets, ports, security groups, quotas
now := time.Now().Format("2006-01-02 15:04:05")
Expand Down Expand Up @@ -366,11 +408,61 @@ func TestIntegration_E2E_FullExporter(t *testing.T) {
assertMetricExists(t, families, "openstack_container_infra_cluster_masters")
assertMetricExists(t, families, "openstack_container_infra_cluster_nodes")

// Manila
assertGaugeValue(t, families, "openstack_sharev2_shares_counter", 1)
assertMetricExists(t, families, "openstack_sharev2_share_gb")
// Manila: every quota family, exact labels and byte units through HTTP.
assertGaugeValue(t, families, "openstack_sharev2_shares_counter", 3)
assertGaugeValue(t, families, "openstack_sharev2_quota_up", 1)
assertMetricExists(t, families, "openstack_sharev2_share_bytes")
assertMetricExists(t, families, "openstack_sharev2_share_status")
assertMetricExists(t, families, "openstack_sharev2_share_status_counter")
if _, legacy := families["openstack_sharev2_share_gb"]; legacy {
t.Error("legacy share_gb family is still exposed")
}
inventoryIDs := map[string]bool{}
var shareBytes float64
for _, metric := range families["openstack_sharev2_share_bytes"].GetMetric() {
for _, label := range metric.Label {
if label.GetName() == "id" {
if inventoryIDs[label.GetValue()] {
t.Errorf("duplicate logical share %s", label.GetValue())
}
inventoryIDs[label.GetValue()] = true
}
}
shareBytes += metric.GetGauge().GetValue()
}
if len(inventoryIDs) != 3 || shareBytes != 125*(1<<30) {
t.Errorf("logical share inventory: ids=%v bytes=%g", inventoryIDs, shareBytes)
}
for i, resource := range manilaResources {
factor := float64(1)
if resource.capacity {
factor = 1 << 30
}
limit := float64(200 + i)
if resource.source == "per_share_gigabytes" {
limit = 64
}
name := "openstack_sharev2_quota_" + resource.metric
assertManilaQuotaValue(t, families, name, "", "limit", limit*factor)
if resource.source != "per_share_gigabytes" {
assertManilaQuotaValue(t, families, name, "", "in_use", float64(3*i+3)*factor)
assertManilaQuotaValue(t, families, name, "", "reserved", float64(i+1)*factor)
} else {
for _, metric := range families[name].GetMetric() {
for _, label := range metric.Label {
if label.GetName() == "type" && label.GetValue() != "limit" {
t.Errorf("per-share capacity must emit limits only: %v", metric)
}
}
}
}
if resource.typed {
name = "openstack_sharev2_share_type_quota_" + resource.metric
assertManilaQuotaValue(t, families, name, "stype-001", "limit", float64(300+i)*factor)
assertManilaQuotaValue(t, families, name, "stype-001", "in_use", float64(101+i)*factor)
assertManilaQuotaValue(t, families, name, "stype-001", "reserved", -2*factor)
}
}

// Neutron
assertMetricExists(t, families, "openstack_neutron_agent_state")
Expand Down Expand Up @@ -831,3 +923,34 @@ func assertQuotaValue(t *testing.T, families map[string]*dto.MetricFamily, name,
t.Errorf("%s project=%s type=%s: got %d samples, want 1", name, projectID, kind, matches)
}
}

// Check Manila's complete label contract as well as its numeric byte values.
func assertManilaQuotaValue(t *testing.T, families map[string]*dto.MetricFamily, name, shareType, kind string, expected float64) {
t.Helper()
family := families[name]
if family == nil || family.GetType() != dto.MetricType_GAUGE {
t.Errorf("missing gauge family %s", name)
return
}
want := map[string]string{"tenant": "test-project-1", "tenant_id": "proj-001", "domain_id": "domain-001", "type": kind}
if shareType != "" {
want["share_type"], want["share_type_name"] = shareType, "default_share_type"
}
matches := 0
for _, metric := range family.Metric {
labels := map[string]string{}
for _, label := range metric.Label {
labels[label.GetName()] = label.GetValue()
}
if labels["tenant_id"] != "proj-001" || labels["share_type"] != shareType || labels["type"] != kind {
continue
}
matches++
if !maps.Equal(labels, want) || metric.Gauge == nil || metric.GetGauge().GetValue() != expected {
t.Errorf("%s: got labels=%v value=%v, want labels=%v value=%g", name, labels, metric.Gauge, want, expected)
}
}
if matches != 1 {
t.Errorf("%s type=%s share_type=%s: got %d samples, want 1", name, kind, shareType, matches)
}
}
Loading
Loading