Skip to content

Commit

Permalink
Telemetry ansible.
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht9277 committed Nov 14, 2024
1 parent 276c152 commit e894c80
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 19 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1193,3 +1193,12 @@ ansible_operator_deploy: ## Deploy the Operator. Parameters: INVENTORY
-i $(INVENTORY) \
-e "ecdsa_keystore_path=$(ECDSA_KEYSTORE)" \
-e "bls_keystore_path=$(BLS_KEYSTORE)"

ansible_telemetry_create_env:
@cp -n infra/ansible/playbooks/ini/config-telemetry.ini.example infra/ansible/playbooks/ini/config-telemetry.ini
@echo "Config files for Telemetry created in infra/ansible/playbooks/ini"
@echo "Please complete the values and run make ansible_telemetry_deploy"

ansible_telemetry_deploy:
@ansible-playbook infra/ansible/playbooks/telemetry.yaml \
-i $(INVENTORY)
33 changes: 14 additions & 19 deletions infra/ansible/playbooks/elixir.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
- name: Elixir Setup
hosts: all
become: true
hosts: "{{ host }}"
vars:
user: "{{ user }}"
erlang_version: 26.0
elixir_version: 1.16.2-otp-26

tasks:
# Install required packages
- name: Update apt and install required system packages
become: true
apt:
pkg:
- build-essential
- autoconf
- m4
- libncurses5-dev
- libwxgtk3.0-gtk3-dev
- libwxgtk-webview3.0-gtk3-dev
- libwxgtk3.2-dev
- libwxgtk-webview3.2-dev
- libgl1-mesa-dev
- libglu1-mesa-dev
- libpng-dev
Expand All @@ -26,44 +25,40 @@
- fop
- libxml2-utils
- libncurses-dev
- openjdk-11-jdk
- openjdk-17-jdk
state: latest
update_cache: true
vars:
ansible_ssh_user: "{{ admin_user }}"

- name: Clone asdf repository into ~/.asdf
ansible.builtin.git:
name: https://github.com/asdf-vm/asdf.git
dest: ~/.asdf
single_branch: yes
version: v0.14.0
become_user: "{{ user }}"

- name: Insert lines to ~/.bashrc to source asdf
ansible.builtin.blockinfile:
path: "/home/{{ user }}/.bashrc"
path: "/home/{{ ansible_user }}/.bashrc"
block: |
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
become_user: "{{ user }}"

# - name: Add asdf to the shell
# shell: export ASDF_DIR="$HOME/.asdf" && . ~/.asdf/asdf.sh
# become_user: "{{ user }}"
- name: Add Erlang plugin to asdf
shell: asdf plugin add erlang
shell: /home/app/.asdf/bin/asdf plugin add erlang

- name: Add Erlang version to asdf
shell: asdf install erlang {{ erlang_version }}
shell: /home/app/.asdf/bin/asdf install erlang {{ erlang_version }}

- name: Set Erlang version as global
shell: asdf global erlang {{ erlang_version }}
shell: /home/app/.asdf/bin/asdf global erlang {{ erlang_version }}

- name: Add Elixir plugin to asdf
shell: asdf plugin add elixir
shell: /home/app/.asdf/bin/asdf plugin add elixir

- name: Add Elixir version to asdf
shell: asdf install elixir {{ elixir_version }}
shell: /home/app/.asdf/bin/asdf install elixir {{ elixir_version }}

- name: Set Elixir version as global
shell: asdf global elixir {{ elixir_version }}
shell: /home/app/.asdf/bin/asdf global elixir {{ elixir_version }}
6 changes: 6 additions & 0 deletions infra/ansible/playbooks/ini/config-telemetry.ini.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[global]
telemetry_api_url=
aligned_aggregator_prometheus_ip=
aligned_operator_prometheus_ip=
aligned_batcher_prometheus_ip=
aligned_tracker_prometheus_ip=
202 changes: 202 additions & 0 deletions infra/ansible/playbooks/telemetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
- name: Run setup playbook
ansible.builtin.import_playbook: setup.yaml
vars:
host: telemetry

- name: Run elixir playbook
ansible.builtin.import_playbook: elixir.yaml # fix!
vars:
host: telemetry

- name: Setup Telemetry
hosts: telemetry
become: true

vars:
prometheus_version: "2.53.2"
ansible_ssh_user: admin

tasks:
# install prometeus
# add config template to set server's IP (ini file)
# grafana
# config
# OpenTelemetry Collector
# install Jaeger
# install Cassandra
# install postgres
# install aligned Telemetry api
# install caddy
# add template for caddyfile for grafana (public) and Jaeger (tailscale)

- name: Install dependencies
apt:
name:
- apt-transport-https
- software-properties-common
- wget
state: present
update_cache: yes

- name: Create keyrings directory for Grafana
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'

- name: Download and install Grafana GPG key
shell:
cmd: wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor -o /etc/apt/keyrings/grafana.gpg
creates: /etc/apt/keyrings/grafana.gpg

