From 2cf07d410ab75bbb32a3111a37faf3f3d8f1e8bf Mon Sep 17 00:00:00 2001 From: Kody Kantor Date: Tue, 18 Sep 2018 11:19:50 +0000 Subject: [PATCH] joyent/pgstatsmon#21 allow tunable superuser for pgstatsmon setup routines --- CHANGES.md | 5 ++++- README.md | 3 +++ docs/overview.md | 3 ++- etc/static.json | 1 + etc/vmapi.json | 1 + lib/dbinit.js | 5 +++-- lib/pgstatsmon.js | 8 ++++++-- test/etc/testconfig.json | 1 + 8 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2ef4314..5ae9bc2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,10 @@ # pgstatsmon Changelog ## Not yet released -None +none + +## 1.2.0 +* #21 allow tunable superuser for pgstatsmon setup routines ## 1.1.0 * #18 pgstatsmon shouldn't try to create functions that depend on missing functions diff --git a/README.md b/README.md index aacc88d..1eb4d12 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ $ cat etc/myconfig.json }, "backend_port": 5432, "user": "pgstatsmon", + "superuser": "postgres", "database": "moray", "static": { "dbs": [{ @@ -105,6 +106,7 @@ $ cat etc/vmapiconfig.json }, "backend_port": 5432, "user": "pgstatsmon", + "superuser": "postgres", "database": "moray", "vmapi": { "url": "http://vmapi.coal-1.example.com", @@ -167,6 +169,7 @@ to run the tests, your configuration file may look like this: "max_connections": 10 }, "user": "pgstatsmon", + "superuser": "postgres", "database": "pgstatsmon", "backend_port": 5432, "static": { diff --git a/docs/overview.md b/docs/overview.md index 34d04da..61c46cf 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -89,7 +89,8 @@ pgstatsmon also logs each metric that is observed. These are available at the When pgstatsmon first encounters a new backend it attempts to do a few things. -- Connects to the database as the 'postgres' user +- Connects to the database as a superuser. The superuser's login name can be + specified in the config file. The default superuser is 'postgres'. - Check if the database is a synchronous or asynchronous peer. If it is, pgstatsmon doesn't perform the rest of these steps - Collects the database server version number diff --git a/etc/static.json b/etc/static.json index 3fb0397..98408ad 100644 --- a/etc/static.json +++ b/etc/static.json @@ -6,6 +6,7 @@ "connect_retries": 3 }, "user": "pgstatsmon", + "superuser": "postgres", "database": "moray", "backend_port": 5432, "static": { diff --git a/etc/vmapi.json b/etc/vmapi.json index 16dee4b..7938424 100644 --- a/etc/vmapi.json +++ b/etc/vmapi.json @@ -6,6 +6,7 @@ "connect_retries": 3 }, "user": "pgstatsmon", + "superuser": "postgres", "database": "moray", "backend_port": 5432, "vmapi": { diff --git a/lib/dbinit.js b/lib/dbinit.js index 6977b1f..a8d0727 100644 --- a/lib/dbinit.js +++ b/lib/dbinit.js @@ -27,7 +27,7 @@ var PostgresInRecoveryError = 'PostgresInRecoveryError'; * doing. * * To accomplish this, this file: - * - Connects to Postgres as the 'postgres' superuser + * - Connects to Postgres as the postgres superuser ('postgres' by default) * - Creates a 'pgstatsmon' role with limited privileges * - Creates a function in the given database ('moray' for Triton/Manta) to * access unfiltered pg_stat_activity information @@ -44,7 +44,7 @@ var PostgresInRecoveryError = 'PostgresInRecoveryError'; */ function connect_to_database(args, callback) { var client; - var superuser = 'postgres'; + var superuser = args.conf.superuser; var query_timeout = args.conf.query_timeout; var connect_timeout = args.conf.connect_timeout; @@ -283,6 +283,7 @@ function setup_monitoring_user(args, callback) { mod_assert.object(args, 'args'); mod_assert.object(args.log, 'args.log'); mod_assert.string(args.user, 'args.user'); + mod_assert.string(args.superuser, 'args.superuser'); mod_assert.number(args.port, 'args.port'); mod_assert.string(args.hostname, 'args.hostname'); mod_assert.string(args.targetdb, 'args.targetdb'); diff --git a/lib/pgstatsmon.js b/lib/pgstatsmon.js index 95d506f..7314066 100644 --- a/lib/pgstatsmon.js +++ b/lib/pgstatsmon.js @@ -109,10 +109,12 @@ function pgstatsmon(config) mod_assertplus.string(target.route, 'config.target.route'); mod_assertplus.object(target.metadata, 'config.target.metadata'); - mod_assertplus.string(config.user, 'user'); - mod_assertplus.string(config.database, 'database'); + mod_assertplus.string(config.user, 'config.user'); + mod_assertplus.string(config.database, 'config.database'); mod_assertplus.number(config.backend_port, 'config.backend_port'); + mod_assertplus.optionalString(config.superuser, 'config.superuser'); + return (new PgMon(config)); } @@ -161,6 +163,7 @@ function PgMon(config) this.pm_log.info(this.pm_backend_list, 'static backends'); } + this.pm_superuser = config.superuser || 'postgres'; this.pm_dbuser = config.user; this.pm_database = config.database; @@ -387,6 +390,7 @@ PgMon.prototype.setup_backend = function setup_backend(pi, callback) mod_dbinit.setup_monitoring_user({ 'user': mon.pm_dbuser, + 'superuser': mon.pm_superuser, 'targetdb': mon.pm_database, 'hostname': mon.pm_pools[pi].backend.address, 'port': mon.pm_pools[pi].backend.port, diff --git a/test/etc/testconfig.json b/test/etc/testconfig.json index d1a9d21..8f87bbf 100644 --- a/test/etc/testconfig.json +++ b/test/etc/testconfig.json @@ -7,6 +7,7 @@ "max_connections": 10 }, "user": "pgstatsmon", + "superuser": "postgres", "database": "pgstatsmon", "backend_port": 5432, "static": {