Repository: zalando/patroni

Issue:
Patroni fails to convert wal_keep_segments to wal_keep_size
**Describe the bug**
With a configuration using "wal_keep_segments":"100", python treat the value as a string then the conversion just concatenates the value 16 times: https://github.com/zalando/patroni/blob/258e7e24f4c8e376908ca626b820ffced1b606da/patroni/postgresql/config.py#L837

`2021-09-06 13:31:38,413 WARNING: Value=100100100100100100100100100100100100100100100100MB of parameter=wal_keep_size is too big, decreasing to 2147483647MB`

This also silently ignores the problem by "decreasing" the value to 2147483647MB which could cause unexpected issues.

**Expected behavior**
The value converted correctly, ex. "100" -> "1600MB".

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment**
- Patroni version: 2.1.0
- PostgreSQL version: 13.4
- DCS (and its version): K8s v1.19.14

**patronictl show-config**
```
bash-4.4$ patronictl show-config
loop_wait: 10
postgresql:
  parameters:
    archive_command: /bin/true
    archive_mode: 'on'
    autovacuum_max_workers: '3'
    autovacuum_vacuum_cost_delay: '2'
    checkpoint_completion_target: '0.9'
    checkpoint_timeout: 15min
    default_statistics_target: '200'
    enable_partitionwise_aggregate: 'on'
    enable_partitionwise_join: 'on'
    jit_inline_above_cost: '-1'
    log_autovacuum_min_duration: '0'
    log_checkpoints: 'on'
    log_connections: 'on'
    log_disconnections: 'on'
    log_line_prefix: '%t [%p]: db=%d,user=%u,app=%a,client=%h '
    log_lock_waits: 'on'
    log_min_duration_statement: '1000'
    log_statement: ddl
    log_temp_files: '0'
    maintenance_work_mem: 2GB
    max_locks_per_transaction: '128'
    max_pred_locks_per_transaction: '128'
    max_prepared_transactions: '32'
    max_replication_slots: '20'
    max_wal_senders: '20'
    max_wal_size: 2GB
    min_wal_size: 1GB
    pg_stat_statements.track_utility: 'off'
    port: '5432'
    random_page_cost: '1.5'
    shared_preload_libraries: pg_stat_statements, auto_explain
    superuser_reserved_connections: '8'
    track_activity_query_size: '4096'
    track_functions: pl
    track_io_timing: 'on'
    wal_keep_segments: '100'
    wal_level: logical
    wal_log_hints: 'on'
    work_mem: 10MB
  use_pg_rewind: true
retry_timeout: 10
ttl: 30
```




Discussion:

Resolving patch:
diff --git a/patroni/postgresql/config.py b/patroni/postgresql/config.py
--- a/patroni/postgresql/config.py
+++ b/patroni/postgresql/config.py
@@ -834,7 +834,7 @@ def get_server_parameters(self, config):
         # this exercise is improving cross version compatibility and user must set the correct parameter in the config.
         if self._postgresql.major_version >= 130000:
             wal_keep_segments = parameters.pop('wal_keep_segments', self.CMDLINE_OPTIONS['wal_keep_segments'][0])
-            parameters.setdefault('wal_keep_size', str(wal_keep_segments * 16) + 'MB')
+            parameters.setdefault('wal_keep_size', str(int(wal_keep_segments) * 16) + 'MB')
         elif self._postgresql.major_version:
             wal_keep_size = parse_int(parameters.pop('wal_keep_size', self.CMDLINE_OPTIONS['wal_keep_size'][0]), 'MB')
             parameters.setdefault('wal_keep_segments', int((wal_keep_size + 8) / 16))


Test patch: