Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more environment variables. #846

Merged
merged 5 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/bin/pg_autoctl/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,60 @@ cli_common_keeper_getopts(int argc, char **argv,
/* default to a "primary" in citus node_role terms */
LocalOptionConfig.citusRole = CITUS_ROLE_PRIMARY;

/* add support for environment variable for some of the options */
if (env_exists(PG_AUTOCTL_NODE_NAME))
{
if (!get_env_copy(PG_AUTOCTL_NODE_NAME,
LocalOptionConfig.name,
sizeof(LocalOptionConfig.name)))
{
/* errors have already been logged */
exit(EXIT_CODE_BAD_ARGS);
}
}

if (env_exists(PG_AUTOCTL_CANDIDATE_PRIORITY))
{
char prio[BUFSIZE] = { 0 };

if (!get_env_copy(PG_AUTOCTL_CANDIDATE_PRIORITY, prio, sizeof(prio)))
{
/* errors have already been logged */
exit(EXIT_CODE_BAD_ARGS);
}

int candidatePriority = strtol(prio, NULL, 10);
if (errno == EINVAL || candidatePriority < 0 || candidatePriority > 100)
{
log_fatal("PG_AUTOCTL_CANDIDATE_PRIORITY environment variable is not valid."
" Valid values are integers from 0 to 100. ");
exit(EXIT_CODE_BAD_ARGS);
}

LocalOptionConfig.pgSetup.settings.candidatePriority = candidatePriority;
}

if (env_exists(PG_AUTOCTL_REPLICATION_QUORUM))
{
char quorum[BUFSIZE] = { 0 };

if (!get_env_copy(PG_AUTOCTL_REPLICATION_QUORUM, quorum, sizeof(quorum)))
{
/* errors have already been logged */
exit(EXIT_CODE_BAD_ARGS);
}

bool replicationQuorum = false;
if (!parse_bool(quorum, &replicationQuorum))
{
log_fatal("PG_AUTOCTL_REPLICATION_QUORUM environment variable is not valid."
" Valid values are \"true\" or \"false\".");
exit(EXIT_CODE_BAD_ARGS);
}

LocalOptionConfig.pgSetup.settings.replicationQuorum = replicationQuorum;
}

optind = 0;

while ((c = getopt_long(argc, argv,
Expand Down
5 changes: 5 additions & 0 deletions src/bin/pg_autoctl/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
/* environment variable for --monitor, when used instead of --pgdata */
#define PG_AUTOCTL_MONITOR "PG_AUTOCTL_MONITOR"

/* environment variable for --candidate-priority and --replication-quorum */
#define PG_AUTOCTL_NODE_NAME "PG_AUTOCTL_NODE_NAME"
#define PG_AUTOCTL_CANDIDATE_PRIORITY "PG_AUTOCTL_CANDIDATE_PRIORITY"
#define PG_AUTOCTL_REPLICATION_QUORUM "PG_AUTOCTL_REPLICATION_QUORUM"

/* default values for the pg_autoctl settings */
#define POSTGRES_PORT 5432
#define POSTGRES_DEFAULT_LISTEN_ADDRESSES "*"
Expand Down
13 changes: 7 additions & 6 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def test_003_init_secondary():
node1.get_synchronous_standby_names_local(),
"ANY 1 (pgautofailover_standby_2)",
)

# Prevent regression from bug fixed in PR #839
logs = node2.logs("STDERR")
match = re.search(
"Failed to connect to .*, retrying until the server is ready", logs
)
match = re.search("Failed to CHECKPOINT before restart", logs)
if match:
print("Found connection failure in logs: ", match[0])
print("Found CHECKPOINT in logs: ", match[0])
assert not match
node2.run()

Expand All @@ -95,8 +95,9 @@ def test_005_logging_of_passwords():
logs = node2.logs()
assert monitor_password not in logs
assert "password=****" in logs
# We are still logging passwords when the pguri is incomplete and when printing settings,
# so assert that it's not there in other cases:

# We are still logging passwords when the pguri is incomplete and when
# printing settings, so assert that it's not there in other cases:
assert not re.search(
"^(?!primary_conninfo|Failed to find).*%s.*$" % replication_password,
logs,
Expand Down