Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/refactor grafana agent #154

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions roles/grafana_agent/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
grafana_agent_version: latest
# grafana_agent_mode: "flow"
grafana_agent_mode: "static"
grafana_agent_package: "grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}{{ (grafana_agent_version != 'latest') | ternary('=' ~ grafana_agent_version, '') }}"
grafana_agent_manage_repo: true
grafana_agent_dependencies: []

# Grafana Agent Apt Repository Configuration
grafana_agent_apt_release_channel: stable
grafana_agent_apt_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
grafana_agent_apt_repo: "deb [arch={{ grafana_agent_apt_arch }} signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com/ {{ grafana_agent_apt_release_channel }} main"
grafana_agent_apt_key: "https://apt.grafana.com/gpg.key"

# Grafana Agent Yum Repository Configuration
grafana_agent_yum_repo: https://rpm.grafana.com
grafana_agent_yum_key: https://rpm.grafana.com/gpg.key

grafana_agent_user_group: grafana-agent

grafana_agent_static_config:
server:
log_level: warn

metrics:
global:
scrape_interval: 1m
wal_directory: '/var/lib/grafana-agent'
configs:
# Example Prometheus scrape configuration to scrape the agent itself for metrics.
# This is not needed if the agent integration is enabled.
# - name: agent
# host_filter: false
# scrape_configs:
# - job_name: agent
# static_configs:
# - targets: ['127.0.0.1:9090']

integrations:
agent:
enabled: true
node_exporter:
enabled: true
include_exporter_metrics: true
disable_collectors:
- "mdadm"

grafana_agent_flow_config: |
logging {
level = "warn"
}

prometheus.exporter.unix "default" {
include_exporter_metrics = true
disable_collectors = ["mdadm"]
}

prometheus.scrape "default" {
targets = concat(
prometheus.exporter.unix.default.targets,
[{
// Self-collect metrics
job = "agent",
__address__ = "127.0.0.1:12345",
}],
)

forward_to = [
// TODO: components to forward metrics to (like prometheus.remote_write or
// prometheus.relabel).
]
}
12 changes: 0 additions & 12 deletions roles/grafana_agent/handlers/main.yaml

This file was deleted.

19 changes: 19 additions & 0 deletions roles/grafana_agent/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Restart Grafana Agent with daemon reload
become: true
ansible.builtin.systemd:
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: restarted
daemon_reload: true

- name: Restart Grafana Agent
become: true
ansible.builtin.systemd:
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: restarted

- name: Reload Grafana Agent
become: true
ansible.builtin.systemd:
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: reloaded
25 changes: 0 additions & 25 deletions roles/grafana_agent/meta/main.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions roles/grafana_agent/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
gather_facts: true
roles:
- role: grafana_agent
1 change: 1 addition & 0 deletions roles/grafana_agent/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
gather_facts: true
vars:
grafana_agent_mode: flow
roles:
- role: grafana_agent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
51 changes: 0 additions & 51 deletions roles/grafana_agent/tasks/configure.yaml

This file was deleted.

20 changes: 20 additions & 0 deletions roles/grafana_agent/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Create Grafana Agent config - static
when: grafana_agent_mode == 'static'
ansible.builtin.template:
src: grafana-agent-static.yaml.j2
dest: /etc/grafana-agent.yaml
owner: root
group: "{{ grafana_agent_user_group }}"
mode: "0640"
notify: Restart Grafana Agent

- name: Create Grafana Agent config - flow
when: grafana_agent_mode == 'flow'
ansible.builtin.template:
src: grafana-agent-flow.river.j2
dest: /etc/grafana-agent-flow.river
owner: root
group: "{{ grafana_agent_user_group }}"
mode: "0640"
notify: Reload Grafana Agent
29 changes: 0 additions & 29 deletions roles/grafana_agent/tasks/ga-started.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions roles/grafana_agent/tasks/install.yaml

This file was deleted.

