Skip to content

Conversation

mvk
Copy link
Contributor

@mvk mvk commented Aug 21, 2025

implements:

  1. filter plugin junuit2obj converts a junit xml report to json report of similar structure
  2. filter plugin reportsmerger merges several json reports into 1 big report, updating aggregate metrics (counters, times)
  3. role junit2json the role to be used to convert and merge junit xml reports
  4. unit tests for both plugins

@openshift-ci openshift-ci bot requested review from cplacani and kononovn August 21, 2025 10:04
- name: Expand the input list to list of existing files
ansible.builtin.include_tasks:
file: expand.yml
loop: "{{ junit2_input_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 is not a list - in the default.yml it set as a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This variable is a list of str, defined here: playbooks/infra/reporting/roles/junit2json/meta/argument_specs.yml, the 1st variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

thats not a var location - it's metadata
under ./default/main.yml the var is defined as str

file: expand.yml
loop: "{{ junit2_input_reports_list }}"
loop_control:
loop_var: file_name
Copy link
Contributor

Choose a reason for hiding this comment

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

where is the var coming from ?

Copy link
Contributor

Choose a reason for hiding this comment

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

also change the name -- file_name is too generic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. junit2_input_reports_list is role's variable (refer to defaults/main.yml and meta/argument_spec.yml),
  2. loop_var is how I set the name of the variable instead of item (for the loop, to be used inside expand.yml

Copy link
Contributor

@eifrach eifrach left a comment

Choose a reason for hiding this comment

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

This is very complex - there is a lot of naming issues / redandant tasks and vars

please go over the comment - and try to make it simpler and shorter

we can skip / merge quite a few steps here
I'll review it once your done

file: expand.yml
loop: "{{ junit2_input_reports_list }}"
loop_control:
loop_var: file_name
Copy link
Contributor

Choose a reason for hiding this comment

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

also change the name -- file_name is too generic

- name: Collect file_name stat
ansible.builtin.stat:
path: "{{ file_name }}"
register: _junit2json_path_item_stat
Copy link
Contributor

Choose a reason for hiding this comment

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

the name should include the task name or the file name
example

Suggested change
register: _junit2json_path_item_stat
register: _expand_file_stat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want the file_name to be as generic, so that I can do ansible.builtin.import_tasks from this role in another role.

Comment on lines 18 to 19
- not(_junit2json_path_item_stat.stat.isdir | default(false))
- _junit2json_path_item_stat.stat.exists | default(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for default

Suggested change
- not(_junit2json_path_item_stat.stat.isdir | default(false))
- _junit2json_path_item_stat.stat.exists | default(false)
- not(_junit2json_path_item_stat.stat.isdir
- _junit2json_path_item_stat.stat.exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ansible.builtin.set_fact:
junit2_reports_list: "{{ junit2_reports_list + [file_name] }}"
when:
- _junit2json_path_item_stat.stat.exists | default(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- _junit2json_path_item_stat.stat.exists | default(false)
- _junit2json_path_item_stat.stat.exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


- name: Update junit2_reports_list with a JUnit XML report item
ansible.builtin.set_fact:
junit2_reports_list: "{{ junit2_reports_list + [file_name] }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

you initialize this as empty value and then you trying to add empty with the file_name?

lets do the initialisation here and remove it from main

Copy link
Contributor Author

@mvk mvk Aug 21, 2025

Choose a reason for hiding this comment

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

@eifrach because I am testing this role in several calls to the role, the list must be reset this list each time the code is in tasks/main.yml. (Otherwise this list will be updated each run)
It is possible to put it deeper than tasks/main.yml, but I think tasks/main.yml` is more readable.
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to change you're code to make you test work
it should be the other way around

Comment on lines 26 to 32
- name: Ensure junit2_output_dir is created
ansible.builtin.include_tasks:
file: ensure-dir.yml
loop:
- "{{ junit2_output_dir }}"
loop_control:
loop_var: folder_path
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 a loop ? are we creating more than one folder?

also if you only create the folder once no need to put it in a new file / playboolk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eifrach 👍 thank you, good catch, it is a left-over

content: "{{ junit2_result_data | junit2obj | to_nice_json(indent=2) }}"
dest: "{{ junit2_output_report_path }}"
mode: '0644'
when: not junit2_out_str | bool
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get this please explain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 use cases:

  • with the filter to_nice_json(indent=2) creates a serializable JSON data, is easy to read and compare, load and merge.
  • without the filter, a single string is created. It is more convenient for dumping all of it in a template.

content: "{{ junit2_result_data | junit2obj }}"
dest: "{{ junit2_output_report_path }}"
mode: '0644'
when: junit2_out_str | bool
Copy link
Contributor

Choose a reason for hiding this comment

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

same

ansible.builtin.include_tasks:
file: merge.yml
when:
- junit2_do_merge
Copy link
Contributor

Choose a reason for hiding this comment

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

there are cases when we don't merge it ?

Copy link
Contributor

Choose a reason for hiding this comment

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

if so when does it change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

during tests mainly.

Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to test a case we don't use

Comment on lines +8 to +10
- name: Load dummy variables configuration
ansible.builtin.include_vars:
file: dummy_variables.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the data inside test reports sometimes contains parts of jinja code, Please refer to this file:
https://github.com/mvk/eco-ci-cd/blob/role-junit2obj/playbooks/infra/reporting/roles/junit2json/doc/dummy_variables.md

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The name of the role and the file are not related to what it's for
  2. can you explain why we shouldn't create a simple python script to do this instead of this complex steps ?

@shaior
Copy link
Contributor

shaior commented Aug 21, 2025

General comment - you added a role under playbooks/infra/reporting but this path is not included under roles_path in ansible.cfg.

Also, it's very difficult to review this since it's too long, I would split it into several much shorter PRs with proper documentation.

Copy link

openshift-ci bot commented Aug 21, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from eifrach. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mvk mvk force-pushed the role-junit2obj branch 4 times, most recently from ee0df99 to 948ee49 Compare August 21, 2025 20:55
@mvk
Copy link
Contributor Author

mvk commented Aug 21, 2025

General comment - you added a role under playbooks/infra/reporting but this path is not included under roles_path in ansible.cfg.

Also, it's very difficult to review this since it's too long, I would split it into several much shorter PRs with proper documentation.

@shaior, I referred to storing-and-finding-roles, namely:

in a directory called roles/, relative to the playbook file

this means we don't have to update ansible.cfg.

@mvk
Copy link
Contributor Author

mvk commented Aug 21, 2025

General comment - you added a role under playbooks/infra/reporting but this path is not included under roles_path in ansible.cfg.

Also, it's very difficult to review this since it's too long, I would split it into several much shorter PRs with proper documentation.

@shaior

splitting this one into several commits now, will comment on it, then I will break it down to several PRs by those commits.

@mvk mvk force-pushed the role-junit2obj branch 4 times, most recently from d9ddf94 to 19bffd2 Compare August 23, 2025 00:30
mvk added 4 commits August 24, 2025 19:27
Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
- code
- tests + data

Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
@eifrach
Copy link
Contributor

eifrach commented Aug 25, 2025

  1. I feel this is very complex and we can do it in a simple python script
  2. too many workarounds and supporting documentation just to make it work is very bad practice
  3. also I think if you use Ansible builtin feature for ansible.utils.from_xml it will solve a lot of issues and workarounds

let's talk to the team and re evaluate this

cc @shaior @kononovn

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.

3 participants