Skip to content

Commit

Permalink
Merge branch 'master' into cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Apr 3, 2024
2 parents d7f5833 + 796d843 commit 6135c93
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 19 deletions.
36 changes: 30 additions & 6 deletions roles/confd/templates/haproxy.tmpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ listen replicas
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -91,7 +95,11 @@ listen replicas_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -107,7 +115,11 @@ listen replicas_sync
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /sync{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /sync
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -129,7 +141,11 @@ listen replicas_sync_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /sync{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /sync
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -145,7 +161,11 @@ listen replicas_async
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -167,7 +187,11 @@ listen replicas_async_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand Down
36 changes: 30 additions & 6 deletions roles/haproxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ listen replicas
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -96,7 +100,11 @@ listen replicas_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -113,7 +121,11 @@ listen replicas_sync
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /sync{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /sync
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -137,7 +149,11 @@ listen replicas_sync_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /sync{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /sync
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -154,7 +170,11 @@ listen replicas_async
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand All @@ -178,7 +198,11 @@ listen replicas_async_direct
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %}
{% if balancer_tags | default('') | length > 0 %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') }}
{% else %}
option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}
{% endif %}
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
Expand Down
27 changes: 20 additions & 7 deletions roles/patroni/templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,33 @@ bootstrap:
{% for parameter in postgresql_parameters %}
{{ parameter.option }}: {{ parameter.value }}
{% endfor %}
{% if patroni_standby_cluster.host is defined and patroni_standby_cluster.host | length > 0 %}
{% if patroni_standby_cluster.host is defined and patroni_standby_cluster.host | length > 0 %}
standby_cluster:
host: {{ patroni_standby_cluster.host }}
port: {{ patroni_standby_cluster.port }}
{% if patroni_standby_cluster.primary_slot_name is defined and patroni_standby_cluster.primary_slot_name | length > 0 %}
{% if patroni_standby_cluster.primary_slot_name is defined and patroni_standby_cluster.primary_slot_name | length > 0 %}
primary_slot_name: {{ patroni_standby_cluster.primary_slot_name }}
{% endif %}
{% if patroni_standby_cluster.restore_command is defined and patroni_standby_cluster.restore_command | length > 0 %}
{% endif %}
{% if patroni_standby_cluster.restore_command is defined and patroni_standby_cluster.restore_command | length > 0 %}
restore_command: {{ patroni_standby_cluster.restore_command }}
{% endif %}
{% if patroni_standby_cluster.recovery_min_apply_delay is defined and patroni_standby_cluster.recovery_min_apply_delay | length > 0 %}
{% endif %}
{% if patroni_standby_cluster.recovery_min_apply_delay is defined and patroni_standby_cluster.recovery_min_apply_delay | length > 0 %}
recovery_min_apply_delay: {{ patroni_standby_cluster.recovery_min_apply_delay }}
{% endif %}
{% endif %}
{% if patroni_slots is defined and patroni_slots | length > 0 %}
slots:
{% for slot in patroni_slots %}
{{ slot.slot }}:
type: {{ slot.type }}
{% if slot.plugin | default('') | length > 0 %}
plugin: {{ slot.plugin }}
{% endif %}
{% if slot.database | default('') | length > 0 %}
database: {{ slot.database }}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}

initdb: # List options to be passed on to initdb
- encoding: {{ postgresql_encoding }}
Expand Down
13 changes: 13 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ patroni_standby_cluster:
# restore_command: "" # command to restore WAL records from the remote master to standby leader (optional)
# recovery_min_apply_delay: "" # how long to wait before actually apply WAL records on a standby leader (optional)

# Permanent replication slots.
# These slots will be preserved during switchover/failover.
# https://patroni.readthedocs.io/en/latest/dynamic_configuration.html
patroni_slots: []
# - slot: "logical_replication_slot" # the name of the permanent replication slot.
# type: "logical" # the type of slot. Could be 'physical' or 'logical' (if the slot is logical, you have to define 'database' and 'plugin').
# plugin: "pgoutput" # the plugin name for the logical slot.
# database: "postgres" # the database name where logical slots should be created.
# - slot: "test_logical_replication_slot"
# type: "logical"
# plugin: "pgoutput"
# database: "test"

patroni_log_destination: stderr # or 'logfile'
# if patroni_log_destination: logfile
patroni_log_dir: /var/log/patroni
Expand Down

0 comments on commit 6135c93

Please sign in to comment.