From b316587dae63063cb3cfe22a77707540d36ecebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Thu, 9 May 2019 15:43:02 -0300 Subject: [PATCH] Enable kolla-ansible to use a custom metrics files with Cloudkitty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cloudkitty has a default (built-in the container) metrics.yml file in the /etc/cloudkitty/metrics.yml files. We would like to be able to overwrite/customize these metrics configurations via kolla-ansible. Cloudkitty is able to use a custom metric file via "metrics_conf". Therefore, we are enabling this configuration via Kolla-ansible. Change-Id: Id9019298482c040be05f540e71dacfdf0bd77469 Signed-off-by: Rafael Weingärtner --- ansible/roles/cloudkitty/defaults/main.yml | 1 + ansible/roles/cloudkitty/tasks/config.yml | 22 +++++++++++++++++++ .../templates/cloudkitty-api.json.j2 | 6 +++++ .../templates/cloudkitty-processor.json.j2 | 6 +++++ .../cloudkitty/templates/cloudkitty.conf.j2 | 3 +++ 5 files changed, 38 insertions(+) diff --git a/ansible/roles/cloudkitty/defaults/main.yml b/ansible/roles/cloudkitty/defaults/main.yml index 663720adf6..cc34cfc78b 100644 --- a/ansible/roles/cloudkitty/defaults/main.yml +++ b/ansible/roles/cloudkitty/defaults/main.yml @@ -90,3 +90,4 @@ cloudkitty_git_repository: "{{ kolla_dev_repos_git }}/{{ project_name }}" cloudkitty_dev_repos_pull: "{{ kolla_dev_repos_pull }}" cloudkitty_dev_mode: "{{ kolla_dev_mode }}" cloudkitty_source_version: "{{ kolla_source_version }}" +cloudkitty_custom_metrics_yaml_file: "metrics.yml" diff --git a/ansible/roles/cloudkitty/tasks/config.yml b/ansible/roles/cloudkitty/tasks/config.yml index 6a4200f901..7758f06352 100644 --- a/ansible/roles/cloudkitty/tasks/config.yml +++ b/ansible/roles/cloudkitty/tasks/config.yml @@ -29,6 +29,28 @@ when: - cloudkitty_policy.results +- name: Check if custom {{ cloudkitty_custom_metrics_yaml_file }} exists + local_action: stat path="{{ node_custom_config }}/cloudkitty/{{ cloudkitty_custom_metrics_yaml_file }}" + register: cloudkitty_custom_metrics_file + +- name: Copying {{ cloudkitty_custom_metrics_yaml_file }} if it exists + copy: + src: "{{ node_custom_config }}/cloudkitty/{{ cloudkitty_custom_metrics_yaml_file }}" + dest: "{{ node_config_directory }}/{{ item.key }}/{{ cloudkitty_custom_metrics_yaml_file }}" + mode: "0660" + become: true + when: + - cloudkitty_custom_metrics_file.stat.exists + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ cloudkitty_services }}" + notify: + - "Restart {{ item.key }} container" + +- name: Are we using {{ cloudkitty_custom_metrics_yaml_file }}? + set_fact: + cloudkitty_custom_metrics_used: "{{ cloudkitty_custom_metrics_file.stat.exists }}" + - name: Copying over config.json files for services template: src: "{{ item.key }}.json.j2" diff --git a/ansible/roles/cloudkitty/templates/cloudkitty-api.json.j2 b/ansible/roles/cloudkitty/templates/cloudkitty-api.json.j2 index f31a43b9da..29b67738c0 100644 --- a/ansible/roles/cloudkitty/templates/cloudkitty-api.json.j2 +++ b/ansible/roles/cloudkitty/templates/cloudkitty-api.json.j2 @@ -20,6 +20,12 @@ "dest": "/etc/cloudkitty/{{ cloudkitty_policy_file }}", "owner": "cloudkitty", "perm": "0600" + }{% endif %}{% if cloudkitty_custom_metrics_used %}, + { + "source": "{{ container_config_directory }}/{{ cloudkitty_custom_metrics_yaml_file }}", + "dest": "/etc/cloudkitty/{{ cloudkitty_custom_metrics_yaml_file }}", + "owner": "cloudkitty", + "perm": "0600" }{% endif %} ], "permissions": [ diff --git a/ansible/roles/cloudkitty/templates/cloudkitty-processor.json.j2 b/ansible/roles/cloudkitty/templates/cloudkitty-processor.json.j2 index 7d57ae041e..4cd1041e08 100644 --- a/ansible/roles/cloudkitty/templates/cloudkitty-processor.json.j2 +++ b/ansible/roles/cloudkitty/templates/cloudkitty-processor.json.j2 @@ -12,6 +12,12 @@ "dest": "/etc/cloudkitty/{{ cloudkitty_policy_file }}", "owner": "cloudkitty", "perm": "0600" + }{% endif %}{% if cloudkitty_custom_metrics_used %}, + { + "source": "{{ container_config_directory }}/{{ cloudkitty_custom_metrics_yaml_file }}", + "dest": "/etc/cloudkitty/{{ cloudkitty_custom_metrics_yaml_file }}", + "owner": "cloudkitty", + "perm": "0600" }{% endif %} ], "permissions": [ diff --git a/ansible/roles/cloudkitty/templates/cloudkitty.conf.j2 b/ansible/roles/cloudkitty/templates/cloudkitty.conf.j2 index 9ca9081089..d8f9707309 100644 --- a/ansible/roles/cloudkitty/templates/cloudkitty.conf.j2 +++ b/ansible/roles/cloudkitty/templates/cloudkitty.conf.j2 @@ -39,6 +39,9 @@ policy_file = {{ cloudkitty_policy_file }} [collect] collector = {{ cloudkitty_collector_backend }} services = compute,image{% if enable_cinder | bool %},volume{% endif %},network.bw.out,network.bw.in,network.floating +{% if cloudkitty_custom_metrics_used %} +metrics_conf = /etc/cloudkitty/{{ cloudkitty_custom_metrics_yaml_file }} +{% endif %} [keystone_fetcher] keystone_version = 3