-
Notifications
You must be signed in to change notification settings - Fork 132
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
feature: Agent mode support #198
Conversation
Docs Build 📝Thank you for contribution!✨ This PR has been merged and the docs are now incorporated into |
@@ -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 %} |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
ansible/roles/prometheus/tasks/configure.yml
Lines 1 to 25 in 93ed291
--- | |
- 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 }} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 }}
be1e7bd
to
50539a9
Compare
989196c
to
cf566ba
Compare
There was a problem hiding this 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?
@gardar so just to be sure, currently there're 3 targets: |
Yes exactly! |
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 <[email protected]>
Signed-off-by: Stan Rudenko <[email protected]>
Signed-off-by: Stan Rudenko <[email protected]>
Signed-off-by: Stan Rudenko <[email protected]>
Signed-off-by: Stan Rudenko <[email protected]>
Signed-off-by: Stan Rudenko <[email protected]>
78015b5
to
8f6880c
Compare
There was a problem hiding this comment.
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 %} |
There was a problem hiding this comment.
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.
ansible/roles/prometheus/tasks/configure.yml
Lines 1 to 25 in 93ed291
--- | |
- 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 <[email protected]>
@gardar fixed |
This PR adds support to run prometheus in agent mode.
Fixes: #187