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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Major Features
- **Expanded OpenTelemetry sidecar metrics**: With `spec.monitoring.enabled: true`, every instance's sidecar now reports PostgreSQL uptime and shared-buffer block counters, plus replication lag and WAL receiver state on standbys (`documentdb.postgres.*`). The primary reports per-database collection, view, and index counts and storage size every 5 minutes (`documentdb.database.*`), with the database name in the `db.namespace` attribute. Every instance also reports its data volume usage and pod network I/O through the collector's `hostmetrics` receiver. The collector mounts the data volume read-only on an empty subdirectory, so it sees the volume's capacity and usage but none of its data files. Once the primary is healthy, the operator grants the `otel_monitor` role `USAGE` on the `documentdb_core`, `documentdb_api_internal`, and `documentdb_api_catalog` schemas so the metric queries can run, and it revokes the grants before removing the role when monitoring is disabled. The DocumentDB product profile enables these metrics and grants through `PostgresProfile.DocumentDBMetrics` and `PostgresProfile.MonitoringSchemas`; other products get neither unless they set them. The Prometheus exporter now keeps serving a series for 6 minutes after its last update. Because the collector configuration changes, monitored clusters perform one rolling restart after the operator upgrade. See the [Metrics Reference](docs/operator-public-documentation/v1/monitoring/metrics.md).

## [1.2.2] - 2026-11-24

Operator security-hardening release. The default DocumentDB engine stays at `1.0.1` (extension schema `1.0-0`). The operator image now uses Azure Linux distroless instead of the Alpine dev container base; the operator, sidecar and Helm chart are released together. The CRDs are unchanged from `1.2.0`; when upgrading from `1.1.x` or earlier, apply the `1.2.2` CRDs before `helm upgrade`.
Expand Down
2 changes: 2 additions & 0 deletions docs/designs/product-neutral-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ DocumentDB wrappers.
| Service name prefix, finalizer, labels | `NamingProfile` | `documentdb-service-`, `documentdb.io/...` |
| OTel metric attribute | `NamingProfile` | `documentdb.cluster` |
| OTel SQL health metric | `NamingProfile.HealthMetricName` | `documentdb.postgres.up` |
| OTel SQL instance and catalog metrics | `PostgresProfile.DocumentDBMetrics` (off when false) | enabled (`documentdb.postgres.*`, `documentdb.database.*`) |
| Monitoring role schema grants | `PostgresProfile.MonitoringSchemas` (skipped when empty) | `documentdb_core`, `documentdb_api_internal`, `documentdb_api_catalog` |
| Admission error wording | `validation.Terms` | `documentDBVersion`, `spec.documentDBImage`, ... |

