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

Add tempo role #323

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
73 changes: 73 additions & 0 deletions roles/tempo/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
# defaults file for tempo
tempo_version: "latest"
tempo_uninstall: false
__tempo_arch: "{{ arch_mapping[ansible_facts['architecture']] | default('amd64') }}"
tempo_download_url_rpm: "https://github.com/grafana/tempo/releases/download/v{{ tempo_version }}/tempo_{{ tempo_version }}_linux_{{ __tempo_arch }}.rpm"
tempo_download_url_deb: "https://github.com/grafana/tempo/releases/download/v{{ tempo_version }}/tempo_{{ tempo_version }}_linux_{{ __tempo_arch }}.deb"
tempo_working_path: "/var/lib/tempo"
tempo_http_listen_port: 3200
tempo_http_listen_address: "0.0.0.0"
tempo_log_level: warn
tempo_report_usage: true
tempo_multitenancy_enabled: false

# Default Variables from /etc/tempo/config.yml
tempo_server:
http_listen_port: "{{ tempo_http_listen_port }}"
http_listen_address: "{{ tempo_http_listen_address }}"
log_level: "{{ tempo_log_level }}"

tempo_query_frontend:
search:
duration_slo: 5s
throughput_bytes_slo: 1.073741824e+09
metadata_slo:
duration_slo: 5s
throughput_bytes_slo: 1.073741824e+09
trace_by_id:
duration_slo: 5s

tempo_distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: "{{ tempo_http_listen_address }}:4317"

tempo_metrics_generator:
registry:
external_labels:
source: tempo
cluster: docker-compose
storage:
path: "{{ tempo_working_path }}/generator/wal"
remote_write:
- url: http://prometheus:9090/api/v1/write
send_exemplars: true
traces_storage:
path: "{{ tempo_working_path }}/generator/traces"

tempo_storage:
trace:
backend: local # backend configuration to use
wal:
path: "{{ tempo_working_path }}/wal" # where to store the wal locally
local:
path: "{{ tempo_working_path }}/blocks"

tempo_overrides:
defaults:
metrics_generator:
processors: [service-graphs, span-metrics, local-blocks] # enables metrics generator
generate_native_histograms: both

# Additional Config Variables for /etc/tempo/config.yml
# tempo_ingester:
# tempo_ingester_client:
# tempo_metrics_generator_client:
# tempo_querier:
# tempo_compactor:
# tempo_storage:
# tempo_memberlist:
# tempo_cache:
6 changes: 6 additions & 0 deletions roles/tempo/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- name: Restart tempo
ansible.builtin.systemd:
name: tempo.service
state: restarted
28 changes: 28 additions & 0 deletions roles/tempo/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
galaxy_info:
role_name: tempo
author: Grafana
description: Manage Grafana Tempo Application
license: "GPL-3.0-or-later"
min_ansible_version: "2.10"
platforms:
- name: EL
versions:
- "8"
- "9"
- name: Fedora
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- tempo
- grafana
- tracing
- monitoring

dependencies: []
5 changes: 5 additions & 0 deletions roles/tempo/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: grafana.grafana.tempo
20 changes: 20 additions & 0 deletions roles/tempo/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
98 changes: 98 additions & 0 deletions roles/tempo/tasks/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
# tasks file for Tempo deployment
- name: Obtain the latest version from the Tempo GitHub repo
when: tempo_version == "latest"
block:
- name: Scrape Github API endpoint to obtain latest Tempo version
ansible.builtin.uri:
url: "https://api.github.com/repos/grafana/tempo/releases/latest"
method: GET
body_format: json
become: false
delegate_to: localhost
run_once: true
register: __github_latest_version

- name: Latest available Tempo version
ansible.builtin.set_fact:
tempo_version: "{{ __github_latest_version.json.tag_name | regex_replace('^v?(\\d+\\.\\d+\\.\\d+)$', '\\1') }}"

- name: Verify current deployed version
block:
- name: Check if Tempo binary is present
ansible.builtin.stat:
path: "/usr/bin/tempo"
register: __already_deployed

- name: Obtain current deployed Tempo version
ansible.builtin.command:
cmd: "/usr/bin/tempo --version"
changed_when: false
register: __current_deployed_version
when: __already_deployed.stat.exists | bool

- name: Include RedHat/Rocky setup
ansible.builtin.include_tasks:
file: setup-Redhat.yml
when: ansible_facts['os_family'] in ['RedHat', 'Rocky']

- name: Include Debian/Ubuntu setup
ansible.builtin.include_tasks:
file: setup-Debian.yml
when: ansible_facts['os_family'] == 'Debian'

- name: Check if Tempo default dir is present
ansible.builtin.stat:
path: "/tmp/tempo/boltdb-shipper-active"
register: __default_structure

- name: Default structure cleanup
when: __default_structure.stat.exists | bool
block:
- name: Ensure that Tempo is stopped before default cleanup
ansible.builtin.systemd:
name: tempo.service
state: stopped

