Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the role junit2json #591

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

the role junit2json #591

wants to merge 2 commits into from

Conversation

mvk
Copy link
Contributor

@mvk mvk commented Mar 3, 2025

the role converts junit reports into json.

SUMMARY
Motivation:

As a part of group's desire to be able to make decisions based on data, we're investing into CI/Test observability.
The observability effort requires data collection and analysis, currently using Splunk with native data format as JSON + some data tagging/enrichment needs.
Current test reports are junit XML, which therefore needs to be converted and sent to a splunk index.

This role junit2json is handling reports data conversion, using the previously merged json2obj filter.

After merging it we will submit another one for sending the test reports, it should call this one to convert the data and send the resulting .json files as splunk data frames.

Fixes: TELCOV10N-452, TELCOV10N-451

ISSUE TYPE
  • New Feature
Tests
  1. setup standard collections/ansible_collections/redhatci/ocp hierarchy
  2. run the playbook: ansible-playbook collections/ansible_collections/redhatci/ocp/roles/junit2json/tests/test.yml

Depends-on: #510

@mvk mvk requested review from a team as code owners March 3, 2025 03:19
Copy link

Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch 2 times, most recently from d63179e to 65426e8 Compare March 3, 2025 03:39
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 65426e8 to 655392f Compare March 3, 2025 03:50
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 655392f to df3a0a0 Compare March 3, 2025 03:55
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from df3a0a0 to 3453e39 Compare March 3, 2025 04:20
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 3453e39 to f124996 Compare March 3, 2025 06:40
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from f124996 to 3b16d23 Compare March 3, 2025 06:51
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 3b16d23 to 3d5f4ea Compare March 3, 2025 06:59
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 3d5f4ea to 07c2f6b Compare March 3, 2025 07:13
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 07c2f6b to 3f20ea2 Compare March 4, 2025 13:32
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 3f20ea2 to 1699460 Compare March 5, 2025 07:39
Copy link

ansible.builtin.set_fact:
junit2json_xml_report_hash_path: "{{ xml_report }}.{{ junit2json_hash }}"
junit2json_xml_report_hash_curr: "{{ junit2json_xml_report_content | ansible.builtin.hash(junit2json_hash) }}"
junit2json_xml_report_hash_old: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need it here if it's empty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this conversation resolved? I don't see an answer

when:
- junit2json_xml_report_hash_curr != junit2json_xml_report_hash_old

- name: Write json data to destination
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the following two Write tasks, you can use a block with a single when conditional, as they share the same logic and content approx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reply before resolving.

---
# tasks file main.yml for role redhatci.ocp.junit2json

- name: Validate some variables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is more readable:

- name: Validate required variables
  ansible.builtin.assert:
    that:
      - global_reports_path_patterns | length > 0
      - junit2json_input_reports_list | length > 0
      - junit2json_output_dir | length > 0
    fail_msg: "One or more required variables are missing or empty"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree with what I wrote, please change it.

ansible.builtin.assert:
that: "{{ condition }}"
loop:
- global_reports_path_patterns | length > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable should follow the naming convention of the role (be prefixed by junit2json_ keyword)

- name: Setup helper variable
ansible.builtin.set_fact:
junit2json_find_patterns: "{{ global_reports_path_patterns | map('regex_replace', '^', '*.') | list }}"
cacheable: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Var to be prefixed by junit2json keyword

file: expand.yml
loop: "{{ junit2json_input_reports_list }}"
loop_control:
loop_var: path_item
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this var could be renamed to _junit2json_path_item

- junit2json_debug

- name: Merge multiple JUnit XML files into single consolidated report
ansible.builtin.shell:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If just using one single command, please use command module instead of shell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this file is commented, could it be removed or could you move this content to the README?


- name: Update global_json_reports_list
ansible.builtin.set_fact:
global_json_reports_list: "{{ global_json_reports_list | default([]) + [junit2json_output_report_path] }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should prefix this var with junit2json if possible

Copy link
Contributor Author

@mvk mvk Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, @ramperher ,
only role's variables should have role specific prefix (junit2json_ here)
global_ is a legal prefix for cross-role variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.
Taking that into account, where is this global variable intended to be used? Is it going to be consumed by another role from the collections?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see an answer to this question, please answer before resolving the convos.
More feedback: you could put global_json_reports_list in your defaults file and you won't have to use default() here or pass [] as a variable

@mvk mvk force-pushed the mvk/role_junit2json branch from c5e5954 to e01120f Compare March 5, 2025 14:36
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from e01120f to 1fe5fe5 Compare March 5, 2025 14:59
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 1fe5fe5 to 95b9ecf Compare March 5, 2025 15:22
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from 95b9ecf to f822715 Compare March 5, 2025 15:48
Copy link

@mvk mvk requested review from shaior and ramperher March 5, 2025 15:54
@mvk mvk force-pushed the mvk/role_junit2json branch from f822715 to b3be94d Compare March 5, 2025 16:00
Copy link

@mvk mvk force-pushed the mvk/role_junit2json branch from b3be94d to 264af6c Compare March 5, 2025 16:13
Copy link




- **junit2json_input_merged_report**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have a sane default




- **junit2json_output_merged_report**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also have a sane default

ansible.builtin.set_fact:
junit2json_xml_report_hash_path: "{{ xml_report }}.{{ junit2json_hash }}"
junit2json_xml_report_hash_curr: "{{ junit2json_xml_report_content | ansible.builtin.hash(junit2json_hash) }}"
junit2json_xml_report_hash_old: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this conversation resolved? I don't see an answer


- name: Update global_json_reports_list
ansible.builtin.set_fact:
global_json_reports_list: "{{ global_json_reports_list | default([]) + [junit2json_output_report_path] }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see an answer to this question, please answer before resolving the convos.
More feedback: you could put global_json_reports_list in your defaults file and you won't have to use default() here or pass [] as a variable

- name: "Example playbook to use the role redhatci.ocp.junit2json role"
hosts: localhost
vars:
global_json_reports_list: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this vars line is a bad example, because the nature of passing vars to a role makes it so every task inside the role has the same var definition block, every task receives an empty list for this variable, please remove

@mvk mvk force-pushed the mvk/role_junit2json branch 3 times, most recently from ae6416c to 38f057e Compare March 6, 2025 09:04
@mvk
Copy link
Contributor Author

mvk commented Mar 6, 2025

@thekad I think I covered everything.

Copy link

changed_when:
- true

- name: Validate some variables
Copy link
Contributor

@shaior shaior Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Max,
Few comments here please -

  1. The task name does not specify the real intention of this task.
  2. I would put this assertion somewhere at the beginning of the role execution, so that if this package is missing it will fail at an early stage (as @thekad) wrote.
  3. To me it looks redundant to register a variable to represent package cmd, there are more efficient, readable methods to do this, WDYT?

mvk added 2 commits March 6, 2025 17:23
The role converts reports into json, optionally merging multiple fragments into 1 report in loadable json format

- added:
    - role code
    - initial tests
    - example playbook
    - role `README.md` using:

        docsible -g -nob -nop -r roles/junit2json -p roles/junit2json/examples/example_playbook.yml

Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
Updates to `redhat.ocp` collection:

- `galaxy.yml` - upd author and missing tag (fix `ansible-lint` issue)
- `README.md` at collection level
    - filter plugin `redhatci.ocp.junit2obj`
    - role `redhatci.ocp.junit2json`
- create `execution-environment.yml` to specify the collection requirements
    - add 2 requirements files

Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
@mvk mvk force-pushed the mvk/role_junit2json branch from 38f057e to 7f27908 Compare March 6, 2025 15:37
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants