Skip to content

Commit

Permalink
#21 allow tunable superuser for pgstatsmon setup routines
Browse files Browse the repository at this point in the history
  • Loading branch information
KodyKantor authored and trentm committed Sep 18, 2018
1 parent c3c085e commit 2cf07d4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $ cat etc/myconfig.json
},
"backend_port": 5432,
"user": "pgstatsmon",
"superuser": "postgres",
"database": "moray",
"static": {
"dbs": [{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions etc/static.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"connect_retries": 3
},
"user": "pgstatsmon",
"superuser": "postgres",
"database": "moray",
"backend_port": 5432,
"static": {
Expand Down
1 change: 1 addition & 0 deletions etc/vmapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"connect_retries": 3
},
"user": "pgstatsmon",
"superuser": "postgres",
"database": "moray",
"backend_port": 5432,
"vmapi": {
Expand Down
5 changes: 3 additions & 2 deletions lib/dbinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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');
Expand Down
8 changes: 6 additions & 2 deletions lib/pgstatsmon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test/etc/testconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"max_connections": 10
},
"user": "pgstatsmon",
"superuser": "postgres",
"database": "pgstatsmon",
"backend_port": 5432,
"static": {
Expand Down

0 comments on commit 2cf07d4

Please sign in to comment.