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

Fix pg-backup-api so it can handle Barman <= 3.9 #91

Merged
merged 1 commit into from
May 21, 2024
Merged

Conversation

barthisrael
Copy link
Contributor

pg-backup-api 2.1.0 doesn't work with Barman <= 3.9 because it attempts to fetch models independently of the Barman version it operates on. As Barman models were introduced through version 3.10, pg-backup-api fails with an ugly stack trace:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/lib/python3.9/site-packages/pg_backup_api/logic/utility_controller.py", line 76, in diagnose
    available_models = barman.__config__.model_names()
AttributeError: 'Config' object has no attribute 'model_names'

Through this commit we fix pg-backup-api in that sense:

  • It attempts to use models and the new signature of the exec_diagnose, which were introduced by Barman 3.10;
  • It falls back to the old signature of exec_diagnose if models are not available (Barman <= 3.9).

References: BAR-171.

@barthisrael barthisrael self-assigned this May 21, 2024
@barthisrael
Copy link
Contributor Author

I tested the patch and it seems to work:

  • pg-backup-api 2.1.0 + Barman 3.9.0:
$ curl http://127.0.0.1:7480/diagnose
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
  • patch + Barman 3.9.0:
$ curl http://127.0.0.1:7480/diagnose
{"global":{"config":{"barman_home":"/var/lib/barman","barman_user":"barman","configuration_files_directory":"/etc/barman.d","errors_list":[],"log_file":"/var/log/barman/barman.log","log_level":"INFO"},"system_info":{"barman_ver":"3.9.0","kernel_ver":"Linux pgbackupapidevhost 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux","python_ver":"Python 3.11.4","release":"Distributor ID:\tUbuntu\nDescription:\tUbuntu 22.04.1 LTS\nRelease:\t22.04\nCodename:\tjammy","rsync_ver":"rsync  version 3.2.7  protocol version 31","ssh_ver":"","timestamp":"2024-05-21T14:18:30.115250+00:00"}},"servers":{"main":{"backups":{},"config":{"active":true,"archiver":false,"archiver_batch_size":0,"autogenerate_manifest":false,"aws_profile":null,"aws_region":null,"azure_credential":null,"azure_resource_group":null,"azure_subscription_id":null,"backup_compression":null,"backup_compression_format":null,"backup_compression_level":null,"backup_compression_location":null,"backup_compression_workers":null,"backup_directory":"/var/lib/barman/main","backup_method":"postgres","backup_options":"concurrent_backup","bandwidth_limit":null,"barman_home":"/var/lib/barman","barman_lock_directory":"/var/lib/barman","basebackup_retry_sleep":30,"basebackup_retry_times":0,"basebackups_directory":"/var/lib/barman/main/base","check_timeout":30,"compression":null,"conninfo":"host=localhost user=barman dbname=postgres","create_slot":"manual","custom_compression_filter":null,"custom_compression_magic":null,"custom_decompression_filter":null,"description":"Example of PostgreSQL Database (Streaming-Only)","disabled":false,"errors_directory":"/var/lib/barman/main/errors","forward_config_path":false,"gcp_project":null,"gcp_zone":null,"immediate_checkpoint":false,"incoming_wals_directory":"/var/lib/barman/main/incoming","last_backup_maximum_age":null,"last_backup_minimum_size":null,"last_wal_maximum_age":null,"max_incoming_wals_queue":null,"minimum_redundancy":0,"msg_list":[],"name":"main","network_compression":false,"parallel_jobs":1,"parallel_jobs_start_batch_period":1,"parallel_jobs_start_batch_size":10,"path_prefix":"/usr/lib/postgresql/15/bin","post_archive_retry_script":null,"post_archive_script":null,"post_backup_retry_script":null,"post_backup_script":null,"post_delete_retry_script":null,"post_delete_script":null,"post_recovery_retry_script":null,"post_recovery_script":null,"post_wal_delete_retry_script":null,"post_wal_delete_script":null,"pre_archive_retry_script":null,"pre_archive_script":null,"pre_backup_retry_script":null,"pre_backup_script":null,"pre_delete_retry_script":null,"pre_delete_script":null,"pre_recovery_retry_script":null,"pre_recovery_script":null,"pre_wal_delete_retry_script":null,"pre_wal_delete_script":null,"primary_checkpoint_timeout":0,"primary_conninfo":null,"primary_ssh_command":null,"recovery_options":"","recovery_staging_path":null,"retention_policy":null,"retention_policy_mode":"auto","reuse_backup":null,"slot_name":"barman","snapshot_disks":null,"snapshot_gcp_project":null,"snapshot_instance":null,"snapshot_provider":null,"snapshot_zone":null,"ssh_command":null,"streaming_archiver":true,"streaming_archiver_batch_size":0,"streaming_archiver_name":"barman_receive_wal","streaming_backup_name":"barman_streaming_backup","streaming_conninfo":"host=localhost user=streaming_barman","streaming_wals_directory":"/var/lib/barman/main/streaming","tablespace_bandwidth_limit":null,"wal_retention_policy":"main","wals_directory":"/var/lib/barman/main/wals"},"status":{"archive_timeout":0,"checkpoint_timeout":300,"config_file":"/etc/postgresql/15/main/postgresql.conf","connection_error":"connection to server at \"localhost\" (127.0.0.1), port 5432 failed: fe_sendauth: no password supplied","current_lsn":"0/E066598","current_size":23565757.0,"current_xlog":"00000001000000000000000E","data_checksums":"off","data_directory":"/var/lib/postgresql/15/main","has_backup_privileges":true,"hba_file":"/etc/postgresql/15/main/pg_hba.conf","hot_standby":"on","ident_file":"/etc/postgresql/15/main/pg_ident.conf","is_in_recovery":false,"is_superuser":true,"max_replication_slots":"10","max_wal_senders":"10","pg_basebackup_bwlimit":true,"pg_basebackup_compatible":null,"pg_basebackup_installed":true,"pg_basebackup_path":"/usr/lib/postgresql/15/bin/pg_basebackup","pg_basebackup_tbls_mapping":true,"pg_basebackup_version":"15.3","pg_receivexlog_compatible":null,"pg_receivexlog_installed":true,"pg_receivexlog_path":"/usr/lib/postgresql/15/bin/pg_receivewal","pg_receivexlog_supports_slots":null,"pg_receivexlog_synchronous":null,"pg_receivexlog_version":"15.3","postgres_systemid":"7265351402956825023","replication_slot":["barman",true,"0/E000000"],"replication_slot_support":true,"server_txt_version":"15.3","streaming":null,"streaming_supported":null,"streaming_systemid":null,"synchronous_standby_names":[""],"timeline":null,"version_supported":null,"wal_compression":"off","wal_keep_size":"0","wal_level":"replica","xlog_segment_size":16777216,"xlogpos":null},"wals":{"last_archived_wal_per_timeline":{}}}}}
  • patch + Barman 3.10.0:
