Skip to content
This repository was archived by the owner on Mar 6, 2023. It is now read-only.

Commit 029d005

Browse files
SuperQpaulfantom
authored andcommitted
Add support for retention by size (#182)
* Add support for retention by size [feature] Prometheus 2.7.0 now supports setting retention by size in addition to time. * Fix some long lines issues * Fix some issues with long lines. * Ignore long lines in ansible-lint.
1 parent af7f1eb commit 029d005

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

.ansible-lint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
skip_list:
3+
- '204'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
3434
| `prometheus_web_listen_address` | "0.0.0.0:9090" | Address on which prometheus will be listening |
3535
| `prometheus_web_external_url` | "" | External address on which prometheus is available. Useful when behind reverse proxy. Ex. `http://example.org/prometheus` |
3636
| `prometheus_storage_retention` | "30d" | Data retention period |
37+
| `prometheus_storage_retention_size` | "0" | Data retention period by size |
3738
| `prometheus_config_flags_extra` | {} | Additional configuration flags passed to prometheus binary at startup |
3839
| `prometheus_alertmanager_config` | [] | Configuration responsible for pointing where alertmanagers are. This should be specified as list in yaml format. It is compatible with official [<alertmanager_config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config) |
3940
| `prometheus_alert_relabel_configs` | [] | Alert relabeling rules. This should be specified as list in yaml format. It is compatible with the official [<alert_relabel_configs>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alert_relabel_configs) |

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ prometheus_web_listen_address: "0.0.0.0:9090"
88
prometheus_web_external_url: ''
99

1010
prometheus_storage_retention: "30d"
11+
# Available since Prometheus 2.7.0
12+
# [EXPERIMENTAL] Maximum number of bytes that can be stored for blocks. Units
13+
# supported: KB, MB, GB, TB, PB.
14+
prometheus_storage_retention_size: "0"
1115

1216
prometheus_config_flags_extra: {}
1317
# prometheus_config_flags_extra:

molecule/alternative/playbook.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
prometheus_web_listen_address: "127.0.0.1:9090"
1212
prometheus_web_external_url: "http://127.0.0.1:9090/prometheus"
1313
prometheus_storage_retention: "60d"
14+
prometheus_storage_retention_size: "1GB"
1415
prometheus_config_flags_extra:
1516
alertmanager.timeout: 10s
1617
web.enable-admin-api:

tasks/preflight.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@
2020

2121
- name: Fail when prometheus_config_flags_extra duplicates parameters set by other variables
2222
fail:
23-
msg: "Whooops. You are duplicating configuration. Please look at your prometheus_config_flags_extra and check against other variables in defaults/main.yml"
24-
with_items: [ 'storage.tsdb.retention', 'storage.tsdb.path', 'storage.local.retention', 'storage.local.path', 'config.file', 'web.listen-address', 'web.external-url' ]
23+
msg: >
24+
Whooops. You are duplicating configuration. Please look at your prometheus_config_flags_extra
25+
and check against other variables in defaults/main.yml
26+
with_items:
27+
- 'storage.tsdb.retention'
28+
- 'storage.tsdb.path'
29+
- 'storage.local.retention'
30+
- 'storage.local.path'
31+
- 'config.file'
32+
- 'web.listen-address'
33+
- 'web.external-url'
2534
when: item in prometheus_config_flags_extra.keys()
2635

2736
- name: Get all file_sd files from scrape_configs
@@ -30,14 +39,19 @@
3039

3140
- name: Fail when file_sd targets are not defined in scrape_configs
3241
fail:
33-
msg: "Oh, snap! `{{ item.key }}` couldn't be found in your scrape configs. Please ensure you provided all targets from prometheus_targets in prometheus_scrape_configs"
42+
msg: >
43+
Oh, snap! `{{ item.key }}` couldn't be found in your scrape configs. Please ensure you provided
44+
all targets from prometheus_targets in prometheus_scrape_configs
3445
when: not prometheus_config_dir + "/file_sd/" + item.key + ".yml" in file_sd_files
3546
# when: not item | basename | splitext | difference(['.yml']) | join('') in prometheus_targets.keys()
3647
with_dict: "{{ prometheus_targets }}"
3748

3849
- name: Fail when prometheus_alertmanager_config is empty, but prometheus_alert_rules is specified
3950
debug:
40-
msg: "There's no use in defining alerting rules if you're not going to use them! Be sure to specify a prometheus_alertmanager_config in defaults/main.yml if you're going to define prometheus_alert_rules"
51+
msg: >
52+
There's no use in defining alerting rules if you're not going to use them! Be sure to
53+
specify a prometheus_alertmanager_config in defaults/main.yml if you're going to define
54+
prometheus_alert_rules
4155
when:
4256
- prometheus_alertmanager_config == []
4357
- prometheus_alert_rules != []

templates/prometheus.service.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ ExecReload=/bin/kill -HUP $MAINPID
1313
ExecStart=/usr/local/bin/prometheus \
1414
--config.file={{ prometheus_config_dir }}/prometheus.yml \
1515
--storage.tsdb.path={{ prometheus_db_dir }} \
16+
{% if prometheus_version | version_compare('2.7.0', '>=') %}
17+
--storage.tsdb.retention.time={{ prometheus_storage_retention }} \
18+
--storage.tsdb.retention.size={{ prometheus_storage_retention_size }} \
19+
{% else %}
1620
--storage.tsdb.retention={{ prometheus_storage_retention }} \
21+
{% endif %}
1722
--web.console.libraries={{ prometheus_config_dir }}/console_libraries \
1823
--web.console.templates={{ prometheus_config_dir }}/consoles \
1924
--web.listen-address={{ prometheus_web_listen_address }} \

0 commit comments

Comments
 (0)