Skip to content

Commit

Permalink
PMM-12592 PMM-12587 fix SQLite to PostgreSQL (#2549)
Browse files Browse the repository at this point in the history
* PMM-7 More debug data.

* PMM-12584 fix hex values in PostgreSQL DB.

* PMM-12588 Outdated grafana-db-migrator used (#2547)

* PMM-12584 fix provisioning problem.

* PMM-12584 fix drop database issue.

* PMM-12584 fix drop database issue for EL7.

* PMM-12584 fix drop database issue for EL7.

* PMM-12584 fix drop database issue for EL7.

* Update update/ansible/playbook/tasks/roles/sqlite-to-postgres/tasks/main.yml

Co-authored-by: Alex Demidoff <[email protected]>

---------

Co-authored-by: Vadim Yalovets <[email protected]>
Co-authored-by: Alex Demidoff <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2023
1 parent 79357f3 commit 578bab3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
9 changes: 6 additions & 3 deletions build/packages/rpm/server/SPECS/grafana-db-migrator.spec
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%undefine _missing_build_ids_terminate_build

%global release_hash 63e4bfdb7dd7162e238531c794f4ddef83173158
%global release_hash 27b37c412e257bd8a5bcdbcaf52befa3fe555a9d

Name: grafana-db-migrator
Version: 1.0.7
Release: 1%{?dist}
Version: 1.0.8
Release: 2%{?dist}
Summary: A tool for Grafana database migration
License: MIT
URL: https://github.com/percona/grafana-db-migrator
Expand All @@ -30,6 +30,9 @@ install -m 755 dist/grafana-db-migrator %{buildroot}%{_sbindir}/
%{_sbindir}/grafana-db-migrator

%changelog
* Fri Oct 13 2023 Nurlan Moldomurov <[email protected]> - 1.0.8-2
- Fix issue with hexed values and folder fixes.

* Mon Feb 13 2023 Nikita Beletskii <[email protected]> - 1.0.7-1
- Fix issue with convert_from()

Expand Down
3 changes: 3 additions & 0 deletions build/scripts/build-server-rpm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ build() {
s3://pmm-build-cache/RELEASE/${rpmbuild_dist}/${spec_name}-${rpm_version} \
|| :
fi

cp ${rpms_dir}/${spec_name}-${rpm_version}/*/*.rpm ${rpms_dir}

fi
}

Expand Down
22 changes: 15 additions & 7 deletions update/ansible/playbook/tasks/roles/initialization/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
debug:
msg: "Current version: {{ pmm_current_version }} Image Version: {{ pmm_image_version }}"

# We use current_version_file['failed'] because we don't want to run this on creating container
# and we use pmm_current_version is version(pmm_image_version, '>=') to run it only if upgrade is required
- name: Determine type of upgrade
set_fact:
docker_upgrade: not ui_upgrade and current_version_file['failed'] == false and not pmm_current_version is version(pmm_image_version, '>=')

# We use current_version_file['failed'] because we don't want to run this on creating container
# and we use pmm_current_version is version(pmm_image_version, '>=') to run it only if upgrade is required
Expand All @@ -42,7 +47,7 @@
src: maintenance.html
dest: /usr/share/pmm-server/maintenance/
mode: 0644
when: not ui_upgrade and current_version_file['failed'] == false and not pmm_current_version is version(pmm_image_version, '>=')
when: docker_upgrade

# PMM-10858 - In certain environments, including AWS EC2, some of the
# EPEL repository mirrors do not respond within the time limit defined
Expand All @@ -60,11 +65,6 @@
become: true
changed_when: True

- name: Check if we need an update or not
include_role:
name: dashboards_upgrade
when: not pmm_current_version is version(pmm_image_version, '>=')

- name: Create backup directory
file:
path: /srv/backup
Expand Down Expand Up @@ -159,7 +159,15 @@
tags:
- skip_ansible_lint # '503 Tasks that run when changed should likely be handlers'.
when: is_database_sqlite.stat.exists
when: docker_upgrade

- name: Check if we need an update or not
include_role:
name: dashboards_upgrade
when: not pmm_current_version is version(pmm_image_version, '>=')

- name: Finalization
block:
- name: Wait for PMM to be ready
ansible.builtin.uri:
url: "http://127.0.0.1:7772/v1/readyz"
Expand All @@ -173,6 +181,6 @@
state: absent
path: /usr/share/pmm-server/maintenance/maintenance.html
# We use current_version_file['failed'] because we don't want to run this on creating container
when: not ui_upgrade and current_version_file['failed'] == false and not pmm_current_version is version(pmm_image_version, '>=')
when: docker_upgrade


Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@
name: 'grafana'
state: stopped

- name: Drop grafana database from postgres EL7
postgresql_query:
db: postgres
query: DROP DATABASE grafana WITH (FORCE);
when:
- ansible_distribution == "CentOS"
- ansible_distribution_major_version == "7"
- not ansible_check_mode

- name: Drop grafana database from postgres EL9
postgresql_db:
name: grafana
state: absent
force: yes
when:
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'

- name: Create grafana database in postgres
postgresql_db:
name: grafana
state: present

- name: Create grafana user in postgres
postgresql_user:
db: grafana
name: grafana
password: grafana
priv: 'ALL'
expires: infinity
state: present
when: not ansible_check_mode

- name: Create backup for SQLite Grafana database
copy:
src: /srv/grafana/grafana.db
Expand Down Expand Up @@ -105,6 +138,12 @@
register: migrator_output
changed_when: "'All done' in migrator_output.stdout"

- name: copy the output of grafana-db-migrator to file
copy:
content: "{{ migrator_output.stdout }}"
dest: "/srv/logs/grafana-db-migrator.log"
when: not ansible_check_mode

- name: Enable provisioning after change database
ini_file:
dest: /etc/grafana/grafana.ini
Expand All @@ -126,6 +165,13 @@
register: migrator_output
changed_when: "'All done' in migrator_output.stdout"

- name: Copy the output of grafana-db-migrator to file
ansible.builtin.blockinfile:
dest: /srv/logs/grafana-db-migrator.log
block: "{{ migrator_output.stdout }}"
backup: yes
when: not ansible_check_mode

- name: Remove SQLite Grafana database
file:
path: /srv/grafana/grafana.db
Expand Down

0 comments on commit 578bab3

Please sign in to comment.