Skip to content

feat: Add prometheus role #23

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

Merged
merged 7 commits into from
May 30, 2024
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Fluence provider toolkit.
- [ccp](https://github.com/fluencelabs/ansible/tree/main/roles/ccp)
- [prerequisites](https://github.com/fluencelabs/ansible/tree/main/roles/prerequisites)
- [ipfs_cli](https://github.com/fluencelabs/ansible/tree/main/roles/ipfs_cli)
- [promtail](https://github.com/fluencelabs/ansible/tree/main/roles/promtail)
- [prometheus](https://github.com/fluencelabs/ansible/tree/main/roles/prometheus)
14 changes: 12 additions & 2 deletions molecule/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
nox_version: "0.22.0"
ccp_version: "0.2.0"
ipfs_cli_version: "0.25.0"

fluence_promtail_version: "2.9.5"
fluence_promtail_api_url: "http://localhost:80"
fluence_promtail_username: "foo"
fluence_promtail_password: "bar"

fluence_basicauth_username: "foo"
fluence_basicauth_password: "bar"

fluence_prometheus_version: "2.52.0"
fluence_prometheus_api_url: "http://localhost:80"

fluence_instance_id: "peer-0"
fluence_network: "molecule"
fluence_project_dir: "molecule"

collections:
Expand All @@ -24,3 +30,7 @@
- name: Run promtail role
include_role:
name: promtail

- name: Run prometheus role
include_role:
name: prometheus
3 changes: 3 additions & 0 deletions molecule/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"/opt/fluence/nox",
"/opt/fluence/ccp",
"/opt/fluence/promtail",
"/opt/fluence/prometheus",
])
def test_directories(host, directory):
d = host.file(directory)
Expand All @@ -23,6 +24,7 @@ def test_directories(host, directory):
"/opt/fluence/nox/Config.toml",
"/opt/fluence/ccp/Config.toml",
"/opt/fluence/promtail/config.yml",
"/opt/fluence/prometheus/config.yml",
])
def test_config(host, config):
d = host.file(config)
Expand All @@ -43,6 +45,7 @@ def test_ipfs_download(host):
"nox",
"ccp",
"fluence-promtail",
"fluence-prometheus",
])
def test_service_is_running(host, service):
service = host.service(service)
Expand Down
3 changes: 3 additions & 0 deletions roles/prometheus/.ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
skip_list:
- role-name
- fqcn-builtins
2 changes: 2 additions & 0 deletions roles/prometheus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**.zip
**.pyc
32 changes: 32 additions & 0 deletions roles/prometheus/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# vim:ft=yaml
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
81 changes: 81 additions & 0 deletions roles/prometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Fluence prometheus

