Skip to content

Commit 630e87e

Browse files
committed
fix: add missing pmie webhook action configuration functionality
1 parent e50979a commit 630e87e

File tree

7 files changed

+115
-0
lines changed

7 files changed

+115
-0
lines changed

docs/pcp/setup.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
roles:
55
- role: performancecopilot.metrics.pcp
66
vars:
7+
pcp_pmie_endpoint: https://example.com/webhook
78
pcp_pmlogger_interval: 10
89
pcp_optional_agents: [dm, nfsclient, openmetrics]
910
pcp_explicit_labels:

roles/pcp/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Default location for [pmlogger(1)](http://man7.org/linux/man-pages/man1/pmlogger
2828

2929
An optional list of remote hostnames for which metric recording and inference rules should be installed, to be monitored from the host running the playbook. By default, all performance rules evaluating to true will be logged to the local system log (for both the local host and remote hosts in the target hosts list), and daily archives will be created below *pcp_archive_dir*/*hostname* locally, again for each host listed in the target hosts list.
3030

31+
pcp_pmie_endpoint: ''
32+
33+
Send inference events to the given webhook endpoint (URL) from [pmie(1)](http://man7.org/linux/man-pages/man1/pmie.1.html) performance rules. The default is to log these events into the local system log only.
34+
3135
pcp_single_control: 0
3236

3337
Specifies whether the pcp_target_hosts configuration file(s) for pmie and pmlogger are in control.d form (the default) or in the single file form where /*etc*/*pcp*/*pmlogger*/*control* and /*etc*/*pcp*/*pmie*/*control* are used to setup the target hosts list for monitoring.

roles/pcp/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pcp_rest_api: false
55
pcp_pmlogger_discard: 14
66
pcp_pmlogger_interval: 60
77
pcp_archive_dir: /var/log/pcp/pmlogger
8+
pcp_pmie_endpoint: ''
89
pcp_pmcd_localonly: 0
910
pcp_pmproxy_localonly: 0
1011
pcp_pmlogger_localonly: 1

roles/pcp/tasks/pmie.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,58 @@
3131
loop: "{{ __pcp_pmieconf_rules | default([]) }}"
3232
register: __pcp_register_changed_rules_for_hosts
3333

34+
- name: Ensure performance rule actions are installed for targeted hosts
35+
set_fact:
36+
local_pmie: "default"
37+
38+
- name: Check if global pmie webhook action is configured
39+
lineinfile:
40+
state: absent
41+
path: "{{ __pcp_pmie_config_path }}/config.{{ item }}"
42+
regexp: "//.*global webhook_action = yes"
43+
check_mode: true
44+
changed_when: false
45+
register: __pcp_global_webhook_action_status
46+
loop: "{{ pcp_target_hosts + [local_pmie] }}"
47+
when:
48+
- pcp_pmie_endpoint | length > 0
49+
50+
- name: Configure global webhook action
51+
# yamllint disable rule:line-length
52+
command: "pmieconf -f {{ __pcp_pmie_config_path }}/config.{{ item.item }} modify global webhook_action yes"
53+
loop: "{{ __pcp_global_webhook_action_status.results }}"
54+
changed_when:
55+
- pcp_pmie_endpoint | length > 0
56+
- item.found == 0
57+
when:
58+
- pcp_pmie_endpoint | length > 0
59+
- item.found == 0
60+
register: __pcp_register_changed_actions_for_hosts
61+
# yamllint enable rule:line-length
62+
63+
- name: Check if global webhook endpoint is configured
64+
lineinfile:
65+
state: absent
66+
path: "{{ __pcp_pmie_config_path }}/config.{{ item }}"
67+
regexp: "//.*global webhook_endpoint = \"{{ pcp_pmie_endpoint }}\""
68+
check_mode: true
69+
changed_when: false
70+
register: __pcp_global_webhook_endpoint_status
71+
loop: "{{ pcp_target_hosts + [local_pmie] }}"
72+
73+
- name: Configure global webhook endpoint
74+
# yamllint disable rule:line-length
75+
command: "pmieconf -f {{ __pcp_pmie_config_path }}/config.{{ item.item }} modify global webhook_endpoint {{ pcp_pmie_endpoint }}"
76+
loop: "{{ __pcp_global_webhook_endpoint_status.results }}"
77+
changed_when:
78+
- pcp_pmie_endpoint | length > 0
79+
- item.found == 0
80+
when:
81+
- pcp_pmie_endpoint | length > 0
82+
- item.found == 0
83+
register: __pcp_register_changed_actions_for_hosts
84+
# yamllint enable rule:line-length
85+
3486
- name: Ensure extra rules symlinks have been created for targeted hosts
3587
file:
3688
src: "{{ __pcp_pmieconf_path }}/{{ item }}"
@@ -67,6 +119,7 @@
67119
__pcp_register_changed_group_dir is changed or
68120
__pcp_register_changed_group_link_dir is changed or
69121
__pcp_register_changed_rules_for_hosts is changed or
122+
__pcp_register_changed_actions_for_hosts is changed or
70123
__pcp_register_changed_symlinks_for_hosts is changed or
71124
__pcp_register_changed_target_hosts_controld is changed or
72125
__pcp_register_changed_target_hosts_single is changed }}"

roles/pcp/vars/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __pcp_pmlogger_control_path: /etc/pcp/pmlogger/control
1919

2020
__pcp_pmie_control_d_path: /etc/pcp/pmie/control.d
2121
__pcp_pmie_control_path: /etc/pcp/pmie/control
22+
__pcp_pmie_config_path: /var/lib/pcp/config/pmie
2223

2324
__pcp_pmieconf_path: /etc/pcp/pmieconf
2425
__pcp_pmieconf_link_path: /var/lib/pcp/config/pmieconf

tests/check_pmie_webhook.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-License-Identifier: MIT
2+
---
3+
- name: Check if primary pmie is running
4+
changed_when: false
5+
shell: |
6+
set -eu
7+
if set -o | grep -q pipefail; then
8+
set -o pipefail # no pipefail on debian, some ubuntu
9+
fi
10+
pmprobe -I pmcd.pmie.pmcd_host | grep '"primary"'
11+
when: (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
12+
ansible_facts['distribution_major_version'] | int > 6) or
13+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
14+
15+
# yamllint disable rule:line-length
16+
- name: Check if primary pmie uses webhook
17+
changed_when: false
18+
shell: |
19+
set -eu
20+
if set -o | grep -q pipefail; then
21+
set -o pipefail # no pipefail on debian, some ubuntu
22+
fi
23+
pmieconf -f /var/lib/pcp/config/pmie/config.default list global webhook_endpoint | grep '"example"'
24+
pmieconf -f /var/lib/pcp/config/pmie/config.default list global webhook_action | grep '"yes"'
25+
when: (ansible_distribution in ['RedHat', 'CentOS'] and
26+
(ansible_facts['distribution_version'] is version('9.3', '<'))) or
27+
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
28+
# yamllint enable rule:line-length
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: MIT
2+
---
3+
- name: Test pmie webhook configuration
4+
hosts: all
5+
6+
roles:
7+
- role: performancecopilot.metrics.pcp
8+
vars:
9+
pcp_pmie_endpoint: https://example.com:12345/webhook
10+
11+
pre_tasks:
12+
- name: Skip test if not supported by platform
13+
meta: end_host
14+
when: (ansible_distribution in ['RedHat', 'CentOS'] and
15+
(ansible_facts['distribution_version'] is version('9.3', '<'))) or
16+
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
17+
18+
- name: Save state of services
19+
import_tasks: get_services_state.yml
20+
21+
tasks:
22+
- name: Check if configuring pmie webhook works
23+
include_tasks: check_pmie_webhook.yml
24+
25+
post_tasks:
26+
- name: Restore state of services
27+
import_tasks: restore_services_state.yml

0 commit comments

Comments
 (0)