grafana-ansible-collection icon indicating copy to clipboard operation
grafana-ansible-collection copied to clipboard

alloy: Use service reload instead of restart

Open f9n opened this issue 1 year ago • 2 comments

When you change the configuration of the alloy service, ansible role restarts the service. So all the nodes of the cluster are down, they are replaying the wal files. Can we reload it when the configuration is changed?

# roles/alloy/tasks/configure.yml#L19
- name: Deploy alloy configuration file
  ansible.builtin.template:
    src: config.alloy.j2
    dest: "{{ config_dir }}/{{ config_file }}"
    owner: "{{ service_user }}"
    group: "{{ service_group }}"
    mode: '0644'
  notify: Reload alloy
  become: true

# roles/alloy/handlers/main.yml#L7 Add new handler
- name: Check if alloy service is active
  ansible.builtin.shell: systemctl is-active alloy
  register: alloy_service_status
  ignore_errors: true
  listen: "Reload alloy"

- name: Restart alloy service if not active
  ansible.builtin.service:
    name: alloy
    state: restarted
  when: alloy_service_status.stdout != "active"
  listen: "Reload alloy"

- name: Reload alloy service if active
  ansible.builtin.service:
    name: alloy
    state: reloaded
  when: alloy_service_status.stdout == "active"
  listen: "Reload alloy"

- name: Check alloy is started properly
  ansible.builtin.include_tasks: ga-started.yml
  listen: "Reload alloy"

If it is convenient for you, we can create a pull request for the above changes. cc: @emre-23 @acciorg

f9n avatar Jun 11 '24 17:06 f9n

Thanks @f9n Yeah that makes sense and yeah definitely put a PR

ishanjainn avatar Jun 12 '24 03:06 ishanjainn

If you'd like to implement this, I believe it should be sufficient to update the template task to trigger a reload instead of a restart and create a new handler for the reload.

voidquark avatar Oct 21 '24 15:10 voidquark