## Sidecar-injector gateway contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ Track replication health using PostgreSQL system views:
kubectl exec -n documentdb my-documentdb-1 -- psql -U postgres -c "SELECT client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn FROM pg_stat_replication;"
```

With `spec.monitoring.enabled: true`, each standby's OTel Collector sidecar also reports replication lag and WAL receiver state. See [PostgreSQL instance metrics](../monitoring/metrics.md#postgresql-instance).

!!! tip "Alerting and Observability"
For production monitoring, see the [CloudNative-PG Monitoring documentation](https://cloudnative-pg.io/documentation/current/monitoring/) which covers Prometheus metrics, Grafana dashboards, and alerting rules for failover detection.

Expand Down
129 changes: 116 additions & 13 deletions docs/operator-public-documentation/v1/monitoring/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,144 @@ This page documents metrics that are part of the DocumentDB operator monitoring

## Available metrics

### PostgreSQL health
The sidecar in each DocumentDB pod collects three groups of metrics:

The sidecar runs a lightweight SQL health query against the local PostgreSQL container in each DocumentDB pod.
| Group | Source | Interval | Reported by |
|-------|--------|----------|-------------|
| [PostgreSQL instance](#postgresql-instance) | SQL queries against the local PostgreSQL server | 30 seconds | Every instance |
| [DocumentDB catalog](#documentdb-catalog) | SQL queries against the DocumentDB catalog | 5 minutes | Primary only |
| [Pod filesystem and network](#pod-filesystem-and-network) | OpenTelemetry Collector `hostmetrics` receiver | 30 seconds | Every instance |

| OpenTelemetry metric | Type | Description |
|----------------------|------|-------------|
| `documentdb.postgres.up` | Gauge | `1` when the local PostgreSQL container responds to the sidecar health query. |

Common resource attributes include:
Every metric carries these resource attributes:

| Attribute | Description |
|-----------|-------------|
| `documentdb.cluster` | DocumentDB cluster name |
| `k8s.namespace.name` | Kubernetes namespace |
| `k8s.pod.name` | Kubernetes pod name |

When exported through the Prometheus exporter, this metric is commonly queried as:
The Prometheus exporter turns attributes into labels, replaces dots with underscores, and adds unit and type suffixes to metric names. The tables below list both forms. For example:

```promql
documentdb_postgres_up{documentdb_cluster="my-cluster"}
```

## Planned DocumentDB metric groups
### PostgreSQL instance

Each instance reports these metrics for its local PostgreSQL server. Use `k8s.pod.name` to tell instances apart.

| OpenTelemetry metric | Prometheus name | Type | Unit | Description |
|----------------------|-----------------|------|------|-------------|
| `documentdb.postgres.up` | `documentdb_postgres_up` | Gauge | | `1` each time the sidecar's health query to the local PostgreSQL server succeeds. The sidecar never reports `0`. |
| `documentdb.postgres.uptime` | `documentdb_postgres_uptime_seconds` | Gauge | `s` | Time since the local PostgreSQL server started. Resets whenever PostgreSQL restarts, including restarts inside a running pod. |
| `documentdb.postgres.replication.lag` | `documentdb_postgres_replication_lag_seconds` | Gauge | `s` | Standbys only. Time since the last replayed transaction, or `0` when the standby has replayed all the WAL it received. |
| `documentdb.postgres.replication.receiver.up` | `documentdb_postgres_replication_receiver_up` | Gauge | | Standbys only. `1` while the WAL receiver process runs, otherwise `0`. |
| `documentdb.postgres.blocks.hit` | `documentdb_postgres_blocks_hit_total` | Counter | `{block}` | Blocks found in PostgreSQL shared buffers. |
| `documentdb.postgres.blocks.read` | `documentdb_postgres_blocks_read_total` | Counter | `{block}` | Blocks read from outside shared buffers, including reads that the OS page cache serves. |

- When the local PostgreSQL server does not answer, the sidecar records no PostgreSQL instance metrics. The Prometheus exporter keeps serving their last values, including `1` for `documentdb_postgres_up`, for up to 6 minutes, and then the series disappear. Detect an unresponsive server from an uptime that stops increasing or a missing `documentdb_postgres_up` series, not from `documentdb_postgres_up == 0`.
- A standby that loses its connection to the primary also reports a lag of `0` once it has replayed everything it received. Read the lag together with `documentdb.postgres.replication.receiver.up`.
- The primary does not report the replication metrics. After a standby is promoted, the Prometheus exporter keeps serving its last replication values for up to 6 minutes.
- The block counters cover the PostgreSQL database that stores DocumentDB data. Compute the shared-buffer hit ratio from their rates.

```promql
# Shared-buffer hit ratio per instance
rate(documentdb_postgres_blocks_hit_total[5m])
/ (rate(documentdb_postgres_blocks_hit_total[5m]) + rate(documentdb_postgres_blocks_read_total[5m]))

# Standbys whose WAL receiver is not running
documentdb_postgres_replication_receiver_up == 0

# Instances whose PostgreSQL has not answered the sidecar for 2 minutes, before their series expire
changes(documentdb_postgres_uptime_seconds[2m]) == 0

# Pods whose PostgreSQL series have expired or never appeared
count by (k8s_namespace_name, documentdb_cluster, k8s_pod_name) (system_network_io_bytes_total)
unless on (k8s_namespace_name, documentdb_cluster, k8s_pod_name) documentdb_postgres_up
```

### DocumentDB catalog

The primary reports these metrics; standbys report none. They describe user data only: the `admin`, `config`, and `local` databases and collections whose names start with `system.` are excluded.

| OpenTelemetry metric | Prometheus name | Type | Unit | Description |
|----------------------|-----------------|------|------|-------------|
| `documentdb.database.count` | `documentdb_database_count` | Gauge | `{database}` | Number of user databases. |
| `documentdb.database.collection.count` | `documentdb_database_collection_count` | Gauge | `{collection}` | Number of collections in the database, not counting views. |
| `documentdb.database.view.count` | `documentdb_database_view_count` | Gauge | `{view}` | Number of views in the database. |
| `documentdb.database.index.count` | `documentdb_database_index_count` | Gauge | `{index}` | Number of indexes in the database whose build has completed, including `_id` indexes. |
| `documentdb.database.storage.size` | `documentdb_database_storage_size_bytes` | Gauge | `By` | On-disk size of the database's collections, excluding indexes. Matches `storageSize` from the `dbStats` command. |

- Every catalog metric except `documentdb.database.count` has a `db.namespace` attribute (`db_namespace` in Prometheus) that holds the database name. Database names leave the cluster with your metrics, and each database adds four series.
- After a switchover or failover, the new primary reports catalog metrics at its next collection, within 5 minutes. The Prometheus exporter on the former primary keeps serving its last values for up to 6 minutes, so aggregate across pods with `max` rather than `sum`.
- With OTLP push, the backend receives one data point per series every 5 minutes. In backends with a 5 minute lookback window, such as Prometheus, query over a longer range.

```promql
# Storage size per database
max by (k8s_namespace_name, documentdb_cluster, db_namespace) (documentdb_database_storage_size_bytes)

