Skip to content

Commit 52303cc

Browse files
Make prometheus port configurable (postgresml#121)
* Make prometheus port configurable * Update circleci config
1 parent be254ce commit 52303cc

File tree

8 files changed

+51
-31
lines changed

8 files changed

+51
-31
lines changed

.circleci/pgcat.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ host = "0.0.0.0"
1111
# Port to run on, same as PgBouncer used in this example.
1212
port = 6432
1313

14-
# enable prometheus exporter on port 9930
14+
# Whether to enable prometheus exporter or not.
1515
enable_prometheus_exporter = true
1616

17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
1720
# How long to wait before aborting a server connection (ms).
1821
connect_timeout = 100
1922

README.md

+28-24
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,34 @@ psql -h 127.0.0.1 -p 6432 -c 'SELECT 1'
3838

3939
### Config
4040

41-
| **Name** | **Description** | **Examples** |
42-
|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
43-
| **`general`** | | |
44-
| `host` | The pooler will run on this host, 0.0.0.0 means accessible from everywhere. | `0.0.0.0` |
45-
| `port` | The pooler will run on this port. | `6432` |
46-
| `pool_size` | Maximum allowed server connections per pool. Pools are separated for each user/shard/server role. The connections are allocated as needed. | `15` |
47-
| `pool_mode` | The pool mode to use, i.e. `session` or `transaction`. | `transaction` |
48-
| `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` |
49-
| `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` |
50-
| `shutdown_timeout` | Maximum time to give clients during shutdown before forcibly killing client connections (ms). | `60000` |
51-
| `healthcheck_delay` | How long to keep connection available for immediate re-use, without running a healthcheck query on it | `30000` |
52-
| `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` |
53-
| | | |
54-
| **`user`** | | |
55-
| `name` | The user name. | `sharding_user` |
56-
| `password` | The user password in plaintext. | `hunter2` |
57-
| | | |
58-
| **`shards`** | Shards are numerically numbered starting from 0; the order in the config is preserved by the pooler to route queries accordingly. | `[shards.0]` |
59-
| `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"]` |
60-
| `database` | The name of the database to connect to. This is the same on all servers that are part of one shard. | |
61-
| **`query_router`** | | |
62-
| `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` |
63-
| `query_parser_enabled` | Enable the query parser which will inspect incoming queries and route them to a primary or replicas. | `false` |
64-
| `primary_reads_enabled` | Enable this to allow read queries on the primary; otherwise read queries are routed to the replicas. | `true` |
41+
| **Name** | **Description** | **Examples** |
42+
|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
43+
| **`general`** | | |
44+
| `host` | The pooler will run on this host, 0.0.0.0 means accessible from everywhere. | `0.0.0.0` |
45+
| `port` | The pooler will run on this port. | `6432` |
46+
| `enable_prometheus_exporter` | Enable prometheus exporter which will export metrics in prometheus exposition format. | `true` |
47+
| `prometheus_exporter_port` | Port at which prometheus exporter listens on. | `9930` |
48+
| `pool_size` | Maximum allowed server connections per pool. Pools are separated for each user/shard/server role. The connections are allocated as needed. | `15` |
49+
| `pool_mode` | The pool mode to use, i.e. `session` or `transaction`. | `transaction` |
50+
| `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` |
51+
| `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` |
52+
| `shutdown_timeout` | Maximum time to give clients during shutdown before forcibly killing client connections (ms). | `60000` |
53+
| `healthcheck_delay` | How long to keep connection available for immediate re-use, without running a healthcheck query on it | `30000` |
54+
| `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` |
55+
| `autoreload` | Enable auto-reload of config after fixed time-interval. | `false` |
56+
| | | |
57+
| **`user`** | | |
58+
| `name` | The user name. | `sharding_user` |
59+
| `password` | The user password in plaintext. | `hunter2` |
60+
| | | |
61+
| **`shards`** | Shards are numerically numbered starting from 0; the order in the config is preserved by the pooler to route queries accordingly. | `[shards.0]` |
62+
| `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"]` |
63+
| `database` | The name of the database to connect to. This is the same on all servers that are part of one shard. | |
64+
| | | |
65+
| **`query_router`** | | |
66+
| `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` |
67+
| `query_parser_enabled` | Enable the query parser which will inspect incoming queries and route them to a primary or replicas. | `false` |
68+
| `primary_reads_enabled` | Enable this to allow read queries on the primary; otherwise read queries are routed to the replicas. | `true` |
6569

6670
## Local development
6771

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
postgres:
4-
image: postgres:13
4+
image: postgres:14
55
environment:
66
POSTGRES_PASSWORD: postgres
77
POSTGRES_HOST_AUTH_METHOD: md5

examples/docker/pgcat.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ host = "0.0.0.0"
1111
# Port to run on, same as PgBouncer used in this example.
1212
port = 6432
1313

14-
# enable prometheus exporter on port 9930
14+
# Whether to enable prometheus exporter or not.
1515
enable_prometheus_exporter = true
1616

17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
1720
# How long to wait before aborting a server connection (ms).
1821
connect_timeout = 5000
1922

pgcat.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ host = "0.0.0.0"
1111
# Port to run on, same as PgBouncer used in this example.
1212
port = 6432
1313

14-
# enable prometheus exporter on port 9930
14+
# Whether to enable prometheus exporter or not.
1515
enable_prometheus_exporter = true
1616

17+
# Port at which prometheus exporter listens on.
18+
prometheus_exporter_port = 9930
19+
1720
# How long to wait before aborting a server connection (ms).
1821
connect_timeout = 5000
1922

src/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub struct General {
118118
pub host: String,
119119
pub port: i16,
120120
pub enable_prometheus_exporter: Option<bool>,
121+
pub prometheus_exporter_port: i16,
121122
pub connect_timeout: u64,
122123
pub healthcheck_timeout: u64,
123124
pub shutdown_timeout: u64,
@@ -136,6 +137,7 @@ impl Default for General {
136137
host: String::from("localhost"),
137138
port: 5432,
138139
enable_prometheus_exporter: Some(false),
140+
prometheus_exporter_port: 9930,
139141
connect_timeout: 5000,
140142
healthcheck_timeout: 1000,
141143
shutdown_timeout: 60000,
@@ -271,6 +273,10 @@ impl From<&Config> for std::collections::HashMap<String, String> {
271273
let mut static_settings = vec![
272274
("host".to_string(), config.general.host.to_string()),
273275
("port".to_string(), config.general.port.to_string()),
276+
(
277+
"prometheus_exporter_port".to_string(),
278+
config.general.prometheus_exporter_port.to_string(),
279+
),
274280
(
275281
"connect_timeout".to_string(),
276282
config.general.connect_timeout.to_string(),

src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ async fn main() {
9999
let config = get_config();
100100

101101
if let Some(true) = config.general.enable_prometheus_exporter {
102-
let http_addr_str = format!("{}:{}", config.general.host, crate::prometheus::HTTP_PORT);
102+
let http_addr_str = format!(
103+
"{}:{}",
104+
config.general.host, config.general.prometheus_exporter_port
105+
);
103106
let http_addr = match SocketAddr::from_str(&http_addr_str) {
104107
Ok(addr) => addr,
105108
Err(err) => {

src/prometheus.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use crate::config::Address;
1010
use crate::pool::get_all_pools;
1111
use crate::stats::get_stats;
1212

13-
pub const HTTP_PORT: usize = 9930;
14-
1513
struct MetricHelpType {
1614
help: &'static str,
1715
ty: &'static str,

0 commit comments

Comments
 (0)