- name: Remove default configuration from "/tmp/tempo" directory
ansible.builtin.file:
path: "/tmp/tempo"
state: absent

- name: Ensure that Tempo working path exists
ansible.builtin.file:
path: "{{ tempo_working_path }}"
state: directory
owner: "tempo"
group: "root"
mode: "0755"

- name: Template Tempo config - /etc/tempo/config.yml
ansible.builtin.template:
src: "config.yml.j2"
dest: "/etc/tempo/config.yml"
owner: "tempo"
group: "root"
mode: "0644"
validate: "/usr/bin/tempo -config.verify %s"
notify: Restart tempo

- name: Ensure restart has completed
ansible.builtin.meta: flush_handlers

- name: Ensure that Tempo is started
ansible.builtin.systemd:
name: tempo.service
state: started
enabled: true

- name: Verify that Tempo URL is responding
ansible.builtin.uri:
url: "http://{{ tempo_http_listen_address }}:{{ tempo_http_listen_port }}/ready"
method: GET
register: tempo_verify_url_status_code
retries: 5
delay: 8
until: tempo_verify_url_status_code.status == 200
when:
- not ansible_check_mode
9 changes: 9 additions & 0 deletions roles/tempo/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: Deploy Tempo service
ansible.builtin.include_tasks:
file: "deploy.yml"
when: not tempo_uninstall

- name: Uninstall Tempo service
ansible.builtin.include_tasks:
file: "uninstall.yml"
when: tempo_uninstall
7 changes: 7 additions & 0 deletions roles/tempo/tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: APT - Install Tempo
ansible.builtin.apt:
deb: "{{ tempo_download_url_deb }}"
state: present
notify: Restart tempo
when: __current_deployed_version.stdout is not defined or tempo_version not in __current_deployed_version.stdout
8 changes: 8 additions & 0 deletions roles/tempo/tasks/setup-Redhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: DNF - Install Tempo from remote URL
ansible.builtin.dnf:
name: "{{ tempo_download_url_rpm }}"
state: present
disable_gpg_check: true
notify: Restart tempo
when: __current_deployed_version.stdout is not defined or tempo_version not in __current_deployed_version.stdout
43 changes: 43 additions & 0 deletions roles/tempo/tasks/uninstall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# tasks file for tempo uninstall

- name: Stop Tempo service
ansible.builtin.systemd: # noqa ignore-errors
name: tempo
state: stopped
ignore_errors: true

- name: Uninstall Tempo rpm package
ansible.builtin.dnf:
name: "tempo"
state: absent
autoremove: true
when: ansible_facts['os_family'] in ['RedHat', 'Rocky']

- name: Uninstall Tempo deb package
ansible.builtin.apt:
name: "tempo"
state: absent
purge: true
when: ansible_facts['os_family'] == 'Debian'

- name: Remove Tempo directories"
ansible.builtin.file:
path: "{{ remove_me }}"
state: absent
loop:
- "/etc/tempo"
- "{{ tempo_working_path }}"
loop_control:
loop_var: remove_me

- name: Remove the Tempo system user
ansible.builtin.user:
name: "tempo"
force: true
state: absent

- name: Remove Tempo system group
ansible.builtin.group:
name: "tempo"
state: absent
57 changes: 57 additions & 0 deletions roles/tempo/templates/config.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
server:
{{ tempo_server | to_nice_yaml(indent=2, sort_keys=False) | indent(2, False) }}
{% if tempo_distributor is defined %}
distributor:
{{ tempo_distributor | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_ingester is defined %}
ingester:
{{ tempo_ingester | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_ingester_client is defined %}
ingester_client:
{{ tempo_ingester_client | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_metrics_generator is defined %}
metrics_generator:
{{ tempo_metrics_generator | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_metrics_generator_client is defined %}
metrics_generator_client:
{{ tempo_metrics_generator_client | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_querier is defined %}
querier:
{{ tempo_querier | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_query_frontend is defined %}
query_frontend:
{{ tempo_query_frontend | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_compactor is defined %}
compactor:
{{ tempo_compactor | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_storage is defined %}
storage:
{{ tempo_storage | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_memberlist is defined %}
memberlist:
{{ tempo_memberlist | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_overrides is defined %}
overrides:
{{ tempo_overrides | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_cache is defined %}
cache:
{{ tempo_cache | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}
{% if tempo_http_api_prefix is defined %}
http_api_prefix: {{ tempo_http_api_prefix }}
{% endif %}
usage_report:
reporting_enabled: {{ tempo_report_usage }}
multitenancy_enabled: {{ tempo_multitenancy_enabled }}
6 changes: 6 additions & 0 deletions roles/tempo/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__tempo_arch_map:
x86_64: 'amd64'
armv6l: 'arm'
armv7l: 'arm'
aarch64: 'arm64'
__tempo_arch: "{{ __tempo_arch_map[ansible_facts['architecture']] | default(ansible_facts['architecture']) }}"