Skip to content

Commit fd9dd5b

Browse files
Added environment variables support (#13)
* WIP adding environment variable option * Added loop for Jaeger environment variables * Jaeger environment variabels for cortex sevices * Fixed environment file for not all in one usecase * Added correct loop for the multiple services * Added services test to circleci * Added back default test port * fix for ci * Added tests for checking content of environment files * fixed linting * changed variable and added more tests * Added backslash n for checking new lines * Updated the README with environment variable option
1 parent 85d25cb commit fd9dd5b

File tree

14 files changed

+94
-5
lines changed

14 files changed

+94
-5
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ jobs:
3535
else
3636
echo 'No alternative test'
3737
fi
38+
- run: |
39+
if [[ -d 'molecule/services' ]]; then
40+
molecule test -s services --destroy never
41+
else
42+
echo 'No services test'
43+
fi
3844
- run: |
3945
if [[ -z "${CIRCLE_PULL_REQUEST}" ]]; then
4046
molecule test -s latest --destroy never

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
3131
| `cortex_system_group` | "cortex" | Default Cortex group |
3232
| `cortex_version` | "1.6.0" | The cortex package version |
3333
| `cortex_auth_enabled` | "false" | Enables of disables the Cortex authentication |
34+
| `cortex_env_variables` | `{}` | Configure Cortex environment variables. |
3435
| `cortex_alertmanager` | `{}` | Cortex alertmanager. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/#alertmanager_config) |
3536
| `cortex_api` | `{}` | Cortex api. Compatible with [official configuration](https://cortexmetrics.io/docs/configuration/configuration-file/) |
3637
| `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) |
@@ -95,6 +96,11 @@ You can run the different Cortex modules as separate services by setting
9596
kvstore:
9697
store: inmemory
9798
replication_factor: 1
99+
cortex_env_variables:
100+
ingester:
101+
JAEGER_AGENT_HOST: localhost
102+
JAEGER_SAMPLER_PARAM: 0
103+
JAEGER_SAMPLER_TYPE: const
98104
```
99105

100106
## Local Testing

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ cortex_system_group: "cortex"
2020

2121
cortex_auth_enabled: false
2222

23+
cortex_environment_location: /etc/default
24+
cortex_env_variables: {}
25+
2326
cortex_server:
2427
http_listen_port: 9009
2528

molecule/alternative/playbook.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
cortex_db_dir: /cortexdb
1010
cortex_system_user: "vortex"
1111
cortex_system_group: "vortex"
12+
cortex_env_variables:
13+
KAEGER_AGENT_HOST: localhost
14+
KAEGER_SAMPLER_PARAM: 0
15+
KAEGER_SAMPLER_TYPE: const

molecule/alternative/tests/test_alternative.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_directories(host, dirs):
2929
"/cortex/cortex.yml",
3030
"/etc/systemd/system/cortex.service",
3131
"/usr/local/bin/cortex-linux-amd64",
32+
"/etc/default/cortex",
3233
])
3334
def test_files(host, files):
3435
f = host.file(files)
@@ -50,3 +51,10 @@ def test_service(host):
5051
def test_socket(host):
5152
s = host.socket("tcp://0.0.0.0:9009")
5253
assert s.is_listening
54+
55+
56+
def test_string(host):
57+
f = host.file("/etc/default/cortex")
58+
assert "KAEGER_AGENT_HOST=localhost\n" in f.content_string
59+
assert "KAEGER_SAMPLER_PARAM=0\n" in f.content_string
60+
assert "KAEGER_SAMPLER_TYPE=const\n" in f.content_string

