From 788e20cb763563983c7a52a889f3603fd2af6e23 Mon Sep 17 00:00:00 2001 From: Brule Date: Mon, 12 Feb 2024 16:06:26 +0100 Subject: [PATCH 1/3] management of the config.river with the conversion of the config.yaml --- roles/grafana_agent/tasks/configure.yaml | 5 +++++ roles/grafana_agent/templates/config.yaml.j2 | 2 ++ 2 files changed, 7 insertions(+) diff --git a/roles/grafana_agent/tasks/configure.yaml b/roles/grafana_agent/tasks/configure.yaml index 6e2bdf7f..b582238e 100644 --- a/roles/grafana_agent/tasks/configure.yaml +++ b/roles/grafana_agent/tasks/configure.yaml @@ -40,6 +40,11 @@ notify: "restart grafana-agent" when: grafana_agent_provisioned_config_file | length == 0 +- name: Create Grafana Agent River Config if flow mode for Grafana Agent + ansible.builtin.shell: "AGENT_MODE=flow {{ grafana_agent_install_dir }}/grafana-agent convert -f static {{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }} -o {{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}" + notify: "restart grafana-agent" + when: grafana_agent_provisioned_config_file | length == 0 + - name: Copy Grafana Agent config ansible.builtin.copy: src: "{{ grafana_agent_provisioned_config_file }}" diff --git a/roles/grafana_agent/templates/config.yaml.j2 b/roles/grafana_agent/templates/config.yaml.j2 index 0e427756..b36ee7a3 100644 --- a/roles/grafana_agent/templates/config.yaml.j2 +++ b/roles/grafana_agent/templates/config.yaml.j2 @@ -22,12 +22,14 @@ metrics: logs: {{ grafana_agent_logs_config | to_nice_yaml(indent=2,sort_keys=False) | indent(2) }} +{% if grafana_agent_mode == 'static' %} ################################################################################################# # Configures traces collection # ################################################################################################# # Docs: https://grafana.com/docs/agent/latest/configuration/traces-config/ traces: {{ grafana_agent_traces_config | to_nice_yaml(indent=2,sort_keys=False) | indent(2) }} +{% endif %} ################################################################################################# # Configures integrations for the agent # From 6d6e72233560176c2b9ffac04797a248ae5dda65 Mon Sep 17 00:00:00 2001 From: Brule Date: Mon, 12 Feb 2024 18:46:22 +0100 Subject: [PATCH 2/3] management of the config.river with the conversion of the config.yaml --- roles/grafana_agent/tasks/configure.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/grafana_agent/tasks/configure.yaml b/roles/grafana_agent/tasks/configure.yaml index b582238e..5f4db485 100644 --- a/roles/grafana_agent/tasks/configure.yaml +++ b/roles/grafana_agent/tasks/configure.yaml @@ -41,7 +41,7 @@ when: grafana_agent_provisioned_config_file | length == 0 - name: Create Grafana Agent River Config if flow mode for Grafana Agent - ansible.builtin.shell: "AGENT_MODE=flow {{ grafana_agent_install_dir }}/grafana-agent convert -f static {{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }} -o {{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}" + ansible.builtin.shell: "AGENT_MODE=flow {{ grafana_agent_install_dir }}/grafana-agent convert -f static {{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }} -o {{ grafana_agent_config_dir }}/{{ grafana_agent_config_filename }}" notify: "restart grafana-agent" when: grafana_agent_provisioned_config_file | length == 0 From 84ebaaf1d689142592a402161e377a76e4bddf34 Mon Sep 17 00:00:00 2001 From: Brule Date: Mon, 12 Feb 2024 19:02:40 +0100 Subject: [PATCH 3/3] management of the config.river with the conversion of the config.yaml : example of playbook --- examples/agent-mode-flow-with-dynamic-conf.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 examples/agent-mode-flow-with-dynamic-conf.yaml diff --git a/examples/agent-mode-flow-with-dynamic-conf.yaml b/examples/agent-mode-flow-with-dynamic-conf.yaml new file mode 100644 index 00000000..be469d0b --- /dev/null +++ b/examples/agent-mode-flow-with-dynamic-conf.yaml @@ -0,0 +1,12 @@ +- hosts: all + tasks: + - name: Install Grafana Agent + ansible.builtin.include_role: + name: grafana.grafana.grafana_agent + vars: + grafana_agent_mode: flow + # Change config file on the host to .river + grafana_agent_config_filename: config.river + # Remove default flags + grafana_agent_flags_extra: + server.http.listen-addr: '0.0.0.0:12345' \ No newline at end of file