pgagroal icon indicating copy to clipboard operation
pgagroal copied to clipboard

Better checks for `pgagroal.conf`

Open fluca1978 opened this issue 2 years ago • 2 comments

This happens on current HEAD 1296cc4216c73119a1ff4c3a3ffd0c610ca04f69; assume the following dumb configuration file pgagroal.conf:

$ cat /etc/pgagroal/pgagroal.conf
[pgagroal]
host = *
port = 5432
unix_socket_dir = /tmp

management=6432

log_type  = console
log_level = info
log_path  = /var/log/pgagroal/pgagroal.log
log_path  = /var/log/pgagroal/pgagroal-%Y-%m-%d-%H-%M-%S.log   
log_mode  = create

log_connections    = on
log_disconnections = on
log_rotation_size = "2M"# in megabytes
log_rotation_age = 1m# one minute
log_line_prefix  = "PGAGROAL #%Y-%m-%d-%H:%M:%S" # the prefix of the log

max_connections = 4

pipeline = 'performance'
# solo per la pipeline transaction
allow_unknown_users = false
blocking_timeout = 10000

metrics = 8000
metrics_cache_max_age = 10s
metrics_cache_max_size = 20k

#idle_timeout = 0

update_process_title = minimal


[venkman]
host = venkman
port = 5432
#primary = on


[pgagroal]
log_level = debug

[venkman]
host = miguel
port = 5432

[a]
host = venkman
port = 5432

[b]
host = venkman
port = 5432

There are a few mistakes by purpose in it:

  1. the pgagroal section has been defined twice;
  2. the venkman section has been defined twice;
  3. server a and b point to the very same endpoint.

As a result:

$ pgagroal-cli details
Status:              Running
Active connections:  0
Total connections:   0
Max connections:     4
---------------------
Server:              venkman
Host:                venkman
Port:                5432
State:               Not init
---------------------
Server:              venkman
Host:                miguel
Port:                5432
State:               Not init
---------------------
Server:              a
Host:                venkman
Port:                5432
State:               Not init
---------------------
Server:              b
Host:                venkman
Port:                5432
State:               Not init
---------------------
Database:            pgbench
Username:            pgbench
Active connections:  0
Max connections:     2
Initial connections: 1
Min connections:     1
---------------------

and the log_level last defined in the repetition of pgagroal section is applied.

I do propose to change the configuration parsing so that:

  • a section can be seen only once, this fixes 1 and 2
  • the same endpoint cannot be used multiple times with different names, this fixes 3. The rationale is that this can lead to dumb behaviours when failover is enabled.

With regard to the latter, at least produce a warning when the same endpoint is found in the configuration, so that the user can be warned properly, in particular when the failover is active.

fluca1978 avatar Aug 10 '22 06:08 fluca1978

:+1:

jesperpedersen avatar Aug 10 '22 12:08 jesperpedersen

This work drags some other refactoring, for example better error messages. I'm working on something like:

$ pgagroal -c /etc/nonexistent.conf
pgagroal: Configuration file not found </etc/nonexistent.conf>

and

$ pgagroal
Main section [pgagroal] duplicated at lines 1 and 42 of file </etc/pgagroal/pgagroal.conf>
Server section [venkman] duplicated at lines 36 and 45 of file </etc/pgagroal/pgagroal.conf>
pgagroal: 2 problematic or duplicated sections </etc/pgagroal/pgagroal.conf>

fluca1978 avatar Aug 10 '22 12:08 fluca1978