Skip to content

Persistence

Policy Reporter uses an internal SQLite database by default to create and manage different views and schemas of your PolicyReports. This allows the various REST APIs to work without extra infrastructure and works well for smaller setups.

If you need a shared or more scalable persistence layer, configure an external SQL database. Policy Reporter supports PostgreSQL, MySQL and MariaDB. For distributed deployments.

Configuration

yaml
database:
  # supports "postgres", "mysql", "mariadb"
  type: "postgres"
  database: "policy-reporter"
  username: "username"
  password: "password"
  host: "localhost:5432"
  enableSSL: false
  # instead of configure the individual values you can also provide an DSN string
  # example postgres: postgres://postgres:password@localhost:5432/postgres?sslmode=disable
  # example mysql: root:password@tcp(localhost:3306)/test?tls=false
  dsn: ""
  # -- Maximum number of open connections, supported for mysql and postgres
  maxOpenConnections: 25
  # -- Maximum number of idle connections, supported for mysql and postgres
  maxIdleConnections: 25
  # -- Maximum amount of time in minutes a connection may be reused, supported for mysql and postgres
  connectionMaxLifetime: 0
  # -- Maximum amount of time in minutes a connection may be idle, supported for mysql and postgres
  connectionMaxIdleTime: 0
  # -- Timeout for database operations in seconds, supported for mysql and postgres
  timeout: 10
  # -- Enables database related metrics, connection status and query histogram
  metrics: false
  # configure an existing secret as source of your values
  # supported fields: username, password, host, dsn, database
  secretRef: ""
  # use an mounted secret as source of your values, required the information in JSON format
  # supported fields: username, password, host, dsn, database
  mountedSecret: ""
  # enabled metrics to observe pool health, query latency, and write failures
  metrics: false

Secret-backed configuration

Database configuration can be populated from a Secret or mounted secret. The supported fields are username, password, host, dsn, and database.

Data Consistency

To ensure data consistency after restarts or a leader switch in an HA setup, Policy Reporter refreshes persisted report data and reprocesses all PolicyReports in your cluster when a persistent SQL database is used.

Redis is used as a cache for results, so it complements the SQL database rather than replacing it.

Metrics

OptionLabelsType
database_connectionsdatabase, systemGauge
database_max_open_connectionsdatabase, systemGauge
database_max_idle_time_closeddatabase, systemGauge
database_max_idle_closeddatabase, systemGauge
database_idle_connectionsdatabase, systemGauge
database_max_lifetime_closeddatabase, systemGauge
database_in_usedatabase, systemGauge
database_wait_countdatabase, systemGauge
database_wait_durationdatabase, systemGauge
database_query_timingdatabase, system, operation, tableHistogram
policy_reporter_database_errors_totaloperation, reason, tableCounter