- name: Add Grafana stable repository
shell:
cmd: echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
creates: /etc/apt/sources.list.d/grafana.list

- name: Update apt cache and install Grafana
apt:
name: grafana
state: present
update_cache: yes

- name: Check if Prometheus is installed
stat:
path: /usr/local/bin/prometheus
register: prometheus_exists

- name: Create Prometheus group
when: not prometheus_exists.stat.exists
group:
name: prometheus
system: yes

- name: Create Prometheus user
when: not prometheus_exists.stat.exists
user:
name: prometheus
group: prometheus
shell: /sbin/nologin
system: yes

- name: Download Prometheus
when: not prometheus_exists.stat.exists
get_url:
url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz"
dest: "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
mode: '0644'

- name: Extract Prometheus
when: not prometheus_exists.stat.exists
unarchive:
src: "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
dest: /tmp/
remote_src: yes

- name: Create Prometheus directories
when: not prometheus_exists.stat.exists
file:
path: "{{ item }}"
state: directory
owner: prometheus
group: prometheus
mode: '0755'
loop:
- /etc/prometheus
- /var/lib/prometheus

- name: Move Prometheus
when: not prometheus_exists.stat.exists
copy:
remote_src: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: prometheus
group: prometheus
mode: '0755'
with_items:
- { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/prometheus", dest: "/usr/local/bin/prometheus" }
- { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/promtool", dest: "/usr/local/bin/promtool" }

- name: Move Prometheus configuration and consoles
when: not prometheus_exists.stat.exists
copy:
remote_src: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: prometheus
group: prometheus
mode: '0755'
with_items:
- { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/consoles", dest: "/etc/prometheus/consoles" }
- { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/console_libraries", dest: "/etc/prometheus/console_libraries" }
- { src: "/tmp/prometheus-{{ prometheus_version }}.linux-amd64/prometheus.yml", dest: "/etc/prometheus/prometheus.yml" }

- name: Clean up Prometheus tar and extracted directory
when: not prometheus_exists.stat.exists
file:
path: "{{ item }}"
state: absent
loop:
- "/tmp/prometheus-{{ prometheus_version }}.tar.gz"
- "/tmp/prometheus-{{ prometheus_version }}.linux-amd64"

- name: Add prometheus config file
template:
src: prometheus/prometheus.yaml.j2
dest: /etc/prometheus/prometheus.yml
vars:
aligned_aggregator_prometheus_ip: "{{ lookup('ini', 'aligned_aggregator_prometheus_ip', file='ini/config-telemetry.ini') }}"
aligned_operator_prometheus_ip: "{{ lookup('ini', 'aligned_operator_prometheus_ip', file='ini/config-telemetry.ini') }}"
aligned_batcher_prometheus_ip: "{{ lookup('ini', 'aligned_batcher_prometheus_ip', file='ini/config-telemetry.ini') }}"
aligned_tracker_prometheus_ip: "{{ lookup('ini', 'aligned_tracker_prometheus_ip', file='ini/config-telemetry.ini') }}"

- name: Add grafana config file
template:
src: grafana.ini.j21
dest: /etc/grafana/grafana.ini

- name: Add Caddy repository to sources list
become: true
apt_repository:
repo:
"deb https://dl.cloudsmith.io/public/caddy/stable/deb/debian
any-version main"
state: present
filename: caddy-stable
vars:
ansible_ssh_user: "{{ admin_user }}"

- name: Add Caddy src repository to sources list
become: true
apt_repository:
repo:
"deb-src https://dl.cloudsmith.io/public/caddy/stable/deb/debian
any-version main"
state: present
filename: caddy-stable
vars:
ansible_ssh_user: "{{ admin_user }}"

- name: Install Caddy
become: true
apt:
update_cache: yes
name: caddy
state: present
vars:
ansible_ssh_user: "{{ admin_user }}"

- name: Add caddyfile config
become: true
template:
src: caddy/Caddyfile.telemetry.j2
dest: /etc/caddy/Caddyfile
vars:
telemetry_api_url: "{{ lookup('ini', 'telemetry_api_url', file='ini/config-telemetry.ini') }}"

handlers:
- name: Restart Grafana
service:
name: grafana-server
state: restarted
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ telemetry_api_url }} {
# reference https://gist.github.com/vocuzi/5cb835dde177cf892e2ca1a03c2a443f
@whitelisted {
path /versions*
}
reverse_proxy @whitelisted localhost:4001
}
7 changes: 7 additions & 0 deletions infra/ansible/stage_inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ batcher:
admin_user: admin
ansible_user: app
ansible_python_interpreter: /usr/bin/python3
telemetry:
hosts:
aligned-holesky-stage-1-telemetry:
ansible_host: aligned-holesky-stage-1-telemetry
admin_user: admin
ansible_user: app
ansible_python_interpreter: /usr/bin/python3
# explorer:
# hosts:
# aligned-holesky-explorer:
Expand Down

0 comments on commit e894c80

Please sign in to comment.