From 001fe7e1aa3b8b0287640b84e0644a4c4f263c6c Mon Sep 17 00:00:00 2001 From: Pradeep Chhetri Date: Sun, 14 Aug 2022 00:52:29 +0800 Subject: [PATCH 1/2] Make prometheus port configurable --- README.md | 52 ++++++++++++++++++++------------------ docker-compose.yml | 2 +- examples/docker/pgcat.toml | 5 +++- pgcat.toml | 5 +++- src/config.rs | 6 +++++ src/main.rs | 5 +++- src/prometheus.rs | 2 -- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 1fac2b60..90cbd823 100644 --- a/README.md +++ b/README.md @@ -38,30 +38,34 @@ psql -h 127.0.0.1 -p 6432 -c 'SELECT 1' ### Config -| **Name** | **Description** | **Examples** | -|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------| -| **`general`** | | | -| `host` | The pooler will run on this host, 0.0.0.0 means accessible from everywhere. | `0.0.0.0` | -| `port` | The pooler will run on this port. | `6432` | -| `pool_size` | Maximum allowed server connections per pool. Pools are separated for each user/shard/server role. The connections are allocated as needed. | `15` | -| `pool_mode` | The pool mode to use, i.e. `session` or `transaction`. | `transaction` | -| `connect_timeout` | Maximum time to establish a connection to a server (milliseconds). If reached, the server is banned and the next target is attempted. | `5000` | -| `healthcheck_timeout` | Maximum time to pass a health check (`SELECT 1`, milliseconds). If reached, the server is banned and the next target is attempted. | `1000` | -| `shutdown_timeout` | Maximum time to give clients during shutdown before forcibly killing client connections (ms). | `60000` | -| `healthcheck_delay` | How long to keep connection available for immediate re-use, without running a healthcheck query on it | `30000` | -| `ban_time` | Ban time for a server (seconds). It won't be allowed to serve transactions until the ban expires; failover targets will be used instead. | `60` | -| | | | -| **`user`** | | | -| `name` | The user name. | `sharding_user` | -| `password` | The user password in plaintext. | `hunter2` | -| | | | -| **`shards`** | Shards are numerically numbered starting from 0; the order in the config is preserved by the pooler to route queries accordingly. | `[shards.0]` | -| `servers` | List of servers to connect to and their roles. A server is: `[host, port, role]`, where `role` is either `primary` or `replica`. | `["127.0.0.1", 5432, "primary"]` | -| `database` | The name of the database to connect to. This is the same on all servers that are part of one shard. | | -| **`query_router`** | | | -| `default_role` | Traffic is routed to this role by default (round-robin), unless the client specifies otherwise. Default is `any`, for any role available. | `any`, `primary`, `replica` | -| `query_parser_enabled` | Enable the query parser which will inspect incoming queries and route them to a primary or replicas. | `false` | -| `primary_reads_enabled` | Enable this to allow read queries on the primary; otherwise read queries are routed to the replicas. | `true` | +| **Name** | **Description** | **Examples** | +|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------| +| **`general`** | | | +| `host` | The pooler will run on this host, 0.0.0.0 means accessible from everywhere. | `0.0.0.0` | +| `port` | The pooler will run on this port. | `6432` | +| `enable_prometheus_exporter` | Enable prometheus exporter which will export metrics in prometheus exposition format. | `true` | +| `prometheus_exporter_port` | Port at which prometheus exporter listens on. | `9930` | +| `pool_size` | Maximum allowed server connections per pool. Pools are separated for each user/shard/server role. The connections are allocated as needed. | `15` | +| `pool_mode` | The pool mode to use, i.e. `session` or `transaction`. | `transaction` | +| `connect_timeout` | Maximum time to establish a connection to a server (milliseconds). If reached, the server is banned and the next target is attempted. | `5000` | +| `healthcheck_timeout` | Maximum time to pass a health check (`SELECT 1`, milliseconds). If reached, the server is banned and the next target is attempted. | `1000` | +| `shutdown_timeout` | Maximum time to give clients during shutdown before forcibly killing client connections (ms). | `60000` | +| `healthcheck_delay` | How long to keep connection available for immediate re-use, without running a healthcheck query on it | `30000` | +| `ban_time` | Ban time for a server (seconds). It won't be allowed to serve transactions until the ban expires; failover targets will be used instead. | `60` | +| `autoreload` | Enable auto-reload of config after fixed time-interval. | `false` | +| | | | +| **`user`** | | | +| `name` | The user name. | `sharding_user` | +| `password` | The user password in plaintext. | `hunter2` | +| | | | +| **`shards`** | Shards are numerically numbered starting from 0; the order in the config is preserved by the pooler to route queries accordingly. | `[shards.0]` | +| `servers` | List of servers to connect to and their roles. A server is: `[host, port, role]`, where `role` is either `primary` or `replica`. | `["127.0.0.1", 5432, "primary"]` | +| `database` | The name of the database to connect to. This is the same on all servers that are part of one shard. | | +| | | | +| **`query_router`** | | | +| `default_role` | Traffic is routed to this role by default (round-robin), unless the client specifies otherwise. Default is `any`, for any role available. | `any`, `primary`, `replica` | +| `query_parser_enabled` | Enable the query parser which will inspect incoming queries and route them to a primary or replicas. | `false` | +| `primary_reads_enabled` | Enable this to allow read queries on the primary; otherwise read queries are routed to the replicas. | `true` | ## Local development diff --git a/docker-compose.yml b/docker-compose.yml index e93d8eb9..96d1f395 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3" services: postgres: - image: postgres:13 + image: postgres:14 environment: POSTGRES_PASSWORD: postgres POSTGRES_HOST_AUTH_METHOD: md5 diff --git a/examples/docker/pgcat.toml b/examples/docker/pgcat.toml index b2ce0b64..3c74df33 100644 --- a/examples/docker/pgcat.toml +++ b/examples/docker/pgcat.toml @@ -11,9 +11,12 @@ host = "0.0.0.0" # Port to run on, same as PgBouncer used in this example. port = 6432 -# enable prometheus exporter on port 9930 +# Whether to enable prometheus exporter or not. enable_prometheus_exporter = true +# Port at which prometheus exporter listens on. +prometheus_exporter_port = 9930 + # How long to wait before aborting a server connection (ms). connect_timeout = 5000 diff --git a/pgcat.toml b/pgcat.toml index 5b046785..bc246f49 100644 --- a/pgcat.toml +++ b/pgcat.toml @@ -11,9 +11,12 @@ host = "0.0.0.0" # Port to run on, same as PgBouncer used in this example. port = 6432 -# enable prometheus exporter on port 9930 +# Whether to enable prometheus exporter or not. enable_prometheus_exporter = true +# Port at which prometheus exporter listens on. +prometheus_exporter_port = 9930 + # How long to wait before aborting a server connection (ms). connect_timeout = 5000 diff --git a/src/config.rs b/src/config.rs index 435cd9e3..57b52ae1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,6 +118,7 @@ pub struct General { pub host: String, pub port: i16, pub enable_prometheus_exporter: Option, + pub prometheus_exporter_port: i16, pub connect_timeout: u64, pub healthcheck_timeout: u64, pub shutdown_timeout: u64, @@ -136,6 +137,7 @@ impl Default for General { host: String::from("localhost"), port: 5432, enable_prometheus_exporter: Some(false), + prometheus_exporter_port: 9930, connect_timeout: 5000, healthcheck_timeout: 1000, shutdown_timeout: 60000, @@ -271,6 +273,10 @@ impl From<&Config> for std::collections::HashMap { let mut static_settings = vec![ ("host".to_string(), config.general.host.to_string()), ("port".to_string(), config.general.port.to_string()), + ( + "prometheus_exporter_port".to_string(), + config.general.prometheus_exporter_port.to_string(), + ), ( "connect_timeout".to_string(), config.general.connect_timeout.to_string(), diff --git a/src/main.rs b/src/main.rs index 7ae71fee..db934747 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,7 +99,10 @@ async fn main() { let config = get_config(); if let Some(true) = config.general.enable_prometheus_exporter { - let http_addr_str = format!("{}:{}", config.general.host, crate::prometheus::HTTP_PORT); + let http_addr_str = format!( + "{}:{}", + config.general.host, config.general.prometheus_exporter_port + ); let http_addr = match SocketAddr::from_str(&http_addr_str) { Ok(addr) => addr, Err(err) => { diff --git a/src/prometheus.rs b/src/prometheus.rs index eeaa9b15..4e3dc3aa 100644 --- a/src/prometheus.rs +++ b/src/prometheus.rs @@ -10,8 +10,6 @@ use crate::config::Address; use crate::pool::get_all_pools; use crate::stats::get_stats; -pub const HTTP_PORT: usize = 9930; - struct MetricHelpType { help: &'static str, ty: &'static str, From 4e9e7a2c82b671ebc86a4af12d700f206d53f86c Mon Sep 17 00:00:00 2001 From: Pradeep Chhetri Date: Sun, 14 Aug 2022 01:00:53 +0800 Subject: [PATCH 2/2] Update circleci config --- .circleci/pgcat.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.circleci/pgcat.toml b/.circleci/pgcat.toml index 24dfe97d..9c3babf2 100644 --- a/.circleci/pgcat.toml +++ b/.circleci/pgcat.toml @@ -11,9 +11,12 @@ host = "0.0.0.0" # Port to run on, same as PgBouncer used in this example. port = 6432 -# enable prometheus exporter on port 9930 +# Whether to enable prometheus exporter or not. enable_prometheus_exporter = true +# Port at which prometheus exporter listens on. +prometheus_exporter_port = 9930 + # How long to wait before aborting a server connection (ms). connect_timeout = 100