60 changes: 60 additions & 0 deletions roles/grafana_agent/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
- name: Gather variables for each operating system
ansible.builtin.include_vars: "{{ distrovars }}"
vars:
distrovars: "{{ lookup('first_found', params, errors='ignore') }}"
params:
skip: true
files:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
paths:
- "vars/"
tags:
- grafana_agent_install
- grafana_agent_configure

- name: Install dependencies
ansible.builtin.package:
name: "{{ grafana_agent_dependencies }}"
state: present

- name: Prepare apt
when:
- "ansible_pkg_mgr == 'apt'"
- grafana_agent_manage_repo
block:
- name: Import Grafana apt gpg key
ansible.builtin.get_url:
url: "{{ grafana_agent_apt_key }}"
dest: /usr/share/keyrings/grafana.key
mode: "0644"

- name: Add Grafana apt repository
ansible.builtin.apt_repository:
repo: "{{ grafana_agent_apt_repo }}"
state: present
update_cache: true

- name: Add Grafana yum/dnf repository
when:
- "ansible_pkg_mgr in ['yum', 'dnf']"
- grafana_agent_manage_repo
ansible.builtin.yum_repository:
name: grafana
description: grafana
baseurl: "{{ grafana_agent_yum_repo }}"
enabled: true
gpgkey: "{{ grafana_agent_yum_key | default(omit) }}"
sslverify: true
repo_gpgcheck: "{{ true if (grafana_agent_yum_key) else omit }}"
gpgcheck: "{{ true if (grafana_agent_yum_key) else omit }}"

- name: "Install Grafana Agent"
ansible.builtin.package:
name: "{{ grafana_agent_package }}"
state: "{{ (grafana_agent_version == 'latest') | ternary('latest', 'present') }}"
notify: Restart Grafana Agent
26 changes: 0 additions & 26 deletions roles/grafana_agent/tasks/install/directories.yaml

This file was deleted.

48 changes: 0 additions & 48 deletions roles/grafana_agent/tasks/install/download-install.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions roles/grafana_agent/tasks/install/local-install.yaml

This file was deleted.

38 changes: 0 additions & 38 deletions roles/grafana_agent/tasks/install/user-group.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
---
- name: Preflight tasks
- name: Preflight
ansible.builtin.include_tasks:
file: preflight.yaml
file: preflight.yml
apply:
become: true
tags:
- grafana_agent_install
- grafana_agent_configure
- grafana_agent_run
tags:
- grafana_agent_install
- grafana_agent_configure
- grafana_agent_run

- name: Install tasks
- name: Install
ansible.builtin.include_tasks:
file: install.yaml
file: install.yml
apply:
become: true
tags:
- grafana_agent_install
tags:
- grafana_agent_install

- name: Configuration tasks
- name: Configure
ansible.builtin.include_tasks:
file: configure.yaml
file: configure.yml
apply:
become: true
tags:
- grafana_agent_configure
tags:
- grafana_agent_configure

- name: Flush handlers
ansible.builtin.meta: flush_handlers

- name: Ensure Grafana Agent is started and enabled on boot
- name: Start and enable Grafana Agent
become: true
ansible.builtin.systemd:
name: grafana-agent
enabled: true
ansible.builtin.service:
name: grafana-agent{% if grafana_agent_mode == 'flow' %}-flow{% endif %}
state: started
enabled: true
tags:
- grafana_agent_install
- grafana_agent_configure
- grafana_agent_run
12 changes: 0 additions & 12 deletions roles/grafana_agent/tasks/preflight.yaml

This file was deleted.

1 change: 1 addition & 0 deletions roles/grafana_agent/tasks/preflight.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
36 changes: 0 additions & 36 deletions roles/grafana_agent/tasks/preflight/download.yaml

This file was deleted.

72 changes: 0 additions & 72 deletions roles/grafana_agent/tasks/preflight/install.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions roles/grafana_agent/tasks/preflight/systemd.yaml

This file was deleted.