molecule/services/molecule.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,44 @@ dependency:
33
name: galaxy
44
driver:
55
name: docker
6-
lint: |
7-
set -e
8-
yamllint .
9-
ansible-lint
10-
flake8
116
platforms:
127
- name: bionic
8+
pre_build_image: true
139
image: quay.io/paulfantom/molecule-systemd:ubuntu-18.04
1410
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
1511
privileged: true
1612
volumes:
1713
- /sys/fs/cgroup:/sys/fs/cgroup:ro
1814
- name: xenial
15+
pre_build_image: true
1916
image: quay.io/paulfantom/molecule-systemd:ubuntu-16.04
2017
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
2118
privileged: true
2219
volumes:
2320
- /sys/fs/cgroup:/sys/fs/cgroup:ro
2421
- name: stretch
22+
pre_build_image: true
2523
image: quay.io/paulfantom/molecule-systemd:debian-9
2624
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
2725
privileged: true
2826
volumes:
2927
- /sys/fs/cgroup:/sys/fs/cgroup:ro
3028
- name: buster
29+
pre_build_image: true
3130
image: quay.io/paulfantom/molecule-systemd:debian-10
3231
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
3332
privileged: true
3433
volumes:
3534
- /sys/fs/cgroup:/sys/fs/cgroup:ro
3635
- name: centos7
36+
pre_build_image: true
3737
image: quay.io/paulfantom/molecule-systemd:centos-7
3838
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
3939
privileged: true
4040
volumes:
4141
- /sys/fs/cgroup:/sys/fs/cgroup:ro
4242
- name: centos8
43+
pre_build_image: true
4344
image: quay.io/paulfantom/molecule-systemd:centos-8
4445
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
4546
privileged: true
@@ -48,6 +49,7 @@ platforms:
4849
groups:
4950
- python3
5051
- name: fedora
52+
pre_build_image: true
5153
image: quay.io/paulfantom/molecule-systemd:fedora-30
5254
docker_host: "${DOCKER_HOST:-unix://var/run/docker.sock}"
5355
privileged: true

molecule/services/playbook.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@
4242
backend: filesystem
4343
filesystem:
4444
dir: /tmp/blocks
45+
cortex_env_variables:
46+
ingester:
47+
KAEGER_AGENT_HOST: localhost
48+
KAEGER_SAMPLER_PARAM: 0
49+
KAEGER_SAMPLER_TYPE: const
50+
readpath:
51+
KAEGER_AGENT_HOST: localhost
52+
KAEGER_SAMPLER_PARAM: 0.1
53+
KAEGER_SAMPLER_TYPE: probabilistic

molecule/services/tests/test_services.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_directories(host, dirs):
2929
"/cortex/cortex-ingester.yml",
3030
"/etc/systemd/system/[email protected]",
3131
"/usr/local/bin/cortex-linux-amd64",
32+
"/etc/default/cortex-ingester",
3233
])
3334
def test_files(host, files):
3435
f = host.file(files)
@@ -63,3 +64,17 @@ def test_config_file_explicit_target(host):
6364
f = host.file("/cortex/cortex-readpath.yml")
6465
config = yaml.load(f.content_string, Loader=yaml.SafeLoader)
6566
assert config["target"] == "querier,store-gateway"
67+
68+
69+
def test_string(host):
70+
f = host.file("/etc/default/cortex-ingester")
71+
assert "KAEGER_AGENT_HOST=localhost\n" in f.content_string
72+
assert "KAEGER_SAMPLER_PARAM=0\n" in f.content_string
73+
assert "KAEGER_SAMPLER_TYPE=const\n" in f.content_string
74+
75+
76+
def test_string2(host):
77+
f = host.file("/etc/default/cortex-readpath")
78+
assert "KAEGER_SAMPLER_TYPE=probabilistic\n" in f.content_string
79+
assert "KAEGER_SAMPLER_PARAM=0.1\n" in f.content_string
80+
assert "KAEGER_SAMPLER_TYPE=probabilistic\n" in f.content_string

tasks/configure.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@
3232
notify:
3333
- reload cortex
3434
loop: "{{ cortex_services | dict2items }}"
35+
36+
- name: Configure cortex environment file
37+
template:
38+
src: "cortex.environment.j2"
39+
dest: "{{ cortex_environment_location }}/cortex"
40+
mode: 0644
41+
notify: reload cortex
42+
when: cortex_all_in_one
43+
44+
- name: Configure cortex environment file for services
45+
template:
46+
47+
dest: "{{ cortex_environment_location }}/cortex-{{ item.key }}"
48+
mode: 0644
49+
notify: reload cortex
50+
loop: "{{ cortex_env_variables | dict2items }}"
51+
when: not cortex_all_in_one

tasks/preflight.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,10 @@
7373
when:
7474
- cortex_binary_local_dir | length == 0
7575
- not cortex_skip_install
76+
77+
- name: Assert that environment variables are asserted with services
78+
assert:
79+
that:
80+
- "item in cortex_services"
81+
with_items: "{{ cortex_env_variables }}"
82+
when: not cortex_all_in_one

0 commit comments

Comments
 (0)