Skip to content

Commit

Permalink
agent mode support
Browse files Browse the repository at this point in the history
Signed-off-by: Stan Rudenko <stan@truera.com>
  • Loading branch information
rooty0 committed Aug 19, 2023
1 parent 764f6db commit 50539a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions roles/prometheus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ prometheus_storage_retention: "30d"
# supported: KB, MB, GB, TB, PB.
prometheus_storage_retention_size: "0"

# The Agent mode optimizes Prometheus for the remote write use case: https://prometheus.io/blog/2021/11/16/agent/
prometheus_agent_mode: false

prometheus_config_flags_extra: {}
# prometheus_config_flags_extra:
# storage.tsdb.retention: 15d
Expand Down Expand Up @@ -87,6 +90,8 @@ prometheus_scrape_configs:
# Alternative config file name, searched in ansible templates path.
prometheus_config_file: 'prometheus.yml.j2'

prometheus_rules_enable: true

prometheus_alert_rules_files:
- prometheus/rules/*.rules

Expand Down
10 changes: 10 additions & 0 deletions roles/prometheus/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ argument_specs:
- "Maximum number of bytes that can be stored for blocks."
- "Units supported: KB, MB, GB, TB, PB."
default: "0"
prometheus_agent_mode:
description:
- "The Agent mode optimizes Prometheus for the remote write use case. It disables querying, alerting, and local storage, and replaces it with a customized TSDB WAL. L(Everything,https://prometheus.io/docs/prometheus/latest/feature_flags/#prometheus-agent) else stays the same."
- "This feature is available starting from Prometheus v2.32.0."
type: bool
default: false
prometheus_config_flags_extra:
description:
- "Additional configuration flags passed to prometheus binary at startup"
Expand Down Expand Up @@ -121,6 +127,10 @@ argument_specs:
prometheus_config_file:
description: "Variable used to provide custom prometheus configuration file in form of ansible template"
default: "prometheus.yml.j2"
prometheus_rules_enable:
description: "To enable rules via the rule_files field in the Prometheus configuration"
type: bool
default: true
prometheus_alert_rules:
description:
- "Full list of alerting rules which will be copied to C({{ prometheus_config_dir }}/rules/ansible_managed.rules)."
Expand Down
9 changes: 7 additions & 2 deletions roles/prometheus/templates/prometheus.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart={{ _prometheus_binary_install_dir }}/prometheus \
{% if not prometheus_agent_mode %}
--storage.tsdb.path={{ prometheus_db_dir }} \
{% if prometheus_version is version('2.7.0', '>=') %}
{% if prometheus_version is version('2.7.0', '>=') %}
--storage.tsdb.retention.time={{ prometheus_storage_retention }} \
--storage.tsdb.retention.size={{ prometheus_storage_retention_size }} \
{% else %}
{% else %}
--storage.tsdb.retention={{ prometheus_storage_retention }} \
{% endif %}
{% else %}
--enable-feature=agent \
{% endif %}
{% if prometheus_version is version('2.24.0', '>=') %}
--web.config.file={{ prometheus_config_dir }}/web.yml \
Expand Down Expand Up @@ -54,6 +58,7 @@ RestrictSUIDSGID=true

{% if (ansible_facts.packages.systemd | first).version is version('231', '>=') %}
ReadWritePaths={{ prometheus_db_dir }}
WorkingDirectory={{ prometheus_db_dir }}
{% for path in prometheus_read_only_dirs %}
ReadOnlyPaths={{ path }}
{% endfor %}
Expand Down
2 changes: 2 additions & 0 deletions roles/prometheus/templates/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ remote_read:
{{ prometheus_remote_read | to_nice_yaml(indent=2,sort_keys=False) | indent(2, False) }}
{% endif %}

{% if prometheus_rules_enable and not prometheus_agent_mode %}
rule_files:
- {{ prometheus_config_dir }}/rules/*.rules
{% endif %}

{% if prometheus_alertmanager_config | length > 0 %}
alerting:
Expand Down

0 comments on commit 50539a9

Please sign in to comment.