72 changes: 0 additions & 72 deletions roles/grafana_agent/tasks/preflight/vars.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions roles/grafana_agent/templates/EnvironmentFile.j2

This file was deleted.

37 changes: 0 additions & 37 deletions roles/grafana_agent/templates/config.yaml.j2

This file was deleted.

3 changes: 3 additions & 0 deletions roles/grafana_agent/templates/grafana-agent-flow.river.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ ansible_managed | comment('c') }}
// For a full configuration reference, see https://grafana.com/docs/agent/latest/flow/
{{ grafana_agent_flow_config }}
5 changes: 5 additions & 0 deletions roles/grafana_agent/templates/grafana-agent-static.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
{{ ansible_managed | comment }}
# For a full configuration reference, see: https://grafana.com/docs/agent/latest/configuration/.
{# The to_nice_yaml filter behaves strange therefore we first read in as yaml and then print as yaml again #}
{{ grafana_agent_static_config | from_yaml | to_nice_yaml(sort_keys=False, width=1000,indent=2) }}
5 changes: 5 additions & 0 deletions roles/grafana_agent/vars/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_grafana_agent_dependencies:
- apt-transport-https
- adduser
- ca-certificates
- gnupg2
29 changes: 0 additions & 29 deletions roles/grafana_agent/vars/main.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions roles/grafana_agent/vars/redhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# https://unix.stackexchange.com/questions/534463/cant-enable-grafana-on-boot-in-fedora-because-systemd-sysv-install-missing
grafana_agent_dependencies:
- chkconfig

Unchanged files with check annotations Beta

# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2

Check warning on line 6 in .github/dependabot.yml

GitHub Actions / Perform Linting

6:1 [document-start] missing document start "---"
updates:
- package-ecosystem: "pip" # See documentation for possible values

Check warning on line 8 in .github/dependabot.yml

GitHub Actions / Perform Linting

8:30 [comments] too few spaces before comment
directory: "/" # Location of package manifests

Check warning on line 9 in .github/dependabot.yml

GitHub Actions / Perform Linting

9:20 [comments] too few spaces before comment
schedule:
interval: "weekly"
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin cloud_stack dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 65 in .github/workflows/full-integration-test.yml

GitHub Actions / Perform Linting

65:151 [line-length] line too long (255 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Cooling Period
run: pip install requests
- name: Test Roles
run: ansible-test integration -v molecule-grafana-alternative molecule-grafana-default --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 89 in .github/workflows/roles-test.yml

GitHub Actions / Perform Linting

89:151 [line-length] line too long (196 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
run: pip install requests
- name: Create Test Stack
run: ansible-test integration -v create_cloud_stack --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 88 in .github/workflows/modules-test.yml

GitHub Actions / Perform Linting

88:151 [line-length] line too long (161 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 92 in .github/workflows/modules-test.yml

GitHub Actions / Perform Linting

92:151 [line-length] line too long (243 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Delete Test Stack
if: success() || failure()
run: ansible-test integration -v delete_cloud_stack --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 97 in .github/workflows/modules-test.yml

GitHub Actions / Perform Linting

97:151 [line-length] line too long (161 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
run: pip install requests
- name: Create Test Stack
run: ansible-test integration -v create_cloud_stack --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 86 in .github/workflows/release.yml

GitHub Actions / Perform Linting

86:151 [line-length] line too long (161 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 90 in .github/workflows/release.yml

GitHub Actions / Perform Linting

90:151 [line-length] line too long (243 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Delete Test Stack
ancestor: null

Check failure on line 1 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

schema[changelog]

$.releases.4.0.0.changes.minor_changes[5] {'fix': 'Apply correct uid + gid for imported dashboards by @hypery2k in https://github.com/grafana/grafana-ansible-collection/pull/167'} is not of type 'string'. See https://github.com/ansible-community/antsibull-changelog/blob/main/docs/changelog.yaml-format.md
releases:
0.0.1:
changes:
0.0.4:
changes:
bugfixes:
- Fix an issue with `cloud_stack` idempotency

Check failure on line 18 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

18:7 [indentation] wrong indentation: expected 8 but found 6
release_date: '2022-08-10'
0.0.5:
changes:
0.0.6:
changes:
minor_changes:
- Idempotency updates to cloud_api_key and datasource modules

Check failure on line 27 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

27:7 [indentation] wrong indentation: expected 8 but found 6
release_date: '2022-08-10'
0.0.7:
changes:
1.0.3:
changes:
minor_changes:
- Add a fail method to modules source code if `requests` library is not present

Check failure on line 48 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

48:7 [indentation] wrong indentation: expected 8 but found 6
- Fixed markup for arg option in Documentation
- Updated Documentation with `notes` to specify if the check_mode feature is
supported by modules
1.0.4:
changes:
bugfixes:
- Fixed cases where cloud_stack and alert_contact_point modules do not return

Check failure on line 57 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

57:7 [indentation] wrong indentation: expected 8 but found 6
a tuple when nothing in loop matches
major_changes:
- All modules except dashboard and datasource modules now support idempotency

Check failure on line 60 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

60:7 [indentation] wrong indentation: expected 8 but found 6
minor_changes:
- All modules use `missing_required_lib`` to compose the message for module.fail_json()

Check failure on line 62 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

62:7 [indentation] wrong indentation: expected 8 but found 6
when required library is missing from host
release_summary: Bug fixes and idempotency fixes for modules
release_date: '2022-11-01'
1.0.5:
changes:
minor_changes:
- Added Note to datasource and dashboard module about not supporting Idempotency

Check failure on line 69 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

69:7 [indentation] wrong indentation: expected 8 but found 6
release_summary: Add Note to modules which don't support Idempotency
release_date: '2022-11-10'
1.1.0:
changes:
major_changes:
- Added Role for Grafana Agent

Check failure on line 75 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

75:7 [indentation] wrong indentation: expected 8 but found 6
release_summary: Added Role to deploy Grafana Agent on linux hosts
release_date: '2022-11-22'
1.1.1:
changes:
minor_changes:
- Updated the return message in grafana.grafana.folder module

Check failure on line 81 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

81:7 [indentation] wrong indentation: expected 8 but found 6
release_summary: Updated return description and value for grafana.grafana.folder
module
release_date: '2023-02-08'
2.0.0:
changes:
major_changes:
- Added Lint support

Check failure on line 88 in changelogs/changelog.yaml

GitHub Actions / Perform Linting

88:7 [indentation] wrong indentation: expected 8 but found 6
- Configs for server, metrics, logs, traces, and integrations
- Installation of the latest version
- Local installations when internet connection is not allowed
---

Check failure on line 1 in meta/runtime.yml

GitHub Actions / Perform Linting

meta-runtime[unsupported-version]

'requires_ansible' key must refer to a currently supported version such as: >=2.14.0, >=2.15.0, >=2.16.0
requires_ansible: ">=2.12.0,<3.0.0"
version: "1.0.0"

Check failure on line 1 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: version)
arch_mapping:

Check failure on line 3 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: arch_mapping)
x86_64: amd64
aarch64: arm64
armv7l: armhf
i386: i386
ppc64le: ppc64le
arch: "{{ arch_mapping[ansible_architecture] | default('amd64') }}"

Check failure on line 10 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: arch)
binary_url: "https://github.com/grafana/alloy/releases/download/v{{ version }}/alloy-linux-{{ arch }}.zip"

Check failure on line 12 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: binary_url)
service_name: "alloy"

Check failure on line 14 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: service_name)
installation_dir: "/etc/alloy"

Check failure on line 16 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: installation_dir)
environment_file: "service.env"

Check failure on line 18 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: environment_file)
config_dir: "/etc/alloy"

Check failure on line 20 in roles/alloy/defaults/main.yml

GitHub Actions / Perform Linting

var-naming[no-role-prefix]

Variables names from within roles should use alloy_ as a prefix. (vars: config_dir)
config_file: "config.alloy"