UI logging (#131)
* Introduced logging task for the ui * Do not update repo to allow multiple apps * Setup logging first * Different template names * Separate docker logging config * Removed duplication * Common logging task. * Tests. * Lint. * Commented out syslog server port for ui * Testing file permissions.
This commit is contained in:
parent
319b493568
commit
4281adfd95
@ -38,8 +38,10 @@ cp hosts.yml.example hosts.yml
|
||||
hosts:
|
||||
<host_ip_B>:
|
||||
ansible_user: <user>
|
||||
#syslog_server_port: "<protocol>://<ip>:<port>"
|
||||
<host_ip_C>:
|
||||
ansible_user: <user>
|
||||
#syslog_server_port: "<protocol>://<ip>:<port>"
|
||||
```
|
||||
|
||||
The config above would install the Oracle on `<host_ip_A>`, UI on `<host_ip_C>`, and both Oracle and UI on `<host_ip_B>`.
|
||||
|
@ -10,3 +10,4 @@ sokol-kovan:
|
||||
hosts:
|
||||
127.0.0.1:
|
||||
ansible_user: ubuntu
|
||||
#syslog_server_port: "udp://127.0.0.1:514"
|
||||
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import pytest
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
@ -18,3 +19,12 @@ def test_docker_group(host):
|
||||
def test_user(host):
|
||||
assert host.user('poadocker').exists
|
||||
assert 'docker' in host.user('poadocker').groups
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filename", [
|
||||
("/etc/rsyslog.d/30-docker.conf"),
|
||||
("/etc/rsyslog.d/35-docker-remote-logging.conf")
|
||||
])
|
||||
def test_logging(host, filename):
|
||||
assert host.file(filename).exists
|
||||
assert host.file(filename).mode == 0o0644
|
||||
|
@ -29,8 +29,13 @@ def test_services(host, service):
|
||||
assert host.service(service).is_running
|
||||
|
||||
|
||||
def test_remote_logging(host):
|
||||
assert host.file('/etc/rsyslog.d/35-remote-logging.conf').exists
|
||||
@pytest.mark.parametrize("filename", [
|
||||
("/etc/rsyslog.d/31-oracle-docker.conf"),
|
||||
("/etc/rsyslog.d/36-oracle-remote-logging.conf")
|
||||
])
|
||||
def test_logging(host, filename):
|
||||
assert host.file(filename).exists
|
||||
assert host.file(filename).mode == 0o0644
|
||||
|
||||
|
||||
def test_docker_config(host):
|
||||
|
29
deployment/roles/common/tasks/logging.yml
Normal file
29
deployment/roles/common/tasks/logging.yml
Normal file
@ -0,0 +1,29 @@
|
||||
- name: Set the local docker logs configuration file
|
||||
template:
|
||||
src: 30-docker.conf.j2
|
||||
dest: /etc/rsyslog.d/30-docker.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: Set the log configuration file to send docker logs to remote server
|
||||
template:
|
||||
src: 35-docker-remote-logging.conf.j2
|
||||
dest: /etc/rsyslog.d/35-docker-remote-logging.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
when: syslog_server_port is defined
|
||||
|
||||
- name: Set the logrotate config file
|
||||
template:
|
||||
src: docker-logs.j2
|
||||
dest: /etc/logrotate.d/docker-logs
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: restart rsyslog
|
||||
service:
|
||||
name: rsyslog
|
||||
state: restarted
|
@ -1,2 +1,3 @@
|
||||
- include_tasks: dependencies.yml
|
||||
- include_tasks: repo.yml
|
||||
- include_tasks: logging.yml
|
||||
|
@ -2,5 +2,6 @@
|
||||
git:
|
||||
repo: "{{ bridge_repo }}"
|
||||
dest: "{{ bridge_path }}"
|
||||
force: yes
|
||||
force: no
|
||||
update: no
|
||||
version: "{{ bridge_repo_branch }}"
|
||||
|
6
deployment/roles/common/templates/30-docker.conf.j2
Normal file
6
deployment/roles/common/templates/30-docker.conf.j2
Normal file
@ -0,0 +1,6 @@
|
||||
$FileCreateMode 0644
|
||||
|
||||
if $programname startswith 'docker' then \
|
||||
/var/log/docker/no_tag/docker.log
|
||||
|
||||
$FileCreateMode 0600
|
@ -11,7 +11,7 @@ template(name="RemoteForwardFormat" type="list") {
|
||||
property(name="msg")
|
||||
}
|
||||
|
||||
if $programname startswith 'oracle_bridge_' or $programname startswith 'docker' then {
|
||||
if $programname startswith 'docker' then {
|
||||
action(
|
||||
type="omfwd"
|
||||
protocol="{{ syslog_server_port.split(":")[0] }}"
|
||||
@ -25,4 +25,4 @@ action(
|
||||
queue.Type="LinkedList"
|
||||
ResendLastMSGOnReconnect="on"
|
||||
)
|
||||
}
|
||||
}
|
0
deployment/roles/oracle/templates/docker-logs.j2 → deployment/roles/common/templates/docker-logs.j2
0
deployment/roles/oracle/templates/docker-logs.j2 → deployment/roles/common/templates/docker-logs.j2
@ -19,29 +19,21 @@
|
||||
|
||||
- name: Set the local container logs configuration file
|
||||
template:
|
||||
src: 30-docker.conf.j2
|
||||
dest: /etc/rsyslog.d/30-docker.conf
|
||||
src: 31-oracle-docker.conf.j2
|
||||
dest: /etc/rsyslog.d/31-oracle-docker.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: Set the log configuration file to send container logs to remote server
|
||||
template:
|
||||
src: 35-remote-logging.conf.j2
|
||||
dest: /etc/rsyslog.d/35-remote-logging.conf
|
||||
src: 36-oracle-remote-logging.conf.j2
|
||||
dest: /etc/rsyslog.d/36-oracle-remote-logging.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
when: syslog_server_port is defined
|
||||
|
||||
- name: Set the logrotate config file
|
||||
template:
|
||||
src: docker-logs.j2
|
||||
dest: /etc/logrotate.d/docker-logs
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: Discarding unwanted messages in rsyslog
|
||||
blockinfile:
|
||||
path: /etc/rsyslog.conf
|
||||
|
@ -1,5 +1,5 @@
|
||||
- include_tasks: pre_config.yml
|
||||
- include_tasks: logging.yml
|
||||
- include_tasks: jumpbox.yml
|
||||
- include_tasks: post_config.yml
|
||||
- include_tasks: logging.yml
|
||||
- include_tasks: servinstall.yml
|
||||
|
@ -1,12 +1,11 @@
|
||||
$FileCreateMode 0644
|
||||
template(name="DockerLogFileName" type="list") {
|
||||
template(name="DockerLogFileName_Oracle" type="list") {
|
||||
constant(value="/var/log/docker/")
|
||||
property(name="syslogtag" securepath="replace" regex.type="ERE" regex.submatch="1" regex.expression="bridge_(.*)\\/[a-zA-Z0-9]+\\[")
|
||||
constant(value="/docker.log")
|
||||
}
|
||||
|
||||
if $programname startswith 'oracle_bridge_' then \
|
||||
?DockerLogFileName
|
||||
else
|
||||
/var/log/docker/no_tag/docker.log
|
||||
?DockerLogFileName_Oracle
|
||||
|
||||
$FileCreateMode 0600
|
@ -0,0 +1,15 @@
|
||||
if $programname startswith 'oracle_bridge_' then {
|
||||
action(
|
||||
type="omfwd"
|
||||
protocol="{{ syslog_server_port.split(":")[0] }}"
|
||||
target="{{ (syslog_server_port.split(":")[1])[2:] }}"
|
||||
port="{{ syslog_server_port.split(":")[2] }}"
|
||||
template="RemoteForwardFormat"
|
||||
queue.SpoolDirectory="/var/spool/rsyslog"
|
||||
queue.FileName="remote"
|
||||
queue.MaxDiskSpace="1g"
|
||||
queue.SaveOnShutdown="on"
|
||||
queue.Type="LinkedList"
|
||||
ResendLastMSGOnReconnect="on"
|
||||
)
|
||||
}
|
40
deployment/roles/ui/tasks/logging.yml
Normal file
40
deployment/roles/ui/tasks/logging.yml
Normal file
@ -0,0 +1,40 @@
|
||||
- name: Slurp docker compose file
|
||||
slurp:
|
||||
src: "{{ bridge_path }}/ui/docker-compose.yml"
|
||||
register: docker_compose_slurp
|
||||
|
||||
- name: Parse docker compose file
|
||||
set_fact:
|
||||
docker_compose_parsed: "{{ docker_compose_slurp['content'] | b64decode | from_yaml }}"
|
||||
|
||||
- name: Set logger to remote server
|
||||
set_fact:
|
||||
docker_compose_parsed: "{{ docker_compose_parsed |combine({'services': {item: {'logging': {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}}}}, recursive=True) }}"
|
||||
with_items: "{{ docker_compose_parsed.services }}"
|
||||
|
||||
- name: Write new docker-compose file
|
||||
copy:
|
||||
content: "{{ docker_compose_parsed | to_yaml }}"
|
||||
dest: "{{ bridge_path }}/ui/docker-compose.yml"
|
||||
|
||||
- name: Set the local container logs configuration file
|
||||
template:
|
||||
src: 32-ui-docker.conf.j2
|
||||
dest: /etc/rsyslog.d/32-ui-docker.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: Set the log configuration file to send container logs to remote server
|
||||
template:
|
||||
src: 37-ui-remote-logging.conf.j2
|
||||
dest: /etc/rsyslog.d/37-ui-remote-logging.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
when: syslog_server_port is defined
|
||||
|
||||
- name: restart rsyslog
|
||||
service:
|
||||
name: rsyslog
|
||||
state: restarted
|
@ -1,3 +1,4 @@
|
||||
- include_tasks: pre_config.yml
|
||||
- include_tasks: logging.yml
|
||||
- include_tasks: jumpbox.yml
|
||||
- include_tasks: servinstall.yml
|
||||
|
11
deployment/roles/ui/templates/32-ui-docker.conf.j2
Normal file
11
deployment/roles/ui/templates/32-ui-docker.conf.j2
Normal file
@ -0,0 +1,11 @@
|
||||
$FileCreateMode 0644
|
||||
template(name="DockerLogFileName_UI" type="list") {
|
||||
constant(value="/var/log/docker/")
|
||||
property(name="syslogtag" securepath="replace" regex.type="ERE" regex.submatch="1" regex.expression="ui_(.*)\\/[a-zA-Z0-9]+\\[")
|
||||
constant(value="/docker.log")
|
||||
}
|
||||
|
||||
if $programname startswith 'ui_' then \
|
||||
?DockerLogFileName_UI
|
||||
|
||||
$FileCreateMode 0600
|
15
deployment/roles/ui/templates/37-ui-remote-logging.conf.j2
Normal file
15
deployment/roles/ui/templates/37-ui-remote-logging.conf.j2
Normal file
@ -0,0 +1,15 @@
|
||||
if $programname startswith 'ui_' then {
|
||||
action(
|
||||
type="omfwd"
|
||||
protocol="{{ syslog_server_port.split(":")[0] }}"
|
||||
target="{{ (syslog_server_port.split(":")[1])[2:] }}"
|
||||
port="{{ syslog_server_port.split(":")[2] }}"
|
||||
template="RemoteForwardFormat"
|
||||
queue.SpoolDirectory="/var/spool/rsyslog"
|
||||
queue.FileName="remote"
|
||||
queue.MaxDiskSpace="1g"
|
||||
queue.SaveOnShutdown="on"
|
||||
queue.Type="LinkedList"
|
||||
ResendLastMSGOnReconnect="on"
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user