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

refactor(report): write tables after rendering all results #8357

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

Conversation

DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented Feb 5, 2025

Description

We need to use the one renderer (for each result Type) for all results, for the correct operation of logs, once functions, etc.

Current logic

  • we create new Renderer for each result (see this)
  • we create a buffer for each renderer and write the tables immediately after rendering the result

New logic

  • We create one Renderer (for each type) for Report.
  • we create one buffer and write tables only after rendering all results.

FilePath log mistake example:
before:

➜  trivy -d rootfs --scanners vuln,secret /Users/dmitriy/work/tmp/8177        
...
2025-02-05T14:57:18+06:00       INFO    Table result includes only package filenames. Use '--format json' option to get the full path to the package file.

Java (jar)

Total: 4 (UNKNOWN: 0, LOW: 0, MEDIUM: 2, HIGH: 2, CRITICAL: 0)

...
2025-02-05T14:57:18+06:00       INFO    Table result includes only package filenames. Use '--format json' option to get the full path to the package file.

Node.js (node-pkg)

Total: 5 (UNKNOWN: 0, LOW: 0, MEDIUM: 2, HIGH: 2, CRITICAL: 1)
...

after:

➜   ./trivy -d rootfs --scanners vuln,secret /Users/dmitriy/work/tmp/8177
...
2025-02-05T14:57:07+06:00       INFO    Table result includes only package filenames. Use '--format json' option to get the full path to the package file.

Java (jar)

Total: 4 (UNKNOWN: 0, LOW: 0, MEDIUM: 2, HIGH: 2, CRITICAL: 0)

...

Node.js (node-pkg)

Total: 5 (UNKNOWN: 0, LOW: 0, MEDIUM: 2, HIGH: 2, CRITICAL: 1)
...

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Feb 5, 2025
@DmitriyLewen DmitriyLewen mentioned this pull request Feb 5, 2025
12 tasks
Comment on lines 93 to 97
_, _ = fmt.Fprint(tw.Output, tw.vulnerabilityRenderer.Flush())
_, _ = fmt.Fprint(tw.Output, tw.misconfigRenderer.Flush())
_, _ = fmt.Fprint(tw.Output, tw.secretRenderer.Flush())
_, _ = fmt.Fprint(tw.Output, tw.pkgLicenseRenderer.Flush())
_, _ = fmt.Fprint(tw.Output, tw.fileLicenseRenderer.Flush())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can pass bytes.Buffer to each renderer rather than each renderer holding its own buffer. The buffer will be flushed at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

something like 4e93197?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes 👍

pkg/report/table/table.go Outdated Show resolved Hide resolved
@knqyf263
Copy link
Collaborator

knqyf263 commented Feb 7, 2025

@danielciuraru86 We want to change the interface of table.Writer slightly. It may require a tiny change on your end. Can you please take a look?

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.

2 participants