Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Agent mode support #198

Merged
merged 7 commits into from
Aug 24, 2023

Conversation

rooty0
Copy link
Contributor

@rooty0 rooty0 commented Aug 19, 2023

This PR adds support to run prometheus in agent mode.

Fixes: #187

@github-actions github-actions bot added enhancement New feature or request roles/prometheus labels Aug 19, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 19, 2023

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and the docs are now incorporated into main:
https://prometheus-community.github.io/ansible/branch/main

@@ -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 %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rule_files are not allowed in agent mode
Aug 17 20:25:51 master2-int prometheus[50413]: ts=2023-08-17T20:25:51.526Z caller=main.go:479 level=error msg="Error loading config (--config.file=/etc/prometheus/prometheus.yml)" file=/etc/prometheus/prometheus.yml err="field rule_files is not allowed in agent mode"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to skip copying the rules when using agent mode and not just configure the service to ignore the rules.

---
- name: Alerting rules file
ansible.builtin.template:
src: "alert.rules.j2"
dest: "{{ prometheus_config_dir }}/rules/ansible_managed.rules"
owner: root
group: prometheus
mode: 0640
validate: "{{ _prometheus_binary_install_dir }}/promtool check rules %s"
when:
- prometheus_alert_rules != []
notify:
- reload prometheus
- name: Copy custom alerting rule files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ prometheus_config_dir }}/rules/"
owner: root
group: prometheus
mode: 0640
validate: "{{ _prometheus_binary_install_dir }}/promtool check rules %s"
with_fileglob: "{{ prometheus_alert_rules_files }}"
notify:
- reload prometheus

Also I feel that the addition of the prometheus_rules_enable variable is unnecessary.
I'm unsure if we need to be able to disable the rules in setups other than agent mode.
But if we want to offer that option a better approach would be to just leave the prometheus_alert_rules and prometheus_alert_rules_files variables empty/unconfigured and disable the rules based on that.

@@ -54,6 +58,7 @@ RestrictSUIDSGID=true

{% if (ansible_facts.packages.systemd | first).version is version('231', '>=') %}
ReadWritePaths={{ prometheus_db_dir }}
WorkingDirectory={{ prometheus_db_dir }}
Copy link
Contributor Author

@rooty0 rooty0 Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when --storage.tsdb.path is removed, prometheus is trying to write some tsdb related file to / aka root of a filesystem, and since by default it's running from prometheus user we're getting an error:
Aug 17 20:26:44 master2-int prometheus[50516]: ts=2023-08-17T20:26:44.773Z caller=main.go:1155 level=error err="opening storage failed: lock DB directory: mkdir /data-agent: read-only file system"
So defining the WorkingDirectory fixes this issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to set --storage.agent.path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, replace with --storage.agent.path={{ prometheus_db_dir }}

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 19, 2023
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 19, 2023
@rooty0 rooty0 requested a review from SuperQ August 20, 2023 16:45
@SuperQ SuperQ requested a review from gardar August 21, 2023 05:40
Copy link
Member

@gardar gardar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a molecule scenario for testing the agent mode?

@rooty0
Copy link
Contributor Author

rooty0 commented Aug 21, 2023

Can you please add a molecule scenario for testing the agent mode?

@gardar so just to be sure, currently there're 3 targets: alternative, default and latest. Do you want me to create one more target something like agentmode ?

@gardar
Copy link
Member

gardar commented Aug 21, 2023

Can you please add a molecule scenario for testing the agent mode?

@gardar so just to be sure, currently there're 3 targets: alternative, default and latest. Do you want me to create one more target something like agentmode ?

Yes exactly!

@SuperQ
Copy link
Contributor

SuperQ commented Aug 23, 2023

We recently refactored our test infra. I would recommend rebasing your fork on latest main to pick up the latest changes.

Signed-off-by: Stan Rudenko <stan@truera.com>
Signed-off-by: Stan Rudenko <stan@truera.com>
Signed-off-by: Stan Rudenko <stan@truera.com>
Signed-off-by: Stan Rudenko <stan@truera.com>
Signed-off-by: Stan Rudenko <stan@truera.com>
Signed-off-by: Stan Rudenko <stan@truera.com>
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 23, 2023
@rooty0
Copy link
Contributor Author

rooty0 commented Aug 23, 2023

@SuperQ thanks!

@gardar looks good now

@SuperQ SuperQ requested a review from gardar August 23, 2023 18:59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to test_agentmode.py

@@ -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 %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to skip copying the rules when using agent mode and not just configure the service to ignore the rules.

---
- name: Alerting rules file
ansible.builtin.template:
src: "alert.rules.j2"
dest: "{{ prometheus_config_dir }}/rules/ansible_managed.rules"
owner: root
group: prometheus
mode: 0640
validate: "{{ _prometheus_binary_install_dir }}/promtool check rules %s"
when:
- prometheus_alert_rules != []
notify:
- reload prometheus
- name: Copy custom alerting rule files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ prometheus_config_dir }}/rules/"
owner: root
group: prometheus
mode: 0640
validate: "{{ _prometheus_binary_install_dir }}/promtool check rules %s"
with_fileglob: "{{ prometheus_alert_rules_files }}"
notify:
- reload prometheus

Also I feel that the addition of the prometheus_rules_enable variable is unnecessary.
I'm unsure if we need to be able to disable the rules in setups other than agent mode.
But if we want to offer that option a better approach would be to just leave the prometheus_alert_rules and prometheus_alert_rules_files variables empty/unconfigured and disable the rules based on that.

Signed-off-by: Stan Rudenko <stan@truera.com>
@github-actions github-actions bot added enhancement New feature or request roles/alertmanager and removed enhancement New feature or request labels Aug 24, 2023
@rooty0
Copy link
Contributor Author

rooty0 commented Aug 24, 2023

@gardar fixed

@SuperQ SuperQ requested a review from gardar August 24, 2023 17:29
@gardar gardar merged commit ec82955 into prometheus-community:main Aug 24, 2023
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to run Prometheus in agent mode?
3 participants