# The same query for series ingested over OTLP
max by (k8s_namespace_name, documentdb_cluster, db_namespace) (last_over_time(documentdb_database_storage_size_bytes[10m]))
```

### Pod filesystem and network

The sidecar reads these metrics from inside its own pod with the OpenTelemetry Collector `hostmetrics` receiver. It needs no node-level collector or kubelet access. A node-level collector that runs the same receiver reports the same `system.*` names; the sidecar's series are the ones with the `documentdb.cluster` attribute.

The `system.*` names and attributes come from OpenTelemetry Collector Contrib 0.149.0, the operator's default collector version. Upstream marks these metrics as Development stability, so other collector versions can rename them or change their attributes.

#### Data volume

The operator mounts the PostgreSQL data volume into the sidecar read-only, on an empty subdirectory, at `/var/lib/otel/pgdata`. The sidecar sees the capacity and usage of the whole volume but none of its data files.

| OpenTelemetry metric | Prometheus name | Type | Unit | Description |
|----------------------|-----------------|------|------|-------------|
| `system.filesystem.usage` | `system_filesystem_usage_bytes` | UpDownCounter | `By` | Data volume space by `state`: `used`, `free`, or `reserved`. `free` is the space available to PostgreSQL, as in the `Avail` column of `df`. |
| `system.filesystem.inodes.usage` | `system_filesystem_inodes_usage` | UpDownCounter | `{inodes}` | Data volume inodes by `state`: `used` or `free`. |
| `system.filesystem.utilization` | `system_filesystem_utilization_ratio` | Gauge | `1` | Fraction of the data volume in use, from `0` to `1`, as in the `Use%` column of `df`. |

These series also carry `device`, `mode`, `mountpoint`, and `type` attributes. `mountpoint` is always `/var/lib/otel/pgdata`, and `mode` is `ro` because the sidecar's mount is read-only; PostgreSQL's own mount stays writable.

#### Network

The sidecar shares the pod's network namespace, so these metrics count all pod traffic on each non-loopback interface (the `device` attribute, such as `eth0`): client traffic to the gateway, replication between instances, and metric export. Loopback traffic between the gateway, PostgreSQL, and the sidecar is excluded.

| OpenTelemetry metric | Prometheus name | Type | Unit | Description |
|----------------------|-----------------|------|------|-------------|
| `system.network.io` | `system_network_io_bytes_total` | Counter | `By` | Bytes by `direction`: `receive` or `transmit`. |
| `system.network.packets` | `system_network_packets_total` | Counter | `{packets}` | Packets by `direction`. |
| `system.network.errors` | `system_network_errors_total` | Counter | `{errors}` | Errors by `direction`. |
| `system.network.dropped` | `system_network_dropped_total` | Counter | `{packets}` | Dropped packets by `direction`. |

Each pod reports 6 filesystem series, plus 8 network series per non-loopback interface.

```promql
# Free space on the data volume
system_filesystem_usage_bytes{documentdb_cluster="my-cluster", state="free"}

