From 916925c9a80f90fbe2c18cbfd9b6499257431e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 3 Feb 2016 11:52:46 +0100 Subject: [PATCH] Add Heka to common role Partially implements: blueprint heka Change-Id: I9ddad09b3f16b323c7ed535243458b0de6620cdb --- ansible/roles/common/defaults/main.yml | 4 ++++ ansible/roles/common/tasks/bootstrap.yml | 23 +++++++++++++++++++ ansible/roles/common/tasks/config.yml | 9 ++++++++ ansible/roles/common/tasks/deploy.yml | 2 ++ ansible/roles/common/tasks/pull.yml | 6 +++++ ansible/roles/common/tasks/start.yml | 12 ++++++++++ .../common/templates/heka-global.toml.j2 | 19 +++++++++++++++ ansible/roles/common/templates/heka.json.j2 | 11 +++++++++ docker/base/start.sh | 7 ++++++ tools/cleanup-containers | 1 + 10 files changed, 94 insertions(+) create mode 100644 ansible/roles/common/tasks/bootstrap.yml create mode 100644 ansible/roles/common/templates/heka-global.toml.j2 create mode 100644 ansible/roles/common/templates/heka.json.j2 diff --git a/ansible/roles/common/defaults/main.yml b/ansible/roles/common/defaults/main.yml index 7cf4384c53..bcafb6bc39 100644 --- a/ansible/roles/common/defaults/main.yml +++ b/ansible/roles/common/defaults/main.yml @@ -13,3 +13,7 @@ ansible_image_full: "{{ ansible_image }}:{{ ansible_tag }}" rsyslog_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-rsyslog" rsyslog_tag: "{{ openstack_release }}" rsyslog_image_full: "{{ rsyslog_image }}:{{ rsyslog_tag }}" + +heka_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ kolla_install_type }}-heka" +heka_tag: "{{ openstack_release }}" +heka_image_full: "{{ heka_image }}:{{ heka_tag }}" diff --git a/ansible/roles/common/tasks/bootstrap.yml b/ansible/roles/common/tasks/bootstrap.yml new file mode 100644 index 0000000000..94bd65321c --- /dev/null +++ b/ansible/roles/common/tasks/bootstrap.yml @@ -0,0 +1,23 @@ +--- +- name: Creating log volume + kolla_docker: + action: "create_volume" + common_options: "{{ docker_common_options }}" + name: "kolla_logs" + +- name: Starting heka bootstrap container + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + detach: False + environment: + KOLLA_BOOTSTRAP: + KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" + image: "{{ heka_image_full }}" + labels: + BOOTSTRAP: + name: "bootstrap_heka" + restart_policy: "never" + volumes: + - "{{ node_config_directory }}/heka/:{{ container_config_directory }}/:ro" + - "kolla_logs:/var/log/kolla/" diff --git a/ansible/roles/common/tasks/config.yml b/ansible/roles/common/tasks/config.yml index 56ba9a9cc5..8800d3ee4e 100644 --- a/ansible/roles/common/tasks/config.yml +++ b/ansible/roles/common/tasks/config.yml @@ -6,6 +6,7 @@ recurse: yes with_items: - "rsyslog" + - "heka" - name: Copying over config.json files for services template: @@ -13,6 +14,7 @@ dest: "{{ node_config_directory }}/{{ item }}/config.json" with_items: - "rsyslog" + - "heka" - name: Copying over rsyslog.conf template: @@ -20,3 +22,10 @@ dest: "{{ node_config_directory }}/{{ item }}/{{ item }}.conf" with_items: - "rsyslog" + +- name: Copying over heka config files + template: + src: "heka-{{ item }}.toml.j2" + dest: "{{ node_config_directory }}/heka/heka-{{ item }}.toml" + with_items: + - "global" diff --git a/ansible/roles/common/tasks/deploy.yml b/ansible/roles/common/tasks/deploy.yml index 1f16915ad9..98daa4021c 100644 --- a/ansible/roles/common/tasks/deploy.yml +++ b/ansible/roles/common/tasks/deploy.yml @@ -1,4 +1,6 @@ --- - include: config.yml +- include: bootstrap.yml + - include: start.yml diff --git a/ansible/roles/common/tasks/pull.yml b/ansible/roles/common/tasks/pull.yml index c5ebeb621d..e001028e8a 100644 --- a/ansible/roles/common/tasks/pull.yml +++ b/ansible/roles/common/tasks/pull.yml @@ -10,3 +10,9 @@ action: "pull_image" common_options: "{{ docker_common_options }}" image: "{{ ansible_image_full }}" + +- name: Pulling heka image + kolla_docker: + action: "pull_image" + common_options: "{{ docker_common_options }}" + image: "{{ heka_image_full }}" diff --git a/ansible/roles/common/tasks/start.yml b/ansible/roles/common/tasks/start.yml index ef94a684a7..3c113d8570 100644 --- a/ansible/roles/common/tasks/start.yml +++ b/ansible/roles/common/tasks/start.yml @@ -14,6 +14,18 @@ - "rsyslog:/var/log" - "rsyslog_socket:/var/lib/kolla/rsyslog/" +- name: Starting heka container + kolla_docker: + action: "start_container" + common_options: "{{ docker_common_options }}" + image: "{{ heka_image_full }}" + name: "heka" + volumes: + - "{{ node_config_directory }}/heka/:{{ container_config_directory }}/:ro" + - "kolla_logs:/var/log/kolla/" + - "heka:/var/cache/hekad" + - "heka_socket:/var/lib/kolla/heka/" + - name: Starting kolla-toolbox container kolla_docker: action: "start_container" diff --git a/ansible/roles/common/templates/heka-global.toml.j2 b/ansible/roles/common/templates/heka-global.toml.j2 new file mode 100644 index 0000000000..c9fbc1e7ec --- /dev/null +++ b/ansible/roles/common/templates/heka-global.toml.j2 @@ -0,0 +1,19 @@ +[hekad] +maxprocs = {{ ansible_processor_count * ansible_processor_cores }} + +[syslog_encoder] +type = "SandboxEncoder" +filename = "lua_encoders/os_syslog.lua" + +[syslog_log_decoder] +type = "SandboxDecoder" +filename = "lua_decoders/os_syslog.lua" + [syslog_log_decoder.config] + hostname = "{{ ansible_hostname }}" + +[syslog_input] +type = "UdpInput" +net = "unixgram" +address = "/var/lib/kolla/heka/log" +decoder = "syslog_log_decoder" +splitter = "NullSplitter" diff --git a/ansible/roles/common/templates/heka.json.j2 b/ansible/roles/common/templates/heka.json.j2 new file mode 100644 index 0000000000..ff11902393 --- /dev/null +++ b/ansible/roles/common/templates/heka.json.j2 @@ -0,0 +1,11 @@ +{ + "command": "/usr/bin/hekad -config=/etc/heka/", + "config_files": [ + { + "source": "{{ container_config_directory }}/heka-global.toml", + "dest": "/etc/heka/heka-global.toml", + "owner": "heka", + "perm": "0600" + } + ] +} diff --git a/docker/base/start.sh b/docker/base/start.sh index d9801d7504..a42c01391d 100644 --- a/docker/base/start.sh +++ b/docker/base/start.sh @@ -11,6 +11,13 @@ if [[ ! "${!SKIP_LOG_SETUP[@]}" && -e /var/lib/kolla/rsyslog ]]; then sudo ln -sf /var/lib/kolla/rsyslog/log /dev/log fi +# Wait for the log socket +if [[ ! "${!SKIP_LOG_SETUP[@]}" && -e /var/lib/kolla/heka ]]; then + while [[ ! -S /var/lib/kolla/heka/log ]]; do + sleep 1 + done +fi + # Processing /var/lib/kolla/config_files/config.json as root. This is necessary # to permit certain files to be controlled by the root user which should # not be writable by the dropped-privileged user, especially /run_command diff --git a/tools/cleanup-containers b/tools/cleanup-containers index 1ac6d6e31c..3d399b8c06 100755 --- a/tools/cleanup-containers +++ b/tools/cleanup-containers @@ -32,6 +32,7 @@ else openvswitch_{vswitchd,db} \ rabbitmq{,_bootstrap} \ rsyslog \ + heka \ swift_{account_{auditor,reaper,replicator,server},container_{auditor,replicator,server,updater},object_{auditor,expirer,replicator,server,updater},proxy_server,rsyncd} ) ceph_osd_bootstrap=$(docker ps -a --filter "name=bootstrap_osd_*" --format "{{.Names}}")