From 56aba493bfaa017d583d4781a146b3c84d24c0e7 Mon Sep 17 00:00:00 2001 From: Vlad Zolotarov Date: Mon, 11 Mar 2024 21:12:39 -0400 Subject: [PATCH] scylla-monitoring: auto-detect Scylla dashboard version Auto-detect Scylla version when scylla_monitoring_dashboards_versions is not specified or is empty. Scylla must be installed on the first host from the 'scylla' section in the inventory for auto-detection to succeed. Signed-off-by: Vlad Zolotarov --- ansible-scylla-monitoring/defaults/main.yml | 7 ++++--- ansible-scylla-monitoring/tasks/common.yml | 23 +++++++++++++++++++++ ansible-scylla-monitoring/tasks/docker.yml | 8 +++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ansible-scylla-monitoring/defaults/main.yml b/ansible-scylla-monitoring/defaults/main.yml index 3bbfea55..b0a1f942 100644 --- a/ansible-scylla-monitoring/defaults/main.yml +++ b/ansible-scylla-monitoring/defaults/main.yml @@ -31,9 +31,10 @@ scylla_monitoring_alertdata_path: "{{ scylla_monitoring_deploy_path }}/alertdata # will use the information from the inventory to generate scylla_servers.yml. use_nodetool_status_with_genconfig: false -# List of monitoring dashboards to enable -scylla_monitoring_dashboards_versions: - - '2021.1' +# List of monitoring dashboards to enable. If empty or not set the Role will auto-select the one that corresponds to a +# Scylla version installed on the first host from the 'scylla' inventory section. +#scylla_monitoring_dashboards_versions: +# - '2021.1' # Username which will be used for the cql plugin if auth is enabled on scylla-server side # scylla_monitoring_cql_default_user: 'scylla_cql_monitor' diff --git a/ansible-scylla-monitoring/tasks/common.yml b/ansible-scylla-monitoring/tasks/common.yml index 091ca6e7..c8f9d937 100644 --- a/ansible-scylla-monitoring/tasks/common.yml +++ b/ansible-scylla-monitoring/tasks/common.yml @@ -240,3 +240,26 @@ msg: "Can't auto-detect Scylla Manager dashboard version. Either specify it explicitly or install Scylla Manager Server on the Scylla Manager host." when: _sm_version_out.rc != 0 when: _scylla_monitoring_params is not search("-M\s+") and 'scylla-manager' in groups and (groups['scylla-manager']|length > 0) + +- name: Set _scylla_monitoring_dashboards_versions to scylla_monitoring_dashboards_versions + set_fact: + _scylla_monitoring_dashboards_versions: "{{ scylla_monitoring_dashboards_versions | default([]) }}" + +- name: Auto detect Scylla version if dashboard versions were not explicitly specified + block: + - name: Get Scylla version from the first Scylla node + shell: | + scylla --version | cut -d'.' -f1,2 + delegate_to: "{{ groups['scylla'][0] }}" + register: _scylla_version_out + + - name: Adding Scylla dashboard option if getting a Scylla version was successful + set_fact: + _scylla_monitoring_dashboards_versions: ["{{ _scylla_version_out.stdout }}"] + when: _scylla_version_out.rc == 0 + + - name: Error out if failed to get Scylla version + fail: + msg: "Can't auto-detect Scylla dashboard version. Either specify it explicitly or install scylla on the first Scylla node." + when: _scylla_version_out.rc != 0 + when: (_scylla_monitoring_dashboards_versions|length == 0) and 'scylla' in groups and (groups['scylla']|length > 0) diff --git a/ansible-scylla-monitoring/tasks/docker.yml b/ansible-scylla-monitoring/tasks/docker.yml index 5bbcd0eb..69004cef 100644 --- a/ansible-scylla-monitoring/tasks/docker.yml +++ b/ansible-scylla-monitoring/tasks/docker.yml @@ -39,7 +39,7 @@ ./start-all.sh \ -d {{ scylla_monitoring_data_path }} \ -f {{ scylla_monitoring_alertdata_path }} \ - -v {{ scylla_monitoring_dashboards_versions|join(',') }} \ + -v {{ _scylla_monitoring_dashboards_versions|join(',') }} \ -s {{ scylla_monitoring_config_path }}/scylla_servers.yml \ -N {{ scylla_monitoring_config_path }}/scylla_manager_servers.yml \ -r {{ scylla_monitoring_config_path }}/rule_config.yml \ @@ -67,7 +67,7 @@ ./start-all.sh \ -d {{ scylla_monitoring_data_path }} \ -f {{ scylla_monitoring_alertdata_path }} \ - -v {{ scylla_monitoring_dashboards_versions|join(',') }} \ + -v {{ _scylla_monitoring_dashboards_versions|join(',') }} \ -s {{ scylla_monitoring_config_path }}/scylla_servers.yml \ -N {{ scylla_monitoring_config_path }}/scylla_manager_servers.yml \ -r {{ scylla_monitoring_config_path }}/rule_config.yml \ @@ -95,7 +95,7 @@ ./start-all.sh \ -d {{ scylla_monitoring_data_path }} \ -f {{ scylla_monitoring_alertdata_path }} \ - -v {{ scylla_monitoring_dashboards_versions|join(',') }} \ + -v {{ _scylla_monitoring_dashboards_versions|join(',') }} \ -s {{ scylla_monitoring_config_path }}/scylla_servers.yml \ -N {{ scylla_monitoring_config_path }}/scylla_manager_servers.yml \ -r {{ scylla_monitoring_config_path }}/rule_config.yml \ @@ -124,7 +124,7 @@ ./start-all.sh \ -d {{ scylla_monitoring_data_path }} \ -f {{ scylla_monitoring_alertdata_path }} \ - -v {{ scylla_monitoring_dashboards_versions|join(',') }} \ + -v {{ _scylla_monitoring_dashboards_versions|join(',') }} \ -s {{ scylla_monitoring_config_path }}/scylla_servers.yml \ -N {{ scylla_monitoring_config_path }}/scylla_manager_servers.yml \ -r {{ scylla_monitoring_config_path }}/rule_config.yml \