# Pod network throughput in bytes per second
rate(system_network_io_bytes_total{documentdb_cluster="my-cluster"}[5m])
```

### Monitoring role permissions

The sidecar connects to PostgreSQL as the `otel_monitor` role. Once the primary is healthy, the operator grants this role `USAGE` on the `documentdb_core`, `documentdb_api_internal`, and `documentdb_api_catalog` schemas. DocumentDB checks the first two for any query that calls a function or operator, and the catalog metrics read the third. The role has no access to the `documentdb_data` schema that stores documents.

Until the grants apply, the sidecar reports only `documentdb.postgres.up` and the filesystem and network metrics. When you disable monitoring, the operator revokes the grants before it removes the role.

## Other metric groups

The preview monitoring API is intentionally small while instrumentation lands. These areas are planned or out of scope for the current preview docs:
The inventory above covers the sidecar's SQL and hostmetrics receivers. Other telemetry sources have a separate scope:

| Area | Status |
|------|--------|
| Gateway application metrics | Planned. The sidecar can receive local OTLP from the gateway, but user-facing gateway metrics will be documented after a public gateway image emits them. |
| CNPG/PostgreSQL internals | Out of preview scope. A future revision may expose a curated subset such as replication freshness, PostgreSQL availability, WAL health, and database size. |
| Gateway application metrics | The public gateway includes [Nacelle](https://github.com/microsoft/nacelle) `server.connection.*` instrumentation. The sidecar can receive gateway OTLP, but gateway-emitted metrics are outside the inventory on this page. |
| CNPG/PostgreSQL internals | The sidecar reports the curated PostgreSQL metrics listed above. Other CloudNativePG and PostgreSQL internals, such as WAL health, are out of preview scope. |
| Operator controller metrics | Not yet exposed end-to-end through the operator Helm chart. |

## Pod and container resource metrics

Pod CPU, container memory, network I/O, filesystem usage, and node metrics are Kubernetes platform metrics. The DocumentDB operator does not install a node-level collector or grant kubelet permissions to DocumentDB pods.
The sidecar reports the data volume usage and pod network I/O listed under [Pod filesystem and network](#pod-filesystem-and-network). CPU, memory, ephemeral storage, and node metrics are Kubernetes platform metrics. The DocumentDB operator does not install a node-level collector or grant kubelet permissions to DocumentDB pods.

Use your existing platform collector, managed cloud agent, kube-prometheus-stack, or OTel Collector DaemonSet for these metrics. Filter that data to DocumentDB workloads using pod or container attributes such as:

Expand Down
10 changes: 7 additions & 3 deletions docs/operator-public-documentation/v1/monitoring/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags:

DocumentDB monitoring is built around an opt-in OpenTelemetry Collector sidecar that the operator injects into each DocumentDB pod. The sidecar collects DocumentDB-owned, pod-local metrics and can export them to an OTLP backend, expose them for Prometheus scraping, or do both.

Pod, container, and node resource metrics are Kubernetes platform metrics, not DocumentDB-specific metrics. Use your platform collector for those signals. If your cluster does not already collect them, the telemetry playground includes a reference kubeletstats DaemonSet you can deploy as an example.
The sidecar also reports data volume usage and network I/O for its own pod. CPU, memory, and ephemeral storage metrics for pods and containers, and node metrics, are Kubernetes platform metrics, not DocumentDB-specific metrics. Use your platform collector for those signals. If your cluster does not already collect them, the telemetry playground includes a reference kubeletstats DaemonSet you can deploy as an example.

## What the operator owns

Expand All @@ -22,7 +22,8 @@ The operator-owned monitoring surface is intentionally narrow:
|------|----------------|
| Sidecar injection | `spec.monitoring.enabled: true` adds one OTel Collector sidecar to each DocumentDB pod. |
| Exporter routing | `spec.monitoring.exporter` chooses OTLP push, Prometheus pull, or both. |
| DocumentDB-specific metrics | The sidecar emits pod-local metrics such as PostgreSQL health. Gateway application metrics will be documented when a public gateway image emits them. |
| DocumentDB-specific metrics | The sidecar emits pod-local metrics: PostgreSQL instance health and replication, per-database collection, index, and storage metrics, and data volume and pod network usage. See [Available metrics](metrics.md#available-metrics) and [Other metric groups](metrics.md#other-metric-groups) for the scope of gateway application metrics. |
| Monitoring role grants | The operator grants the sidecar's `otel_monitor` PostgreSQL role `USAGE` on the DocumentDB schemas that the metric queries need, and revokes the grants when you disable monitoring. The role has no access to document data. See [Monitoring role permissions](metrics.md#monitoring-role-permissions). |

The operator chart does not install a node-level collector, a Prometheus stack, Grafana, or vendor dashboards. Those are downstream platform choices.

Expand Down Expand Up @@ -129,7 +130,9 @@ spec:

## Pod and container resource metrics

CPU, memory, network, filesystem, and node metrics are collected from the Kubernetes platform, usually from kubelet, cAdvisor, a managed cloud agent, kube-prometheus-stack, or an OTel Collector DaemonSet. They are useful for operating DocumentDB, but they are not produced by the DocumentDB operator.
The sidecar reports two pod-level resource signals itself: data volume usage and pod network I/O. See [Pod filesystem and network](metrics.md#pod-filesystem-and-network).

CPU, memory, ephemeral storage, and node metrics are collected from the Kubernetes platform, usually from kubelet, cAdvisor, a managed cloud agent, kube-prometheus-stack, or an OTel Collector DaemonSet. They are useful for operating DocumentDB, but they are not produced by the DocumentDB operator.

If your platform already collects these metrics, filter to DocumentDB pods or containers in that backend. For example, Prometheus metrics produced by an OTel kubeletstats collector commonly use filters like:

Expand Down Expand Up @@ -165,6 +168,7 @@ If metrics are missing, check:
- At least one exporter is configured under `spec.monitoring.exporter`.
- The pods include an `otel-collector` container.
- The sidecar logs do not show exporter connection errors: `kubectl logs <pod> -c otel-collector -n "$NS"`.
- If the sidecar reports only `documentdb.postgres.up` and the `system.*` metrics, the monitoring role does not have its schema grants yet. The operator applies them once the primary is healthy. Check the operator logs for `Failed to grant schema usage to the OTel monitoring role`.

## Telemetry playground

Expand Down
Loading
Loading