Install, configure and maintain
[prometheus](https://prometheus.io)

You need to get `fluence_basicauth_username` and `fluence_basicauth_password` from Cloudless Labs in order to use this role.

## Role Variables

See
[defaults/](https://github.com/fluencelabs/ansible/blob/main/roles/prometheus/defaults/main.yml)
for details and examples.

#### `fluence_prometheus_api_url`

- URL of Mimir to send metrics to
- type: string
- default: "https://mimir.fluence.dev/loki/api/v1/push"

#### `fluence_basicauth_username`

- basic auth username you get from Cloudless Labs to auth to Mimir.
- type: string

#### `fluence_basicauth_password`

- basic auth password you get from Cloudless Labs to auth to Mimir.
- type: string

#### `fluence_prometheus_config`

- main
[configuration](https://prometheus.io/docs/prometheus/latest/configuration/configuration/)
file. Predefined and managed by Cloudless Labs.
- default: please see
[defaults/main.yml](https://github.com/fluencelabs/ansible/blob/main/roles/prometheus/defaults/main.yml)
- type: map

#### `fluence_prometheus_version`

- version to use
- type: string

#### `fluence_network`

- where it runs (kras or dar)
- type: string

#### `fluence_instance_id`

- instance id used as `instance` label in metrics
- type: string

#### `fluence_prometheus_user`

- owner of prometheus process and files
- default: `prometheus`
- type: string

#### `fluence_prometheus_group`

- group of `fluence_prometheus_user`
- default: `prometheus`
- type: string

#### `fluence_prometheus_download_url`

- url to get prometheus archive from
- default: `https://github.com/prometheus/prometheus/releases`
- type: string

#### `fluence_prometheus_unit`

- systemd unit file
- default: see
[defaults/main.yml](https://github.com/fluencelabs/ansible/blob/main/roles/prometheus/defaults/main.yml)
- type: string

## Author

- **Anatolios Laskaris** - [nahsi](https://github.com/nahsi)
51 changes: 51 additions & 0 deletions roles/prometheus/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
fluence_prometheus_download_url: "https://github.com/prometheus/prometheus/releases"

fluence_prometheus_api_url: "https://mimir.fluence.dev/api/v1/push"

fluence_prometheus_group: "prometheus"
fluence_prometheus_user: "prometheus"

fluence_prometheus_dir: "/opt/fluence/prometheus"

fluence_prometheus_unit: |
[Unit]
Description="Metrics collection agent"
Documentation=https://prometheus.io/docs/
After=network.target

[Service]
User={{ fluence_prometheus_user }}
Group={{ fluence_prometheus_group }}
ExecStart={{ fluence_prometheus_dir }}/prometheus --config.file {{ fluence_prometheus_dir }}/config.yml --web.listen-address=0.0.0.0:9898 --enable-feature=agent,expand-external-lables --storage.agent.path={{ fluence_prometheus_dir }}/data
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=control-group

[Install]
WantedBy=multi-user.target

fluence_prometheus_config:
global:
scrape_interval: "15s"
external_labels:
env: "{{ fluence_network }}"
network: "{{ fluence_network }}"

remote_write:
- url: "{{ fluence_prometheus_api_url }}"
basic_auth:
username: "{{ fluence_basicauth_username }}"
password: "{{ fluence_basicauth_password }}"

scrape_configs:
- job_name: 'nox'
static_configs:
- targets: ['localhost:18080']
labels:
instance: "{{ fluence_instance_id }}"

- job_name: 'ccp'
static_configs:
- targets: ['localhost:9384']
labels:
instance: "{{ fluence_instance_id }}"
10 changes: 10 additions & 0 deletions roles/prometheus/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: restart prometheus
ansible.builtin.systemd:
name: fluence-prometheus
state: restarted
daemon_reload: true

- name: reload prometheus
ansible.builtin.systemd:
name: fluence-prometheus
state: reloaded
21 changes: 21 additions & 0 deletions roles/prometheus/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
galaxy_info:
namespace: fluencelabs
role_name: prometheus
license: Apache-2.0
author: Anatolios Laskaris
description: Install prometheus agent
issue_tracker_url: https://github.com/fluencelabs/ansible/issues
min_ansible_version: "2.12"

platforms:
- name: Ubuntu
versions:
- jammy
- name: Debian
versions:
- bookworm

galaxy_tags:
- metrics
- fluence
- web3
93 changes: 93 additions & 0 deletions roles/prometheus/tasks/00-preflight.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
- name: check "fluence_prometheus_version" variable
tags: always
ansible.builtin.assert:
that:
- fluence_prometheus_version is defined
- fluence_prometheus_version is string
- fluence_prometheus_version | length
- fluence_prometheus_version is regex(_semver_regex)
quiet: true

- name: check "fluence_prometheus_download_url" variable
tags: always
ansible.builtin.assert:
that:
- fluence_prometheus_download_url is defined
- fluence_prometheus_download_url is string
- fluence_prometheus_download_url | length
quiet: true

- name: check "fluence_prometheus_api" variable
tags: always
ansible.builtin.assert:
that:
- fluence_prometheus_api_url is defined
- fluence_prometheus_api_url is string
- fluence_prometheus_api_url | length
quiet: true

- name: check "fluence_basicauth_username" variable
tags: always
ansible.builtin.assert:
that:
- fluence_basicauth_username is defined
- fluence_basicauth_username is string
- fluence_basicauth_username | length
quiet: true

- name: check "fluence_basicauth_password" variable
tags: always
ansible.builtin.assert:
that:
- fluence_basicauth_password is defined
- fluence_basicauth_password is string
- fluence_basicauth_password | length
quiet: true

- name: check "fluence_network" variable
tags: always
ansible.builtin.assert:
that:
- fluence_network is defined
- fluence_network is string
- fluence_network | length
quiet: true

- name: check "fluence_instance_id" variable
tags: always
ansible.builtin.assert:
that:
- fluence_instance_id is defined
- fluence_instance_id is string
- fluence_instance_id | length
quiet: true

- name: check if "{{ fluence_prometheus_download_url }}" is online
become: false
run_once: true
delegate_to: localhost
uri:
url: "{{ fluence_prometheus_download_url }}"
status_code: 200
register: _result
retries: 3
delay: 5
until: _result.status == 200

- name: check "fluence_prometheus_config" variable
tags: always
ansible.builtin.assert:
that:
- fluence_prometheus_config is defined
- fluence_prometheus_config is mapping
- fluence_prometheus_config | length
quiet: true

- name: check "fluence_prometheus_unit" variable
tags: always
ansible.builtin.assert:
that:
- fluence_prometheus_unit is defined
- fluence_prometheus_unit is string
- fluence_prometheus_unit | length
quiet: true
Loading
Loading