Skip to content

Commit af5a51e

Browse files
authored
Merge pull request #3 from inuits/master
Initial Cortex role
2 parents 0f497e8 + 431e09e commit af5a51e

File tree

16 files changed

+411
-18
lines changed

16 files changed

+411
-18
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2020 Pawel Krupa and Julien Pivotto
3+
Copyright (c) 2020 Pawel Krupa, Matthias Antierens and Julien Pivotto
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Description
99

10-
Deploy [cortex](https://github.com/prometheus/cortex) using ansible.
10+
Deploy [cortex](https://github.com/cortexproject/cortex) using ansible.
1111

1212
## Requirements
1313

@@ -19,7 +19,26 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
1919

2020
| Name | Default Value | Description |
2121
| -------------- | ------------- | -----------------------------------|
22-
| `cortex_web_listen_address` | "0.0.0.0:<<PORT>>" | Address on which cortex will listen |
22+
| `cortex_web_listen_address` | "0.0.0.0:9009" | Address on which cortex will listen |
23+
| `cortex_binary_local_dir` | "" | Allows to use local packages instead of ones distributed on github. As parameter it takes a directory where `cortex` binaries are stored on host on which ansible is ran. This overrides `cortex_version` parameter |
24+
| `cortex_interface` | "{{ ansible_default_ipv4.interface }}" | Network adapter that cortex will be using |
25+
| `cortex_config_dir` | "/etc/cortex" | Default directory for the cortex config |
26+
| `cortex_db_dir` | "/var/lib/cortex" | Path to the directory of the Cortex database |
27+
| `cortex_system_user` | "cortex" | Default Cortex user |
28+
| `cortex_system_group` | "cortex" | Default Cortex group |
29+
| `cortex_version` | "1.4.0-rc.1" | The cortex package version |
30+
| `cortex_auth_enabled` | "false" | Enables of disables the Cortex authentication |
31+
| `cortex_server` | [From block storage example][bse] | Cortex server. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#server_config) |
32+
| `cortex_distributor` | [From block storage example][bse] | Cortex distributor. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#distributor_config) |
33+
| `cortex_ingester_client` | [From block storage example][bse] | Cortex ingester client. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#ingester_client_config) |
34+
| `cortex_ingester` | [From block storage example][bse] | Cortex ingester. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#ingester_config) |
35+
| `cortex_storage` | [From block storage example][bse] | Cortex storage. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#storage_config) |
36+
| `cortex_blocks_storage` | [From block storage example][bse] | Cortex blocks storage. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#blocks_storage_config) |
37+
| `cortex_compactor` | [From block storage example][bse] | Cortex compactor. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#compactor_config) |
38+
| `cortex_frontend_worker` | [From block storage example][bse] | Cortex frontend worker. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#frontend_worker_config) |
39+
| `cortex_ruler` | [From block storage example][bse] | Cortex ruler. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#ruler_config) |
40+
41+
[bse]:https://github.com/cortexproject/cortex/blob/master/docs/configuration/single-process-config-blocks.yaml
2342

2443
## Example
2544

@@ -31,11 +50,6 @@ Use it in a playbook as follows:
3150
roles:
3251
- cloudalchemy.cortex
3352
```
34-
35-
### Demo site
36-
37-
We provide demo site for full monitoring solution based on prometheus and grafana. Repository with code and links to running instances is [available on github](https://github.com/prometheus/demo-site) and site is hosted on [DigitalOcean](https://digitalocean.com).
38-
3953
## Local Testing
4054
4155
The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/metacloud/molecule) (v2.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable to for your system.

defaults/main.yml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
---
2-
cortex_web_listen_address: "0.0.0.0:<<PORT>>"
2+
cortex_web_listen_address: "0.0.0.0:9009"
3+
cortex_binary_local_dir: ''
4+
cortex_skip_install: false
5+
6+
cortex_interface: "{{ ansible_default_ipv4.interface }}"
7+
8+
cortex_config_file: 'cortex.yml.j2'
9+
cortex_config_dir: /etc/cortex
10+
cortex_db_dir: /var/lib/cortex
11+
12+
cortex_system_user: "cortex"
13+
cortex_system_group: "cortex"
14+
15+
cortex_version: 1.4.0-rc.1
16+
17+
cortex_auth_enabled: false
18+
19+
cortex_server:
20+
http_listen_port: 9009
21+
22+
# Configure the server to allow messages up to 100MB.
23+
grpc_server_max_recv_msg_size: 104857600
24+
grpc_server_max_send_msg_size: 104857600
25+
grpc_server_max_concurrent_streams: 1000
26+
27+
cortex_distributor:
28+
shard_by_all_labels: true
29+
pool:
30+
health_check_ingesters: true
31+
32+
cortex_ingester_client:
33+
grpc_client_config:
34+
max_recv_msg_size: 104857600
35+
max_send_msg_size: 104857600
36+
grpc_compression: gzip
37+
38+
cortex_ingester:
39+
lifecycler:
40+
interface_names: [ "{{ cortex_interface }}" ]
41+
join_after: 0
42+
min_ready_duration: 0s
43+
final_sleep: 0s
44+
num_tokens: 512
45+
46+
ring:
47+
kvstore:
48+
store: inmemory
49+
replication_factor: 1
50+
51+
cortex_storage:
52+
engine: blocks
53+
54+
cortex_blocks_storage:
55+
tsdb:
56+
dir: /tmp/cortex/tsdb
57+
58+
bucket_store:
59+
sync_dir: /tmp/cortex/tsdb-sync
60+
61+
backend: filesystem
62+
filesystem:
63+
dir: ./data/tsdb
64+
65+
cortex_compactor:
66+
data_dir: /tmp/cortex/compactor
67+
sharding_ring:
68+
kvstore:
69+
store: inmemory
70+
71+
cortex_frontend_worker:
72+
match_max_concurrent: true
73+
74+
cortex_ruler:
75+
enable_api: true
76+
enable_sharding: false
77+
storage:
78+
type: local
79+
local:
80+
directory: "{{ cortex_config_dir }}/rules"

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
daemon_reload: true
66
name: cortex
77
state: restarted
8+
- name: reload cortex
9+
become: true
10+
systemd:
11+
name: cortex
12+
state: reloaded

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
galaxy_info:
3-
author: Julien Pivotto, Pawel Krupa
3+
author: Matthias Antierens, Julien Pivotto
44
description: Deploy cortex
55
role_name: cortex
66
license: MIT

molecule/alternative/playbook.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
2-
- hosts: all
2+
- name: Run role
3+
hosts: all
34
any_errors_fatal: true
45
roles:
56
- ansible-cortex
6-
vars: []
7+
vars:
8+
cortex_config_dir: /cortex
9+
cortex_db_dir: /cortexdb
10+
cortex_system_user: "vortex"
11+
cortex_system_group: "vortex"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
import pytest
22
import os
3+
import yaml
34
import testinfra.utils.ansible_runner
45

6+
57
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
68
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
9+
10+
11+
@pytest.fixture()
12+
def AnsibleDefaults():
13+
with open("../../defaults/main.yml", 'r') as stream:
14+
return yaml.load(stream)
15+
16+
17+
@pytest.mark.parametrize("dirs", [
18+
"/cortex",
19+
"/cortex/rules",
20+
"/cortexdb"
21+
])
22+
def test_directories(host, dirs):
23+
d = host.file(dirs)
24+
assert d.is_directory
25+
assert d.exists
26+
27+
28+
@pytest.mark.parametrize("files", [
29+
"/cortex/cortex.yml",
30+
"/etc/systemd/system/cortex.service",
31+
"/usr/local/bin/cortex-linux-amd64",
32+
])
33+
def test_files(host, files):
34+
f = host.file(files)
35+
assert f.exists
36+
assert f.is_file
37+
38+
39+
def test_user(host):
40+
assert host.group("vortex").exists
41+
assert host.user("vortex").exists
42+
43+
44+
def test_service(host):
45+
s = host.service("cortex")
46+
# assert s.is_enabled
47+
assert s.is_running
48+
49+
50+
def test_socket(host):
51+
s = host.socket("tcp://0.0.0.0:9009")
52+
assert s.is_listening

molecule/default/playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
- hosts: all
33
any_errors_fatal: true
44
roles:
5-
- ansible-cortex
5+
- name: ansible-cortex
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
1+
import pytest
12
import os
3+
import yaml
24
import testinfra.utils.ansible_runner
35

6+
47
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
58
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
9+
10+
11+
@pytest.fixture()
12+
def AnsibleDefaults():
13+
with open("../../defaults/main.yml", 'r') as stream:
14+
return yaml.load(stream)
15+
16+
17+
@pytest.mark.parametrize("dirs", [
18+
"/etc/cortex",
19+
"/etc/cortex/rules",
20+
"/var/lib/cortex"
21+
])
22+
def test_directories(host, dirs):
23+
d = host.file(dirs)
24+
assert d.is_directory
25+
assert d.exists
26+
27+
28+
@pytest.mark.parametrize("files", [
29+
"/etc/cortex/cortex.yml",
30+
"/etc/systemd/system/cortex.service",
31+
"/usr/local/bin/cortex-linux-amd64",
32+
])
33+
def test_files(host, files):
34+
f = host.file(files)
35+
assert f.exists
36+
assert f.is_file
37+
38+
39+
def test_user(host):
40+
assert host.group("cortex").exists
41+
assert host.user("cortex").exists
42+
43+
44+
def test_service(host):
45+
s = host.service("cortex")
46+
# assert s.is_enabled
47+
assert s.is_running
48+
49+
50+
def test_socket(host):
51+
s = host.socket("tcp://0.0.0.0:9009")
52+
assert s.is_listening

tasks/configure.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@
77
group: root
88
mode: 0644
99
notify: restart cortex
10+
11+
- name: configure cortex
12+
template:
13+
src: "{{ cortex_config_file }}"
14+
dest: "{{ cortex_config_dir }}/cortex.yml"
15+
force: true
16+
owner: root
17+
group: "{{ cortex_system_user }}"
18+
mode: 0640
19+
notify:
20+
- reload cortex

0 commit comments

Comments
 (0)