databases section defines database connections that queries can execute against. Each database is configured with a unique name as the key.
Database Structure
Dictionary of database configurations, keyed by database name
Database Fields
Database connection string or structured DSN configuration.Can be specified as:
- A connection string (e.g.,
postgresql://user:pass@host:5432/database) - A structured DSNDetails object (see below)
- An environment variable reference using
!env(e.g.,!env DATABASE_DSN)
DSNDetails Structure
When using the structured format, the following fields are available:The database dialect/driver (e.g.,
postgresql, mysql, sqlite, oracle)Database username for authentication
Database password for authentication
Database server hostname or IP address
Database server port numberConstraints:
- Must be between 1 and 65535 (inclusive)
Database name to connect to
Additional connection options passed as query parameters to the database driver.
Values can be strings or lists of strings.
Connection Pool Configuration
Connection pool configuration for the database.If not specified, defaults to a pool size of 1 with no overflow.
The size of the connection pool to maintain.Constraints:
- Must be between 1 and 100 (inclusive)
1The maximum number of connections that can be created beyond the pool size.When the pool is exhausted, this many additional connections can be created. Once these additional connections are returned to the pool, they are closed.Constraints:
- Must be between 0 and 100 (inclusive)
0Additional Fields
List of SQL statements to execute when a database connection is established.Useful for setting session-level configuration or temporary tables.Constraints:
- If specified, must contain at least 1 statement
Static labels to attach to all metrics from queries running on this database.Label names must match the pattern
^[a-zA-Z_][a-zA-Z0-9_]*$ (start with letter or underscore, followed by letters, numbers, or underscores).Constraints:- If specified, must contain at least 1 label
Complete Example
Validation Rules
- The DSN is validated using SQLAlchemy’s URL parser
- Invalid DSN formats will raise a
ValueError: Invalid DSN format - Port must be in the valid range 1-65535
- Connection pool size must be between 1-100
- Connection pool max-overflow must be between 0-100
- Label names must follow Prometheus naming conventions
- If
connect-sqlis specified, it must contain at least one statement - If
labelsis specified, it must contain at least one label