Skip to content

Commit

Permalink
Merge branch 'main' into fix/dashboard-argument-message
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanjainn authored Oct 19, 2024
2 parents a4ffb6a + 3614c5f commit a3ad1d1
Show file tree
Hide file tree
Showing 36 changed files with 793 additions and 627 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/alloy-molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Alloy Molecule

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
working-directory: roles/alloy

jobs:
molecule:
name: Molecule
runs-on: ubuntu-latest
strategy:
matrix:
distro:
- rockylinux9
- ubuntu2204
- debian12

steps:
- name: Check out the codebase.
uses: actions/checkout@v4

- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install ansible molecule molecule-plugins[docker] docker

- name: Run Molecule tests.
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
./ @ishanjainn
/roles/grafana @gardar @ishanjainn
/roles/grafana_agent @ishanjainn @v-zhuravlev @gardar
/roles/alloy @ishanjainn @v-zhuravlev @gardar
/roles/alloy @ishanjainn @v-zhuravlev @gardar @voidquark
/roles/opentelemetry_collector @ishanjainn
/roles/loki @voidquark @ishanjainn
/roles/mimir @GVengelen @gardar @ishanjainn
Expand Down
648 changes: 332 additions & 316 deletions Pipfile.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![GitHub Last Commit](https://img.shields.io/github/last-commit/grafana/grafana-ansible-collection)](https://github.com/grafana/grafana-ansible-collection/tags)
[![GitHub Contributors](https://img.shields.io/github/contributors/grafana/grafana-ansible-collection)](https://github.com/grafana/grafana-ansible-collection/tags)

This collection (`grafana.grafana`) contains modules and roles to assist in automating the management of resources in **Grafana**, **Grafana Agent**, **OpenTelemetry Collector**, **Loki**, **Mimir**, and **Promtail** with Ansible.
This collection (`grafana.grafana`) contains modules and roles to assist in automating the management of resources in **Grafana**, **Grafana Agent**, **OpenTelemetry Collector**, **Loki**, **Mimir**, **Alloy**, and **Promtail** with Ansible.

- [Ansible collection Documentation](https://docs.ansible.com/ansible/latest/collections/grafana/grafana/)
- [Grafana](https://grafana.com)
Expand Down Expand Up @@ -43,10 +43,11 @@ collections:

## Roles included in the collection

This collection includes the following roles to help set up and manage Grafana, Grafana Agent, OpenTelemetry Collector, Loki, Mimir and Promtail:
This collection includes the following roles to help set up and manage Grafana, Grafana Agent, Alloy, OpenTelemetry Collector, Loki, Mimir and Promtail:

- **Grafana**: Installs and configures Grafana on your target hosts.
- **Grafana Agent**: Deploys and configures Grafana Agent, allowing for efficient metrics, logs, and trace data shipping to Grafana Cloud or other endpoints.
- **Alloy**: The replacement for Grafana Agent and Promtail. Alloy can be used to collect traces, metrics, and logs.
- **OpenTelemetry Collector**: Sets up and configures the OpenTelemetry Collector, enabling advanced observability features through data collection and transmission.
- **Loki**: Deploy and manage Loki, the log aggregation system.
- **Mimir**: Deploy and manage Mimir, the scalable long-term storage for Prometheus.
Expand Down
21 changes: 9 additions & 12 deletions examples/alloy.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
- name: Install alloy
---
- name: Deploy alloy
hosts: all
become: true

roles:
- role: grafana.grafana.alloy
tasks:
- name: Install alloy
- name: Deploy alloy
ansible.builtin.include_role:
name: grafana.grafana.alloy
vars:
config: |
alloy_config: |
prometheus.scrape "default" {
targets = [{"__address__" = "localhost:12345"}]
forward_to = [prometheus.remote_write.prom.receiver]
targets = [{"__address__" = "127.0.0.1:12345"}]
forward_to = [prometheus.remote_write.prom.receiver]
}
prometheus.remote_write "prom" {
endpoint {
url = "https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push"
basic_auth {
username = "1493467"
password = "glc_eyJvIjoiNjUyOTkyIiwibiI6InN0YWNrLTg5MDA0My1obS13cml0ZS1hc2FzIiwiayI6IjIwME9NeThmWlFpMGlmQzBGMTlJNDdqSiIsIm0iOnsiciI6InByb2QtdXMtZWFzdC0wIn19"
}
url = "http://mimir:9009/api/v1/push"
}
}
91 changes: 42 additions & 49 deletions roles/alloy/README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,59 @@
# Ansible Role for Alloy
# Ansible role - Alloy

[![License](https://img.shields.io/github/license/grafana/grafana-ansible-collection)](LICENSE)

This Ansible role to install and configure [Alloy](https://grafana.com/docs/alloy/latest/), which can be used to collect traces, metrics, and logs.
This role is tailored for operating systems such as **RedHat**, **Rocky Linux**, **AlmaLinux**, **Ubuntu**, and **Debian**.

## Requirements
## Table of Content

Please ensure that `curl` is intalled on Ansible controller.
- [Requirements](#requirements)
- [Role Variables](#role-variables)
- [Playbook](#playbook)

## Role Variables
## Requirements

Available variables with their default values are listed below (`defaults/main.yml`):
- Ansible 2.13+
- `ansible.utils` collection is required. Additionally, you must install the `netaddr` Python library on the host where you are running Ansible (not on the target remote host) if is not present.

## Role Variables

| Variable Name | Description | Default Value |
|-----------------------|----------------------------------------------------------------------|---------------------------------------------------------------------|
| `version` | The version of Grafana Alloy to be installed. | "1.0.0" |
| `arch_mapping` | A mapping of common architecture names to Grafana Alloy binaries. | `{'x86_64': 'amd64', 'aarch64': 'arm64', 'armv7l': 'armhf', 'i386': 'i386', 'ppc64le': 'ppc64le'}` |
| `arch` | The architecture of the current machine. | Based on `ansible_architecture` lookup, defaults to 'amd64'. |
| `binary_url` | URL to Grafana Alloy binary for the specific version and architecture. | Constructed URL based on `version` and `arch` variables. |
| `service_name` | The name to be used for the Grafana Alloy service. | "alloy" |
| `installation_dir` | Directory where Grafana Alloy binary is to be installed. Must be present. | "/usr/local/bin" |
| `environment_file` | Name of the environment file for the Grafana Alloy service. | "service.env" |
| `config_dir` | Directory for Grafana Alloy configuration. | "/etc/alloy" |
| `config_file` | Configuration file name for Grafana Alloy. | "config.alloy" |
| `service_user` | User under which the Grafana Alloy service will run. | "alloy" |
| `service_group` | Group under which the Grafana Alloy service will run. | "alloy" |
| `working_dir` | Working directory for the Grafana Alloy service. | "/var/lib/alloy" |
| `env_file_vars` | Additional environment variables to be set in the service environment file. | {} (Empty dictionary) |
| `alloy_flags_extra` | Extra flags to pass to the Alloy service. | {} (Empty dictionary) |
| `start_after_service` | Specify an optional dependency service Alloy should start after. | '' (Empty string) |
| `config` | Configuration template for Grafana Alloy. | Configuration script with Prometheus scrape and remote_write setup |
| `alloy_user_groups`. | Configurable user groups that the Grafana Alloy can be put in so that it can access logs. | `[]` |



## Example Playbook

Including an example of how to use your role:
| `alloy_version` | The version of Alloy to download and deploy. Supported standard version "1.4.2" format or "latest". | `latest` |
| `alloy_uninstall` | If set to `true` will perfom uninstall instead of deployment. | `false` |
| `alloy_expose_port` | By default, this is set to false. It supports only simple firewalld configurations. If set to true, a firewalld rule is added to expose the TCP alloy port. The Port is automatically extracted from the environment variable `alloy_env_file_vars` in CUSTOM_ARGS when --server.http.listen-addr=0.0.0.0:12345 is defined. If set to false, configuration is skipped. If the firewalld.service is not active, all firewalld tasks are skipped. | `false` |
| `alloy_user_groups` | Appends the alloy user to specific groups. | `[]` |
| `alloy_download_url_rpm` | The default download URL for the Alloy rpm package from GitHub. | `"https://github.com/grafana/alloy/releases/download/v{{ aloy_version }}/alloy-{{ aloy_version }}-1.{{ __alloy_arch }}.rpm"` |
| `alloy_download_url_deb` | The default download URL for the Alloy deb package from GitHub. | `"https://github.com/grafana/alloy/releases/download/v{{ aloy_version }}/alloy-{{ aloy_version }}-1.{{ __alloy_arch }}.deb"` |
| `alloy_env_file_vars` | You can use environment variables to control the run-time behavior of Grafana Alloy. | `{}` |
| `alloy_systemd_override` | Systemd unit drop-in file used to override or extend the default configuration of a systemd unit. | `{}` |
| `alloy_config` | This is the configuration that sets up Alloy. Refer to the [configuration blocks](https://grafana.com/docs/alloy/latest/reference/config-blocks/) and [components](https://grafana.com/docs/alloy/latest/reference/components/) documentation for more details. By default, there is no configuration provided, and it is required for successful deployment. Without it, the deployment will fail. Since the purpose of using Alloy varies, no default configuration is provided. ⚠️ **This configuration is mandatory.** | `{}` |

## Dependencies

No Dependencies

## Playbook

```yaml
- name: Install alloy
- name: Manage alloy service
hosts: all
become: true
vars:
# alloy_config: |
# Your Config Content
roles:
- role: grafana.grafana.alloy
```
- Playbook execution example
```shell
# Deploy Alloy
ansible-playbook function_alloy_play.yml

tasks:
- name: Install alloy
ansible.builtin.include_role:
name: grafana.grafana.alloy
vars:
config: |
prometheus.scrape "default" {
targets = [{"__address__" = "localhost:12345"}]
forward_to = [prometheus.remote_write.prom.receiver]
}
prometheus.remote_write "prom" {
endpoint {
url = "https://prometheus-prod-13-prod-us-east-0.grafana.net/api/prom/push"
basic_auth {
username = "149xxx"
password = "glc_xxx"
}
}
}
# Uninstall Alloy
ansible-playbook function_alloy_play.yml -e "alloy_uninstall=true"
```

## License
Expand All @@ -71,3 +63,4 @@ See [LICENSE](https://github.com/grafana/grafana-ansible-collection/blob/main/LI
## Author Information

- [Ishan Jain](https://github.com/ishanjainn)
- [VoidQuark](https://github.com/voidquark)
76 changes: 30 additions & 46 deletions roles/alloy/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,32 @@
version: "1.0.0"
---
# defaults file for alloy
alloy_version: "latest"
alloy_uninstall: false
alloy_expose_port: false
alloy_download_url_rpm: "https://github.com/grafana/alloy/releases/download/v{{ alloy_version }}/alloy-{{ alloy_version }}-1.{{ __alloy_arch }}.rpm"
alloy_download_url_deb: "https://github.com/grafana/alloy/releases/download/v{{ alloy_version }}/alloy-{{ alloy_version }}-1.{{ __alloy_arch }}.deb"

arch_mapping:
x86_64: amd64
aarch64: arm64
armv7l: armhf
i386: i386
ppc64le: ppc64le

arch: "{{ arch_mapping[ansible_architecture] | default('amd64') }}"

binary_url: "https://github.com/grafana/alloy/releases/download/v{{ version }}/alloy-linux-{{ arch }}.zip"

service_name: "alloy"

installation_dir: "/usr/local/bin"

environment_file: "service.env"

config_dir: "/etc/alloy"

config_file: "config.alloy"

service_user: "alloy"

service_group: "alloy"

working_dir: "/var/lib/alloy"

env_file_vars: {}

alloy_flags_extra: {}

start_after_service: ''

config: |
prometheus.scrape "default" {
targets = [{"__address__" = "localhost:12345"}]
forward_to = [prometheus.remote_write.prom.receiver]
}
prometheus.remote_write "prom" {
endpoint {
url = "http://mimir:9009/api/v1/push"
}
}
# Configurable user groups that the Grafana Alloy can be put in so that it can access logs.
alloy_user_groups: []
# alloy_user_groups:
# - "systemd-journal"

alloy_env_file_vars: {}
# alloy_env_file_vars:
# CUSTOM_ARGS: "--server.http.listen-addr=0.0.0.0:12345 --stability.level=public-preview --feature.community-components.enabled=true"

alloy_systemd_override: {}
# alloy_systemd_override: |
# [Service]
# User=root

alloy_config: {}
# alloy_config: |
# prometheus.scrape "default" {
# targets = [{"__address__" = "127.0.0.1:12345"}]
# forward_to = [prometheus.remote_write.prom.receiver]
# }
# prometheus.remote_write "prom" {
# endpoint {
# url = "http://mimir:9009/api/v1/push"
# }
# }
14 changes: 7 additions & 7 deletions roles/alloy/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
# handlers file for alloy
- name: Restart alloy
listen: "restart alloy"
ansible.builtin.systemd:
name: "{{ service_name }}"
daemon_reload: true
name: alloy.service
state: restarted
become: true
listen: "Restart alloy"

- name: Check alloy is started properly
ansible.builtin.include_tasks: ga-started.yml
listen: "Restart alloy"
enabled: true
when: not ansible_check_mode
19 changes: 11 additions & 8 deletions roles/alloy/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
---
galaxy_info:
author: Ishan Jain
role_name: alloy
author: Ishan Jain, voidquark
description: Role to Install and Configure Grafana Alloy
license: "GPL-3.0-or-later"
min_ansible_version: "2.11"
min_ansible_version: "2.13"
platforms:
- name: EL
versions:
- "8"
- "9"
- name: Fedora
versions:
- "all"
- all
- name: Debian
versions:
- "all"
- all
- name: Ubuntu
versions:
- "all"
- name: EL
versions:
- "all"
- all
galaxy_tags:
- grafana
- observability
Expand Down
17 changes: 17 additions & 0 deletions roles/alloy/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Converge
hosts: all
vars:
alloy_version: "1.4.2"
alloy_config: |
prometheus.scrape "default" {
targets = [{"__address__" = "127.0.0.1:12345"}]
forward_to = [prometheus.remote_write.prom.receiver]
}
prometheus.remote_write "prom" {
endpoint {
url = "http://mimir:9009/api/v1/push"
}
}
roles:
- role: grafana.grafana.alloy
20 changes: 20 additions & 0 deletions roles/alloy/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
dependency:
name: galaxy
options:
ignore-errors: true
driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux8}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
playbooks:
converge: converge.yml
Loading

0 comments on commit a3ad1d1

Please sign in to comment.