Skip to content

Commit da15fa8

Browse files
committed
promtail cosmetic changes
1 parent f9a9d32 commit da15fa8

2 files changed

Lines changed: 79 additions & 89 deletions

File tree

promtail/init.sls

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
{% if pillar['promtail'] is defined and pillar['promtail'] is not none %}
2-
3-
{% if "acme_domain" in pillar["promtail"] %}
4-
5-
{% from "acme/macros.jinja" import verify_and_issue %}
6-
7-
{% set acme = pillar["acme"].keys() | first %}
8-
2+
{%- if "acme_domain" in pillar["promtail"] %}
3+
{%- from "acme/macros.jinja" import verify_and_issue %}
4+
{%- set acme = pillar["acme"].keys() | first %}
95
{{ verify_and_issue(acme, "promtail", pillar["promtail"]["acme_domain"]) }}
10-
11-
{% endif %}
6+
{%- endif %}
127
13-
{% if pillar["promtail"]["scrape_configs"] is defined and pillar["promtail"]["config"] is defined %}
8+
{%- if pillar["promtail"]["scrape_configs"] is defined and pillar["promtail"]["config"] is defined %}
149
1510
pillar must contain either "promtail.config" or "promtail.scrape_configs" block:
1611
test.fail_without_changes:
1712
- name: Pillar must contain either "promtail.config" or "promtail.scrape_configs" block.
1813
19-
{% else %}
14+
{%- else %}
2015
2116
promtail_data_dirs:
2217
file.directory:
@@ -37,15 +32,15 @@ promtail_data_dirs:
3732
own key and they all end up here.
3833
If config_scrape_parts is empty or absent, a warning is issued and Promtail will not be deployed.
3934
================================================================ #}
40-
{% set config_deployed = { 'is_ready': false } %}
41-
{% if "config_global_part" in pillar["promtail"] %}
42-
{% set scrape_fragments = [] %}
43-
{% if "config_scrape_parts" in pillar["promtail"] %}
44-
{% for part_name in pillar["promtail"]["config_scrape_parts"].keys() | sort %}
45-
{% set _ = scrape_fragments.append(pillar["promtail"]["config_scrape_parts"][part_name]) %}
46-
{% endfor %}
47-
{% endif %}
48-
{% if scrape_fragments | length == 0 %}
35+
{%- set config_deployed = { 'is_ready': false } %}
36+
{%- if "config_global_part" in pillar["promtail"] %}
37+
{%- set scrape_fragments = [] %}
38+
{%- if "config_scrape_parts" in pillar["promtail"] %}
39+
{%- for part_name in pillar["promtail"]["config_scrape_parts"].keys() | sort %}
40+
{%- set _ = scrape_fragments.append(pillar["promtail"]["config_scrape_parts"][part_name]) %}
41+
{%- endfor %}
42+
{%- endif %}
43+
{%- if scrape_fragments | length == 0 %}
4944
5045
promtail_no_scrape_jobs:
5146
test.configurable_test_state:
@@ -56,9 +51,9 @@ promtail_no_scrape_jobs:
5651
promtail: config_global_part is set but no config_scrape_parts jobs are attached.
5752
Promtail config will NOT be deployed until at least one job pillar is connected via top_sls.
5853
59-
{% else %}
60-
{% set merged_scrape_text = scrape_fragments | join('\n') %}
61-
{% set _ = config_deployed.update({'is_ready': true}) %}
54+
{%- else %}
55+
{%- set merged_scrape_text = scrape_fragments | join('\n') %}
56+
{%- set _ = config_deployed.update({'is_ready': true}) %}
6257
6358
promtail_config:
6459
file.managed:
@@ -70,13 +65,13 @@ promtail_config:
7065
{{ pillar['promtail']['config_global_part'] | indent(8) }}
7166
scrape_configs:
7267
{{ merged_scrape_text | indent(8) }}
73-
{% endif %}
68+
{%- endif %}
7469
7570
{# ================================================================
7671
LEGACY PATH 1: promtail.scrape_configs (uses config.jinja template)
7772
================================================================ #}
78-
{% elif pillar["promtail"]["scrape_configs"] is defined %}
79-
{% set _ = config_deployed.update({'is_ready': true}) %}
73+
{%- elif pillar["promtail"]["scrape_configs"] is defined %}
74+
{%- set _ = config_deployed.update({'is_ready': true}) %}
8075
promtail_config:
8176
file.managed:
8277
- name: /opt/promtail/etc/promtail.yaml
@@ -96,17 +91,17 @@ promtail_config:
9691
{# ================================================================
9792
LEGACY PATH 2: promtail.config (full config verbatim)
9893
================================================================ #}
99-
{% elif pillar["promtail"]["config"] is defined %}
100-
{% set _ = config_deployed.update({'is_ready': true}) %}
101-
{% if pillar["promtail"]["loki"] is defined or pillar["promtail"]["positions"] is defined %}
94+
{%- elif pillar["promtail"]["config"] is defined %}
95+
{%- set _ = config_deployed.update({'is_ready': true}) %}
96+
{%- if pillar["promtail"]["loki"] is defined or pillar["promtail"]["positions"] is defined %}
10297
when pillar contain "pillar.config" block:
10398
test.configurable_test_state:
10499
- name: nothing_done
105100
- changes: False
106101
- result: True
107102
- warnings: |
108103
When pillar contain "promtail.config" block, the "promtail.positions", "promtail.loki" blocks are IGNORED
109-
{% endif %}
104+
{%- endif %}
110105
promtail_config:
111106
file.managed:
112107
- name: /opt/promtail/etc/promtail.yaml
@@ -115,9 +110,9 @@ promtail_config:
115110
- group: 0
116111
- contents: |
117112
{{ pillar['promtail']['config'] | indent(8) }}
118-
{% endif %}
113+
{%- endif %}
119114
120-
{% if config_deployed['is_ready'] and 'docker' in pillar['promtail'] %}
115+
{%- if config_deployed['is_ready'] and 'docker' in pillar['promtail'] %}
121116
promtail_image:
122117
cmd.run:
123118
- name: docker pull {{ pillar['promtail']['docker']['image'] }}
@@ -139,7 +134,7 @@ promtail_container:
139134
- watch:
140135
- /opt/promtail/etc/promtail.yaml
141136
- command: -config.file=/etc/promtail/promtail.yaml
142-
{% elif config_deployed['is_ready'] %}
137+
{%- elif config_deployed['is_ready'] %}
143138
144139
promtail_binary_1:
145140
archive.extracted:
@@ -191,7 +186,7 @@ promtail_systemd_4:
191186
- onchanges:
192187
- file: /etc/systemd/system/promtail.service
193188
- file: /opt/promtail/etc/promtail.yaml
194-
{% endif %}
195-
{% endif %}
189+
{%- endif %}
190+
{%- endif %}
196191
{% endif %}
197192

promtail/pillar.example

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,58 @@
1-
### NEW: config_global_part + config_scrape_parts (recommended for multi-pillar merge)
2-
###
3-
### Split promtail config into two pieces that live in SEPARATE pillar SLS files:
4-
### config_global_part — string: everything above scrape_configs (server, clients, limits…)
5-
### config_scrape_parts — dict: each key is a unique name, value is a YAML string
6-
### containing one or more `- job_name: …` blocks
7-
###
8-
### Salt deep-merges dicts, so when multiple pillar SLS files each add their own
9-
### key to config_scrape_parts, all keys end up in the compiled pillar.
10-
### The formula iterates over all values (sorted by key) and assembles them under
11-
### `scrape_configs:`.
12-
###
13-
### If config_scrape_parts is empty or absent, a default stub job is used (no errors).
14-
###
15-
### Targeting is done ONLY via top_sls — job pillar SLS files contain no targets.
16-
###
17-
### See pillar/promtail/examples/ for complete working examples.
1+
# NEW: config_global_part + config_scrape_parts (recommended for multi-pillar merge)
2+
#
3+
# Split promtail config into two pieces that live in SEPARATE pillar SLS files:
4+
# config_global_part — string: everything above scrape_configs (server, clients, limits…)
5+
# config_scrape_parts — dict: each key is a unique name, value is a YAML string
6+
# containing one or more `- job_name: …` blocks
7+
#
8+
# Salt deep-merges dicts, so when multiple pillar SLS files each add their own
9+
# key to config_scrape_parts, all keys end up in the compiled pillar.
10+
# The formula iterates over all values (sorted by key) and assembles them under
11+
# `scrape_configs:`.
12+
#
13+
# If config_scrape_parts is empty or absent, a default stub job is used (no errors).
14+
#
15+
# Targeting is done ONLY via top_sls — job pillar SLS files contain no targets.
16+
#
17+
# See pillar/promtail/examples/ for complete working examples.
1818

1919
# --- Global pillar (attach to '*' in top_sls) ---
20-
# promtail:
21-
# binary:
22-
# link: https://github.com/grafana/loki/releases/download/v2.7.3/promtail-linux-amd64.zip
23-
# config_global_part: |
24-
# server:
25-
# http_listen_port: 9080
26-
# grpc_listen_port: 0
27-
# positions:
28-
# filename: /tmp/positions.yaml
29-
# clients:
30-
# - url: https://loki.example.com/loki/api/v1/push
31-
# limits_config:
32-
# readline_rate_enabled: true
33-
# readline_rate_drop: false
20+
promtail:
21+
binary:
22+
link: https://github.com/grafana/loki/releases/download/v2.7.3/promtail-linux-amd64.zip
23+
config_global_part: |
24+
server:
25+
http_listen_port: 9080
26+
grpc_listen_port: 0
27+
positions:
28+
filename: /tmp/positions.yaml
29+
clients:
30+
- url: https://loki.example.com/loki/api/v1/push
31+
limits_config:
32+
readline_rate_enabled: true
33+
readline_rate_drop: false
3434

3535
# --- Job pillar (attach to matching servers in top_sls) ---
36-
# promtail:
37-
# config_scrape_parts:
38-
# nginx_access: |
39-
# - job_name: nginx_access_logs
40-
# static_configs:
41-
# - labels:
42-
# job: nginx
43-
# __path__: /var/log/nginx/*access.log
36+
promtail:
37+
config_scrape_parts:
38+
nginx_access: |
39+
- job_name: nginx_access_logs
40+
static_configs:
41+
- labels:
42+
job: nginx
43+
__path__: /var/log/nginx/*access.log
4444

4545
# --- Another job pillar (same server can get both) ---
46-
# promtail:
47-
# config_scrape_parts:
48-
# mysql_slowlog: |
49-
# - job_name: mysql_slowlog
50-
# static_configs:
51-
# - labels:
52-
# job: mysql_slowlog
53-
# __path__: /var/log/mysql/*slow.log
54-
46+
promtail:
47+
config_scrape_parts:
48+
mysql_slowlog: |
49+
- job_name: mysql_slowlog
50+
static_configs:
51+
- labels:
52+
job: mysql_slowlog
53+
__path__: /var/log/mysql/*slow.log
5554

56-
### FULL CONFIG (single pillar, no merge)
55+
# FULL CONFIG pillar example (single pillar, no merge)
5756

5857
{%- set promtail_version = "2.7.3" -%}
5958
{%- set host = grains['fqdn'] -%}
@@ -119,11 +118,7 @@ promtail:
119118
- output:
120119
source: message
121120

122-
123-
124-
125-
126-
### LEGASY PILLAR
121+
# LEGACY pillar example (single pillar, no merge, hardcoded values)
127122

128123
{%- set host = "server1.example.com" -%}
129124
promtail:

0 commit comments

Comments
 (0)