OCI Autonomous Database discovery
Configure databasesFrom.oci to discover Autonomous Databases from OCI metadata and freeform tags. The exporter lists all result pages in each configured compartment, filters by lifecycle state and required tags, selects a secure connection profile, resolves credentials, and registers ordinary database scrape targets.
This implementation covers Autonomous Database in explicit compartments in one OCI provider-selected region. In the current implementation, it does not recursively search compartments, search other regions, read defined tags, or discover Base Database and Exadata DB systems.
Discovery configuration
databasesFrom:
timeout: 30s
refreshInterval: 5m
walletRefreshInterval: 24h
walletDirectory: /tmp/exporter
oci:
# config_file (default), instance_principal, resource_principal,
# or workload_identity
auth: workload_identity
compartments:
- ocid1.compartment.oc1..example
filters:
lifecycleState: AVAILABLE
requiredTags:
oracledb-metrics-exporter-enabled: "true"
AVAILABLE and the enablement tag above are the default filters. Every required freeform tag must match exactly. Supplying a non-empty custom requiredTags map replaces the default map.
timeout bounds each startup discovery or metadata refresh, including startup wallet preparation, and must be positive. refreshInterval defaults to five minutes; 0s disables metadata polling. walletRefreshInterval defaults to 24 hours; 0s disables scheduled renewal of wallets managed by discovery. Negative intervals are invalid.
With instance_principal authentication, the exporter shares one initialization attempt across discovery and Vault requests. Each request observes its own deadline while waiting for initialization. The OCI SDK can continue retrying authentication in the background and handles later token refreshes itself.
Configuration validation does not call OCI.
Database tags
All tag keys below have the prefix oracledb-metrics-exporter-.
| Suffix | Example value | Behavior |
|---|---|---|
enabled | true | Matches the default discovery filter. |
dbname | production-orders | Overrides the exporter target name and database label; defaults to OCI dbName. |
connect-service | LOW | Selects LOW (default), MEDIUM, HIGH, TP, or TPURGENT from returned connection profiles. |
vault-id | ocid1.vault.oc1..example | Vault containing the credential and/or wallet secret. |
usernamePasswordSecret | orders-credentials | Name of a JSON credential secret in that Vault. |
wallet-secret | orders-wallet | Name of a Vault secret containing wallet ZIP bytes; requests an mTLS profile. |
is-mtls-connection-required | true | Requests mTLS. false explicitly requests walletless TLS and is rejected if OCI says mTLS is required. |
For a walletless TLS target, the usual tags are:
oracledb-metrics-exporter-enabled: true
oracledb-metrics-exporter-dbname: production-orders
oracledb-metrics-exporter-connect-service: LOW
oracledb-metrics-exporter-vault-id: ocid1.vault.oc1..example
oracledb-metrics-exporter-usernamePasswordSecret: orders-credentials
The credential secret contains:
{"username":"exporter","password":"example"}
The discovery authentication mode is also used for these special Vault references. OCI authentication authorizes control-plane operations; database username/password authentication and SQL grants remain separate requirements.
An override name is trimmed; a present but empty override skips the resource. Names do not change the database connection service or resource identity. The OCI resource OCID is retained separately. Static entries take precedence over discovered targets with the same effective name; among discovered name collisions, the first valid entry in stable OCID order wins with a warning identifying both resources. Assign distinct dbname tags to avoid collisions across compartments.
Invalid individual configurations are skipped with warnings. A successful listing with zero usable targets remains running and exposes discovery status.
Connection service and transport
The exporter selects OCI connection profiles by consumer group, TCPS protocol, and TLS authentication metadata. When multiple profiles match, it selects the lexically smallest connection string so OCI response reordering does not trigger a restart. The godror mTLS path adds the target wallet to the long OCI descriptor and enables server DN matching when the descriptor leaves it unset. Existing certificate verification settings are preserved. Legacy connection fields are not used as a fallback.
LOW is the default for monitoring. You can select any of the five groups when the database returns a compatible profile. The exporter does not switch to another service when the requested service is unavailable. See Oracle's service guidance.
OCI's actual isMtlsConnectionRequired metadata is respected. If the metadata does not require mTLS, discovery selects walletless TLS unless a tag or wallet explicitly requests mTLS. Missing compatible profiles skip the target; discovery does not switch transport modes. A tag cannot enable walletless TLS on a database that requires mTLS. A supplied wallet secret or tnsAdmin also requests a mutual profile.
An explicit url configuration tag is passed unchanged to the driver, as with a statically configured database. Configure the required transport and certificate verification settings in that connection string. An explicit connect-service takes precedence over url.
| Driver | Walletless TLS path | Automatic mTLS wallet path |
|---|---|---|
| godror | Unchanged OCI connection string | Per-target auto-login wallet selected by MY_WALLET_DIRECTORY in the OCI descriptor |
| go-oracledb | Full OCI descriptor | Supplied ewallet.pem, read directly from the per-connector wallet directory |
This table describes implemented paths validated by local configuration and driver tests. Live OCI connections still require validation for the intended deployment.
Wallet lifecycle
When mTLS is selected, discovery uses a preconfigured tnsAdmin directory if present. Otherwise it reads a wallet ZIP from wallet-secret, or calls OCI GenerateAutonomousDatabaseWallet when no wallet secret is configured.
A wallet Vault secret must contain the original ZIP bytes. The OCI secret-bundle base64 encoding is decoded once; do not add an extra application-level base64 layer.
Minimal wallet ZIP by driver
Place the files at the ZIP root, without an enclosing directory. Discovery obtains full connection descriptors from OCI, so TNS aliases are not required.
| Driver | Minimum files to include in the ZIP | Runtime configuration |
|---|---|---|
| godror | cwallet.sso | The OCI descriptor points to the mounted or extracted wallet directory. |
| go-oracledb | ewallet.pem | The connector reads the supplied PEM directly. It must contain the client private key, matching client certificate, and CA certificates. |
For a ZIP shared by both builds, include cwallet.sso and ewallet.pem. The exporter does not convert, decrypt, derive, or rewrite these credential files.
For these discovery connections, you can omit ewallet.p12, keystore.jks, truststore.jks, ojdbc.properties, README files, and tnsnames.ora. The ZIP also does not need sqlnet.ora; the exporter writes its local configuration after extraction. Keep tnsnames.ora if another application uses TNS aliases from the same wallet. For a pre-mounted godror wallet with an explicit url override, configure the wallet location in the connection string or the applicable Oracle Net configuration.
Downloaded/generated wallets are extracted into private wallet-* subdirectories of databasesFrom.walletDirectory (default /tmp/exporter). This path is independent of TMPDIR. Directories use mode 0700, files use 0600, and extraction rejects unsafe entries and oversized archives. The ZIP must contain a non-empty root cwallet.sso or ewallet.pem; the selected driver requires its own file from the table. External tnsAdmin directories configure the wallet directory; go-oracledb TNS alias lookup is not added.
PEM wallet passwords
If the supplied ewallet.pem has an encrypted private key, configure its existing wallet password using the native go-oracledb environment variable:
ORACLE_GO_WALLET_PASSWORD=<wallet-download-password>
The driver also accepts oracle.go.wallet_password, which takes precedence if both are set. The exporter reads these settings without modifying the environment. This is the wallet encryption password, not the database user's password; database credentials still come from the configured Vault secret. Unencrypted PEM files do not require a wallet password. These settings are process-wide, so encrypted PEM wallets used by one exporter process must use the same password.
When discovery calls OCI wallet generation with the go-oracledb build, this setting is required and is used as the generation password as well as by the driver to open the resulting PEM. Set it to a value that satisfies OCI's wallet password requirements. For an existing Vault wallet secret or mounted wallet, use the password that already protects its PEM. The godror build generates a random password and uses cwallet.sso, so it does not need to retain that password.
Wallets are cached for the process lifetime, so metadata polling never downloads wallets. Managed wallets are renewed through a controlled process restart after walletRefreshInterval; this is interval-based renewal, not certificate-expiry detection. Renewal first requires a successful metadata probe; if OCI listing fails, active targets stay running and renewal retries at the metadata interval (five minutes if metadata polling is disabled). Externally managed tnsAdmin directories are not renewed or deleted. Discovery-owned directories are removed after database pools close during normal shutdown/restart.
Managed wallet storage and restarts
Use a dedicated writable walletDirectory owned by this exporter instance. At startup, the exporter acquires an exclusive .wallet.lock and removes leftover wallet-* subdirectories before discovery. It keeps the lock until database pools close and wallet cleanup completes. A second exporter using the same directory fails discovery rather than deleting active wallets. Unrelated entries in the directory are preserved, and externally managed tnsAdmin directories are outside this cleanup.
On a process crash or forced container termination, the OS releases the lock. The next exporter startup cleans the abandoned wallets before downloading replacements, preventing accumulation across container restarts. The root directory and small lock file remain so ownership always uses the same lock file. Legacy metrics-exporter-wallet-* directories created by earlier versions outside this root are not swept.
For Kubernetes, the existing writable /tmp volume supports the default. You can instead mount a dedicated emptyDir at /tmp/exporter, or mount it at another path and set walletDirectory accordingly. An emptyDir survives container restarts within a Pod; the next process performs cleanup. Pod deletion removes the volume. No persistent volume or TMPDIR override is needed.
Refresh, failures, and credentials
Metadata polling compares effective targets, including resource OCIDs, names, labels, connection settings, and wallet sources. A complete successful snapshot that changes these values requests the existing graceful process restart. Shutdown drains workers and closes pools before the replacement process rediscovers and reconnects. This introduces a brief scrape interruption; it does not mutate the collector's target list in place.
An OCI listing failure during polling retains current targets and does not request removal or restart. At startup, discovery failure continues with static targets when present; without static targets, startup fails. A successful empty discovery remains running so later metadata polls can detect new targets.
If OCI listing succeeds but a managed wallet fails to prepare, the exporter skips that target and serves the usable targets and discovery status. An unchanged metadata poll keeps the process running. A metadata change that triggers a restart or the configured wallet renewal schedule retries wallet preparation.
Combined OCI credentials are read when a SQL handle is created or rebuilt. On an OCI-backed authentication failure, the exporter retires the old handle and fetches the current secret when it rebuilds the handle after metrics.connectionBackoff. Ordinary pool replacement connections use their existing connector credentials until an authentication failure or restart. The Vault request and the wait for initial instance-principal authentication use caller cancellation and a maximum 30-second deadline. The OCI SDK can outlast the caller's deadline when refreshing an expired instance-principal token.
Discovery exposes these metrics:
oracledb_exporter_discovery_successoracledb_exporter_discovery_duration_secondsoracledb_exporter_discovery_last_success_timestamp_secondsoracledb_exporter_discovery_targetsoracledb_exporter_discovery_matched_targetsoracledb_exporter_discovery_skipped_targets
Matched counts resources after lifecycle/tag filtering. Skipped counts invalid targets, duplicate names, static-name collisions, and targets with wallet preparation failures. Counts retain the last successful values during discovery failures. The target count reports accepted discovered entries in the last successful snapshot. Use normal per-database up/error metrics and logs to track SQL connections.
IAM, networking, and database prerequisites
For instance-principal authentication, example compartment-scoped policies are:
Allow dynamic-group exporter-instances to inspect autonomous-databases in compartment databases
Allow dynamic-group exporter-instances to read secret-bundles in compartment secrets
When discovery generates wallets, grant read autonomous-databases instead of only inspect in the database compartment. That verb includes wallet generation. Adjust the principal clause for the chosen authentication mode; the dynamic-group example does not apply directly to OKE workload identity. Scope policies to the actual resource compartments, including a separate secret compartment when needed. See ADB IAM permissions and Vault secret policy examples.
The exporter needs DNS and HTTPS access to OCI database/secret APIs, and network access to the returned database endpoint and port. Private endpoints require appropriate VCN routing/DNS; public endpoints require the database's access controls to admit the exporter. IAM permissions do not establish SQL connectivity.
Create a database user with CREATE SESSION, permission to initialize DBMS_APPLICATION_INFO client information, and the SELECT/EXECUTE grants required by the configured metric queries. The default metric set queries database monitoring views; a successful SELECT 1 FROM DUAL is only a connection probe, not proof of all metric privileges. See the normal exporter database setup documentation for metric grants.
Live validation
The opt-in test TestOCIDiscoveryLiveScrape exercises listing, tag conversion, Vault credentials, secure connection, session initialization, and a Prometheus metric from SELECT 1 FROM DUAL. Ordinary test runs skip it.
Prepare a dedicated test compartment/database with the tags above and a discovery YAML file with no static databases. Configure credentials for the chosen OCI auth mode and run from the repository root:
OCI_DISCOVERY_TEST_CONFIG=/absolute/path/discovery-test.yaml go test ./collector -run '^TestOCIDiscoveryLiveScrape$' -count=1 -v
OCI_DISCOVERY_TEST_CONFIG=/absolute/path/discovery-test.yaml go test -tags oracledb ./collector -run '^TestOCIDiscoveryLiveScrape$' -count=1 -v
Both walletless TLS and automatic mTLS can be exercised with the thin go-oracledb build. For mTLS targets without a wallet secret, this test calls OCI wallet generation. It does not create databases, change access controls, or rotate passwords. A test run must produce one probe metric per discovered target to pass.