Skip to content

Commit

Permalink
Merge branch 'pmm-2.40.1'
Browse files Browse the repository at this point in the history
# Conflicts:
#	update/ansible/playbook/tasks/roles/clickhouse/tasks/main.yml
  • Loading branch information
BupycHuk committed Oct 21, 2023
2 parents c3cb1a7 + 12ce642 commit 3029ae9
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 12 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
37 changes: 28 additions & 9 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,15 @@
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'] != true and not pmm_current_version is version(pmm_image_version, '>=') }}"

- name: Print Docker upgrade fact
debug:
msg: "Docker upgrade: {{ docker_upgrade }}"

# 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 +51,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 +69,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 @@ -104,14 +108,14 @@
- name: Create empty configuration file for VictoriaMetrics
file: path=/etc/victoriametrics-promscrape.yml state=touch owner=pmm group=pmm

- name: Run SQLite -> Postgres only for docker upgrade
- name: Run operations for docker-way upgrade
block:
- name: Check that the SQLite grafana database exists
stat:
path: /srv/grafana/grafana.db
register: is_database_sqlite

- name: Temporary change database to SQLite
- name: Run SQLite -> Postgres only
block:
- name: Remove database options (SQLite is default)
ini_file:
Expand Down Expand Up @@ -160,6 +164,21 @@
- skip_ansible_lint # '503 Tasks that run when changed should likely be handlers'.
when: is_database_sqlite.stat.exists

- name: Change default admin id
postgresql_query:
db: grafana
query: UPDATE "user" SET id='1' WHERE login='admin';
when: not ansible_check_mode

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 +192,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 @@ -62,6 +62,7 @@
error_page 503 @maintenance;

location @maintenance {
auth_request off;
root /usr/share/pmm-server/maintenance;
rewrite ^(.*)$ /maintenance.html break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@
name: 'grafana'
state: stopped

- name: Drop grafana database from postgres EL7
command: dropdb -f grafana -U postgres
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 @@ -84,6 +115,7 @@
register: psql_result
until: psql_result.rowcount == 1
when: not ansible_check_mode
ignore_errors: yes

- name: Wait for grafana database initialization
pause:
Expand All @@ -105,6 +137,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 +164,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
6 changes: 6 additions & 0 deletions update/ansible/playbook/tasks/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@
- ALTER TABLE api_key ALTER COLUMN name TYPE text;
when: not ansible_check_mode

- name: Change default admin id
postgresql_query:
db: grafana
query: UPDATE "user" SET id='1' WHERE login='admin';
when: not ansible_check_mode

# we need to put this step as one of the last steps, because it removes pmm.ini and /etc/alertmanager.yml
- name: Remove old or redundant packages
yum:
Expand Down

0 comments on commit 3029ae9

Please sign in to comment.