Introduce LogJuicer roles
This change adds new roles to run logjuicer in zuul jobs: https://github.com/logjuicer/logjuicer Change-Id: I02824a18285a16c8f0be6bb96b5404aa0d601c16
This commit is contained in:
parent
3b3495e255
commit
26db5b3b24
18
doc/source/logjuicer-roles.rst
Normal file
18
doc/source/logjuicer-roles.rst
Normal file
@ -0,0 +1,18 @@
|
||||
LogJuicer Roles
|
||||
===============
|
||||
|
||||
`LogJuicer <https://github.com/logjuicer/logjuicer>`_ extracts anomalies from log files.
|
||||
|
||||
You have two options to integrate LogJuicer in your Zuul job post-run phase:
|
||||
|
||||
#. Deploy the `web-service <https://github.com/logjuicer/logjuicer/tree/main/crates/web-service>`_ and use the :zuul:role:`report-logjuicer`.
|
||||
|
||||
#. Use the :zuul:role:`run-logjuicer` to create the report locally:
|
||||
|
||||
* For single-node job, the role can be used in untrusted playbooks.
|
||||
* For multi-node job, the role must be used on localhost (the executor) between the :zuul:role:`fetch-output` and the log upload. Note that a future version may support merging reports produced on multi nodes through an untrusted playbooks.
|
||||
|
||||
In both case, a new artifact named "LogJuicer Report" will be provided to access the build report.
|
||||
|
||||
.. zuul:autorole:: report-logjuicer
|
||||
.. zuul:autorole:: run-logjuicer
|
@ -29,3 +29,4 @@ Roles
|
||||
rust-roles
|
||||
system-roles
|
||||
translation-roles
|
||||
logjuicer-roles
|
||||
|
25
roles/report-logjuicer/README.rst
Normal file
25
roles/report-logjuicer/README.rst
Normal file
@ -0,0 +1,25 @@
|
||||
Create a LogJuicer report link
|
||||
|
||||
This role emits an artifact to create a report through a LogJuicer web service.
|
||||
Add the following task to your job post-run phase:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- when: not zuul_success | bool
|
||||
include_role:
|
||||
name: report-logjuicer
|
||||
vars:
|
||||
logjuicer_web_url: https://softwarefactory-project.io/logjuicer
|
||||
zuul_web_url: https://zuul.opendev.org/t/{{ zuul.tenant }}
|
||||
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: logjuicer_web_url
|
||||
|
||||
The http url of the LogJuicer web service.
|
||||
|
||||
.. zuul:rolevar:: zuul_web_url
|
||||
|
||||
The http url of zuul-web.
|
||||
For multi-tenant deployment, add ``/t/{{ zuul.tenant }}``.
|
8
roles/report-logjuicer/tasks/main.yaml
Normal file
8
roles/report-logjuicer/tasks/main.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
- name: Return LogJuicer report url
|
||||
zuul_return:
|
||||
data:
|
||||
zuul:
|
||||
artifacts:
|
||||
- name: "LogJuicer Report"
|
||||
url: "{{ logjuicer_web_url }}/report/new?target={{ zuul_web_url }}/build/{{ zuul.build }}"
|
28
roles/run-logjuicer/README.rst
Normal file
28
roles/run-logjuicer/README.rst
Normal file
@ -0,0 +1,28 @@
|
||||
Create a LogJuicer report
|
||||
|
||||
This role runs the `LogJuicer <https://github.com/logjuicer/logjuicer>`_ tool
|
||||
to create a report of the current build.
|
||||
For single-node jobs, the role can be used on the test instance in the job post-run phase.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- when: not zuul_success | bool
|
||||
include_role:
|
||||
name: run-logjuicer
|
||||
vars:
|
||||
zuul_web_url: https://zuul.opendev.org/
|
||||
|
||||
For multi-node jobs, the role must be used on localhost (the executor)
|
||||
between the :zuul:role:`fetch-output` and the log upload.
|
||||
|
||||
|
||||
**Role Variables**
|
||||
|
||||
.. zuul:rolevar:: zuul_web_url
|
||||
|
||||
The zuul-web URL, to lookup baselines.
|
||||
|
||||
.. zuul:rolevar:: logjuicer_max_run_time
|
||||
:default: 900
|
||||
|
||||
Maximum runtime in seconds.
|
9
roles/run-logjuicer/defaults/main.yaml
Normal file
9
roles/run-logjuicer/defaults/main.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
# Update from https://github.com/logjuicer/logjuicer/releases
|
||||
logjuicer_version: 0.9.6
|
||||
|
||||
# Enable logjuicer debug logs
|
||||
logjuicer_debug: false
|
||||
|
||||
# Maximum runtime in seconds
|
||||
logjuicer_max_run_time: 900
|
15
roles/run-logjuicer/tasks/install.yaml
Normal file
15
roles/run-logjuicer/tasks/install.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Install LogJuicer
|
||||
shell: |
|
||||
set -o pipefail
|
||||
mkdir -p ~/.local/bin
|
||||
curl -L https://github.com/logjuicer/logjuicer/releases/download/{{ logjuicer_version }}/logjuicer-x86_64-linux.tar.bz2 | tar -C ~/.local/ -xjvf -
|
||||
tags:
|
||||
# skip using file module to create the directory to keep this role short
|
||||
- skip_ansible_lint
|
||||
args:
|
||||
executable: '/bin/bash'
|
||||
|
||||
- name: Set logjuicer_cmd fact
|
||||
set_fact:
|
||||
logjuicer_cmd: "{% if logjuicer_debug %}env LOGJUICER_LOG=debug {% endif %}{{ ansible_env.HOME }}/.local/bin/logjuicer"
|
7
roles/run-logjuicer/tasks/main.yaml
Normal file
7
roles/run-logjuicer/tasks/main.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Detect anomalies with logjuicer
|
||||
block:
|
||||
- name: Install logjuicer
|
||||
include_tasks: install.yaml
|
||||
- name: Run logjuicer
|
||||
include_tasks: run.yaml
|
44
roles/run-logjuicer/tasks/run.yaml
Normal file
44
roles/run-logjuicer/tasks/run.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
---
|
||||
- name: Check for multi-node usages
|
||||
when: ansible_play_hosts_all | length > 1
|
||||
fail:
|
||||
msg: "Run logjuicer from the executor after the fetch-output for multi-node jobs"
|
||||
|
||||
- name: Setup multi-node fact
|
||||
when: inventory_hostname == "localhost"
|
||||
set_fact:
|
||||
_logs_path: "{{ zuul.executor.log_root }}"
|
||||
|
||||
- name: Setup single-node
|
||||
when: inventory_hostname != "localhost"
|
||||
block:
|
||||
- name: Setup fact
|
||||
set_fact:
|
||||
_logs_path: "{{ ansible_user_dir }}/zuul-output/logs"
|
||||
|
||||
- name: Copy the console log and inventory for analysis on the test instance
|
||||
copy:
|
||||
src: "{{ zuul.executor.log_root }}/{{ zj_item }}"
|
||||
dest: "{{ _logs_path }}/"
|
||||
loop_control:
|
||||
loop_var: zj_item
|
||||
loop:
|
||||
- "job-output.txt"
|
||||
- "zuul-info"
|
||||
|
||||
- name: Analyse the logs
|
||||
command: >
|
||||
timeout {{ logjuicer_max_run_time }}s {{ logjuicer_cmd }}
|
||||
--report {{ _logs_path }}/logjuicer.{% if zuul_log_compress|default(false) %}gz{% else %}bin{% endif %}
|
||||
zuul-build --api-url {{ zuul_web_url }} {{ _logs_path }}/
|
||||
ignore_errors: true
|
||||
register: _logjuicer_run
|
||||
|
||||
- name: Register the output
|
||||
when: _logjuicer_run.rc == 0
|
||||
zuul_return:
|
||||
data:
|
||||
zuul:
|
||||
artifacts:
|
||||
- name: "LogJuicer Report"
|
||||
url: "logjuicer.html"
|
13
test-playbooks/run-logjuicer.yaml
Normal file
13
test-playbooks/run-logjuicer.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Generate random data
|
||||
command: "echo {{ log_line }}"
|
||||
vars:
|
||||
log_line: "{{ ['eventa occured today', 'eventb happened previously', 'eventc presently failed'] | random }}"
|
||||
|
||||
- name: Run logjuicer
|
||||
include_role:
|
||||
name: run-logjuicer
|
||||
vars:
|
||||
zuul_web_url: https://zuul.opendev.org/
|
@ -15,6 +15,14 @@
|
||||
- test-playbooks/upload-logs-s3.yaml
|
||||
run: test-playbooks/upload-logs-s3.yaml
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-run-logjuicer
|
||||
description: Test the run-logjuicer role
|
||||
files:
|
||||
- roles/run-logjuicer/.*
|
||||
- test-playbooks/run-loreduce.yaml
|
||||
run: test-playbooks/run-logjuicer.yaml
|
||||
|
||||
# -* AUTOGENERATED *-
|
||||
# The following project section is autogenerated by
|
||||
# tox -e update-test-platforms
|
||||
@ -25,6 +33,7 @@
|
||||
jobs: &id001
|
||||
- zuul-jobs-test-local-log-download
|
||||
- zuul-jobs-test-upload-logs-s3
|
||||
- zuul-jobs-test-run-logjuicer
|
||||
gate:
|
||||
jobs: *id001
|
||||
periodic-weekly:
|
||||
|
Loading…
Reference in New Issue
Block a user