Skip to content

Commit

Permalink
Performance improvement
Browse files Browse the repository at this point in the history
- Eliminating unnecessary set_fact tasks in tasks/main.yml and moving
  them to the individual input and output.
- Eliminating unnecessary loop for the set_certs tasks.
- Fixing a typo and applying the set_certs changes to tests_ovirt_elasticsearch.yml
  and tests_files_elasticsearch.yml.
- Replacing variable names starting with one underscore with two.
- Initializing rsyslog_inputs and rsyslog_outputs with [].
  • Loading branch information
nhosoi committed Oct 4, 2021
1 parent 9c8abed commit 1e11266
Show file tree
Hide file tree
Showing 29 changed files with 289 additions and 331 deletions.
6 changes: 0 additions & 6 deletions roles/rsyslog/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,3 @@ rsyslog_custom_config_files: []
# Traditional timestamp format looks like 'Mar 27 14:16:47'
# By setting false, it'd change 2020-03-27T14:16:47.139796+00:00)
rsyslog_basics_use_traditional_timestamp_format: true

# Files and Forwards outputs
# --------------------------

rsyslog_output_files: []
rsyslog_output_forwards: []
8 changes: 4 additions & 4 deletions roles/rsyslog/tasks/inputs/basics/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create basics input configuration file
input-basics-{{ _input.name }} in /etc/rsyslog.d"
input-basics-{{ __rsyslog_input.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "input-basics-{{ _input.name }}"
- name: "input-basics-{{ __rsyslog_input.name }}"
type: input
state: "{{ _input.state | d('present') }}"
state: "{{ __rsyslog_input.state | d('present') }}"
sections:
- options: "{{ lookup('template', __rsyslog_input_basics) }}"
include_tasks:
file: "{{ role_path }}/tasks/deploy.yml"
when:
- _input.type | d() == 'basics'
- __rsyslog_input.type | d() == 'basics'
12 changes: 6 additions & 6 deletions roles/rsyslog/tasks/inputs/files/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

# yamllint disable rule:line-length
- name: "Create files input configuration file
input-files-{{ _input.name }} in /etc/rsyslog.d"
input-files-{{ __rsyslog_input.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "input-files-{{ _input.name }}"
- name: "input-files-{{ __rsyslog_input.name }}"
type: input
state: "{{ _input.state | d('present') }}"
state: "{{ __rsyslog_input.state | d('present') }}"
sections:
- options: |-
input(type="imfile" file="{{ _input.input_log_path }}" tag="{{ _input.name }}")
input(type="imfile" file="{{ __rsyslog_input.input_log_path }}" tag="{{ __rsyslog_input.name }}")
{{ lookup("template", "input_template.j2") }}
include_tasks:
file: "{{ role_path }}/tasks/deploy.yml"
when:
- _input.type | d() == 'files'
- _input.input_log_path | d() | length > 0
- __rsyslog_input.type | d() == 'files'
- __rsyslog_input.input_log_path | d() | length > 0
# yamllint enable rule:line-length
14 changes: 7 additions & 7 deletions roles/rsyslog/tasks/inputs/ovirt/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create oVirt input configuration file
input-ovirt-{{ _input.name }} in /etc/rsyslog.d"
input-ovirt-{{ __rsyslog_input.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "input-ovirt-{{ _input.name }}"
- name: "input-ovirt-{{ __rsyslog_input.name }}"
type: input
sections:
- options: "{{ lookup('template', 'input_ovirt.j2') }}"
state: "{{ _input.state | d('present') }}"
state: "{{ __rsyslog_input.state | d('present') }}"
include_tasks:
file: "{{ role_path }}/tasks/deploy.yml"
when:
- _input.type | d('') == 'ovirt'
- _input.subtype | d('') in ['collectd','engine','vdsm']
- __rsyslog_input.type | d('') == 'ovirt'
- __rsyslog_input.subtype | d('') in ['collectd','engine','vdsm']

- name: Ensure collectd port is allowed for rsyslogd to listen to
shell: |-
set -euo pipefail
sport={{ _input.rsyslog_read_collectd_port | d(44514) }}
sport={{ __rsyslog_input.rsyslog_read_collectd_port | d(44514) }}
plist=$( semanage port -l | grep "$sport" || : )
if [ "$plist" = "" ]; then
semanage port -a -t syslogd_port_t -p tcp "$sport"
Expand All @@ -58,6 +58,6 @@
fi
fi
when:
- _input.type | d() == 'ovirt'
- __rsyslog_input.type | d() == 'ovirt'
- ansible_selinux.mode in ["enforcing", "permissive"]
notify: restart rsyslogd
8 changes: 4 additions & 4 deletions roles/rsyslog/tasks/inputs/relp/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include_tasks:
file: "{{ role_path }}/tasks/set_certs.yml"
vars:
__rsyslog_cert_subject: "{{ rsyslog_input_relp }}"
__rsyslog_cert_subject: "{{ __rsyslog_input }}"

# Deploy configuration files
- name: "Install/Update relp logging packages and generate
Expand All @@ -15,14 +15,14 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create relp input configuration file
input-relp-{{ _input.name }} in /etc/rsyslog.d"
input-relp-{{ __rsyslog_input.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "input-relp-{{ _input.name }}"
- name: "input-relp-{{ __rsyslog_input.name }}"
type: input
weight: "11"
state: "{{ _input.state | d('present') }}"
state: "{{ __rsyslog_input.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'input_relp.j2') }}"
include_tasks:
Expand Down
14 changes: 7 additions & 7 deletions roles/rsyslog/tasks/inputs/remote/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
when:
- item | length > 1
vars:
__logging_remote: "{{ logging_inputs |
__logging_remote: "{{ rsyslog_inputs |
selectattr('type', 'match', '^remote$') | list }}"
__logging_remote_udp: "{{ __logging_remote |
selectattr('udp_ports', 'defined') | list }}"
Expand All @@ -29,25 +29,25 @@
vars:
__rsyslog_packages: "{{ __rsyslog_remote_packages }}"
__rsyslog_rules:
- name: "input-remote-modules-{{ _input.name }}"
- name: "input-remote-modules-{{ __rsyslog_input.name }}"
type: modules
sections:
- options: "{{ lookup('template', 'input_remote_module.j2') }}"
include_tasks:
file: "{{ role_path }}/tasks/deploy.yml"
when: _input.type | d() == 'remote'
when: __rsyslog_input.type | d() == 'remote'

- name: "Create remote input configuration file
input-remote-{{ _input.name }} in /etc/rsyslog.d"
input-remote-{{ __rsyslog_input.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "input-remote-{{ _input.name }}"
- name: "input-remote-{{ __rsyslog_input.name }}"
type: input
weight: "11"
state: "{{ _input.state | d('present') }}"
state: "{{ __rsyslog_input.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'input_remote.j2') }}"
include_tasks:
file: "{{ role_path }}/tasks/deploy.yml"
when: _input.type | d() == 'remote'
when: __rsyslog_input.type | d() == 'remote'
17 changes: 9 additions & 8 deletions roles/rsyslog/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
mode: "{{ __rsyslog_register_stat_conf.stat.mode | d('0700') }}"
when:
- __rsyslog_enabled | bool
- logging_inputs | d([])
- rsyslog_inputs | d([])
notify: restart rsyslogd

- name: Generate global rule to add to __rsyslog_common_rules
Expand Down Expand Up @@ -156,7 +156,7 @@
loop_var: inner_item
when:
- __rsyslog_enabled | bool
- logging_inputs | d([])
- rsyslog_inputs | d([])
- inner_item.filename | d() or inner_item.name | d()
- inner_item.state is undefined or inner_item.state != 'absent'
- inner_item.options | d() or inner_item.sections | d()
Expand Down Expand Up @@ -264,11 +264,12 @@
notify: restart rsyslogd

vars:
__logging_forwards_tls: "{{ logging_outputs |
__logging_forwards_tls: "{{ rsyslog_outputs |
selectattr('target', 'defined') |
selectattr('type', 'match', '^forwards$') |
selectattr('tls', 'defined') |
selectattr('tls') | list }}"
__logging_remote_tls: "{{ logging_inputs |
__logging_remote_tls: "{{ rsyslog_inputs |
selectattr('type', 'match', '^remote$') |
selectattr('tcp_ports', 'defined') |
selectattr('tls', 'defined') |
Expand All @@ -282,7 +283,7 @@
file: "{{ role_path }}/vars/{{ varfile }}"
vars:
varfile: "inputs/{{ input_item.type }}/main.yml"
loop: "{{ logging_inputs }}"
loop: "{{ rsyslog_inputs }}"
loop_control:
loop_var: input_item
when:
Expand All @@ -293,8 +294,8 @@
file: "{{ tasks }}"
vars:
tasks: "{{ role_path }}/tasks/inputs/{{ input_item.type }}/main.yml"
_input: "{{ input_item }}"
loop: '{{ logging_inputs | sort(attribute="type") }}'
__rsyslog_input: "{{ input_item }}"
loop: '{{ rsyslog_inputs | sort(attribute="type") }}'
loop_control:
extended: yes
loop_var: input_item
Expand Down Expand Up @@ -324,7 +325,7 @@
file: "{{ tasks }}"
vars:
tasks: "{{ role_path }}/tasks/outputs/{{ output_item.type }}/main.yml"
_output: "{{ output_item }}"
__rsyslog_output: "{{ output_item }}"
loop: "{{ rsyslog_outputs }}"
loop_control:
loop_var: output_item
Expand Down
14 changes: 7 additions & 7 deletions roles/rsyslog/tasks/outputs/elasticsearch/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include_tasks:
file: "{{ role_path }}/tasks/set_certs.yml"
vars:
__rsyslog_cert_subject: "{{ rsyslog_output_elasticsearch }}"
__rsyslog_cert_subject: "{{ __rsyslog_output }}"

# Deploy configuration files
- name: "Install/Update elasticsearch logging packages and generate
Expand All @@ -15,14 +15,14 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create elasticsearch output configuration file
output-elasticsearch-{{ _output.name }} in /etc/rsyslog.d"
output-elasticsearch-{{ __rsyslog_output.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "output-elasticsearch-{{ _output.name }}"
- name: "output-elasticsearch-{{ __rsyslog_output.name }}"
type: "output"
weight: "31"
state: "{{ _output.state | d('present') }}"
state: "{{ __rsyslog_output.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'output_elasticsearch.j2') }}"
mode: "0600"
Expand All @@ -34,14 +34,14 @@
(logging_elasticsearch_password | length == 0)

- name: "Create elasticsearch output configuration file
output-elasticsearch-{{ _output.name }} in /etc/rsyslog.d (no_log)"
output-elasticsearch-{{ __rsyslog_output.name }} in /etc/rsyslog.d (no_log)"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "output-elasticsearch-{{ _output.name }}"
- name: "output-elasticsearch-{{ __rsyslog_output.name }}"
type: "output"
weight: "31"
state: "{{ _output.state | d('present') }}"
state: "{{ __rsyslog_output.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'output_elasticsearch.j2') }}"
mode: "0600"
Expand Down
6 changes: 3 additions & 3 deletions roles/rsyslog/tasks/outputs/files/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create files output configuration file
output-files-{{ _output.name }} in /etc/rsyslog.d"
output-files-{{ __rsyslog_output.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "output-files-{{ _output.name }}"
- name: "output-files-{{ __rsyslog_output.name }}"
type: "output"
state: "{{ _output.state | d('present') }}"
state: "{{ __rsyslog_output.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'output_files.j2') }}"
include_tasks:
Expand Down
6 changes: 3 additions & 3 deletions roles/rsyslog/tasks/outputs/forwards/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create forwards output configuration file
output-forwards-{{ _output.name }} in /etc/rsyslog.d"
output-forwards-{{ __rsyslog_output.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "output-forwards-{{ _output.name }}"
- name: "output-forwards-{{ __rsyslog_output.name }}"
type: "output"
state: "{{ _output.state | d('present') }}"
state: "{{ __rsyslog_output.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'output_forwards.j2') }}"
include_tasks:
Expand Down
8 changes: 4 additions & 4 deletions roles/rsyslog/tasks/outputs/relp/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include_tasks:
file: "{{ role_path }}/tasks/set_certs.yml"
vars:
__rsyslog_cert_subject: "{{ rsyslog_output_relp }}"
__rsyslog_cert_subject: "{{ __rsyslog_output }}"

# Deploy configuration files
- name: "Install/Update relp logging packages and generate
Expand All @@ -15,14 +15,14 @@
file: "{{ role_path }}/tasks/deploy.yml"

- name: "Create relp output configuration file
output-relp-{{ _output.name }} in /etc/rsyslog.d"
output-relp-{{ __rsyslog_output.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: []
__rsyslog_rules:
- name: "output-relp-{{ _output.name }}"
- name: "output-relp-{{ __rsyslog_output.name }}"
type: "output"
weight: "31"
state: "{{ _output.state | d('present') }}"
state: "{{ __rsyslog_output.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'output_relp.j2') }}"
include_tasks:
Expand Down
6 changes: 3 additions & 3 deletions roles/rsyslog/tasks/outputs/remote_files/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: "Create remote files output configuration file
output-files-{{ _output.name }} in /etc/rsyslog.d"
output-files-{{ __rsyslog_output.name }} in /etc/rsyslog.d"
vars:
__rsyslog_packages: "{{ __rsyslog_remote_files_output_packages }}"
__rsyslog_rules:
- name: "output-files-{{ _output.name }}"
- name: "output-files-{{ __rsyslog_output.name }}"
type: "output"
state: "{{ _output.state | d('present') }}"
state: "{{ __rsyslog_output.state | d('present') }}"
sections:
- options: "{{ lookup('template', 'output_remote_files.j2') }}"
include_tasks:
Expand Down
Loading

0 comments on commit 1e11266

Please sign in to comment.