$ curl http://127.0.0.1:7480/diagnose
{"global":{"config":{"barman_home":"/var/lib/barman","barman_user":"barman","configuration_files_directory":"/etc/barman.d","errors_list":[],"log_file":"/var/log/barman/barman.log","log_level":"INFO"},"system_info":{"barman_ver":"3.10.0","kernel_ver":"Linux pgbackupapidevhost 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux","python_ver":"","release":"Distributor ID:\tUbuntu\nDescription:\tUbuntu 22.04.1 LTS\nRelease:\t22.04\nCodename:\tjammy","rsync_ver":"rsync  version 3.2.7  protocol version 31","ssh_ver":"","timestamp":"2024-05-21T14:40:24.473338+00:00"}},"models":{},"servers":{"main":{"active_model":null,"backups":{},"config":{"active":true,"archiver":false,"archiver_batch_size":0,"autogenerate_manifest":false,"aws_profile":null,"aws_region":null,"azure_credential":null,"azure_resource_group":null,"azure_subscription_id":null,"backup_compression":null,"backup_compression_format":null,"backup_compression_level":null,"backup_compression_location":null,"backup_compression_workers":null,"backup_directory":"/var/lib/barman/main","backup_method":"postgres","backup_options":"concurrent_backup","bandwidth_limit":null,"barman_home":"/var/lib/barman","barman_lock_directory":"/var/lib/barman","basebackup_retry_sleep":30,"basebackup_retry_times":0,"basebackups_directory":"/var/lib/barman/main/base","check_timeout":30,"cluster":"main","compression":null,"config_changes_queue":"/var/lib/barman/cfg_changes.queue","conninfo":"host=localhost user=barman dbname=postgres","create_slot":"manual","custom_compression_filter":null,"custom_compression_magic":null,"custom_decompression_filter":null,"description":"Example of PostgreSQL Database (Streaming-Only)","disabled":false,"errors_directory":"/var/lib/barman/main/errors","forward_config_path":false,"gcp_project":null,"gcp_zone":null,"immediate_checkpoint":false,"incoming_wals_directory":"/var/lib/barman/main/incoming","last_backup_maximum_age":null,"last_backup_minimum_size":null,"last_wal_maximum_age":null,"lock_directory_cleanup":true,"max_incoming_wals_queue":null,"minimum_redundancy":0,"msg_list":[],"name":"main","network_compression":false,"parallel_jobs":1,"parallel_jobs_start_batch_period":1,"parallel_jobs_start_batch_size":10,"path_prefix":"/usr/lib/postgresql/15/bin","post_archive_retry_script":null,"post_archive_script":null,"post_backup_retry_script":null,"post_backup_script":null,"post_delete_retry_script":null,"post_delete_script":null,"post_recovery_retry_script":null,"post_recovery_script":null,"post_wal_delete_retry_script":null,"post_wal_delete_script":null,"pre_archive_retry_script":null,"pre_archive_script":null,"pre_backup_retry_script":null,"pre_backup_script":null,"pre_delete_retry_script":null,"pre_delete_script":null,"pre_recovery_retry_script":null,"pre_recovery_script":null,"pre_wal_delete_retry_script":null,"pre_wal_delete_script":null,"primary_checkpoint_timeout":0,"primary_conninfo":null,"primary_ssh_command":null,"recovery_options":"","recovery_staging_path":null,"retention_policy":null,"retention_policy_mode":"auto","reuse_backup":null,"slot_name":"barman","snapshot_disks":null,"snapshot_gcp_project":null,"snapshot_instance":null,"snapshot_provider":null,"snapshot_zone":null,"ssh_command":null,"streaming_archiver":true,"streaming_archiver_batch_size":0,"streaming_archiver_name":"barman_receive_wal","streaming_backup_name":"barman_streaming_backup","streaming_conninfo":"host=localhost user=streaming_barman","streaming_wals_directory":"/var/lib/barman/main/streaming","tablespace_bandwidth_limit":null,"wal_conninfo":null,"wal_retention_policy":"main","wal_streaming_conninfo":null,"wals_directory":"/var/lib/barman/main/wals"},"status":{"archive_timeout":0,"checkpoint_timeout":300,"config_file":"/etc/postgresql/15/main/postgresql.conf","connection_error":"connection to server at \"localhost\" (127.0.0.1), port 5432 failed: fe_sendauth: no password supplied","current_lsn":"0/E066598","current_size":23565757.0,"current_xlog":"00000001000000000000000E","data_checksums":"off","data_directory":"/var/lib/postgresql/15/main","has_backup_privileges":true,"has_monitoring_privileges":true,"hba_file":"/etc/postgresql/15/main/pg_hba.conf","hot_standby":"on","ident_file":"/etc/postgresql/15/main/pg_ident.conf","is_in_recovery":false,"is_superuser":true,"max_replication_slots":"10","max_wal_senders":"10","pg_basebackup_bwlimit":true,"pg_basebackup_compatible":null,"pg_basebackup_installed":true,"pg_basebackup_path":"/usr/lib/postgresql/15/bin/pg_basebackup","pg_basebackup_tbls_mapping":true,"pg_basebackup_version":"15.3","pg_receivexlog_compatible":null,"pg_receivexlog_installed":true,"pg_receivexlog_path":"/usr/lib/postgresql/15/bin/pg_receivewal","pg_receivexlog_supports_slots":null,"pg_receivexlog_synchronous":null,"pg_receivexlog_version":"15.3","postgres_systemid":"7265351402956825023","replication_slot":["barman",true,"0/E000000"],"replication_slot_support":true,"server_txt_version":"15.3","streaming":null,"streaming_supported":null,"streaming_systemid":null,"synchronous_standby_names":[""],"timeline":null,"version_supported":null,"wal_compression":"off","wal_keep_size":"0","wal_level":"replica","xlog_segment_size":16777216,"xlogpos":null},"wals":{"last_archived_wal_per_timeline":{}}}}}

pg-backup-api 2.1.0 doesn't work with Barman <= 3.9 because it attempts to
fetch models independently of the Barman version it operates on. As Barman
models were introduced through version 3.10, pg-backup-api fails with an
ugly stack trace:

```
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/lib/python3.9/site-packages/pg_backup_api/logic/utility_controller.py", line 76, in diagnose
    available_models = barman.__config__.model_names()
AttributeError: 'Config' object has no attribute 'model_names'
```

Through this commit we fix pg-backup-api in that sense:

* It attempts to use models and the new signature of the `exec_diagnose`,
  which were introduced by Barman 3.10;
* It falls back to the old signature of `exec_diagnose` if models are not
  available (Barman <= 3.9).

References: BAR-171.

Signed-off-by: Israel Barth Rubio <[email protected]>
@barthisrael barthisrael marked this pull request as ready for review May 21, 2024 14:59
@barthisrael barthisrael merged commit 5550f47 into main May 21, 2024
9 of 14 checks passed
@barthisrael barthisrael deleted the dev/bar-171 branch May 21, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants