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

ROX-24172: Added compliance report generator to email report #11177

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ksurabhi91
Copy link
Contributor

@ksurabhi91 ksurabhi91 commented May 20, 2024

This PR adds changes to

  • create csvs per cluster and zip them
  • email report

Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 15.88235% with 143 lines in your changes are missing coverage. Please review.

Project coverage is 47.97%. Comparing base (2e6cafa) to head (ffe9bc3).

Files Patch % Lines
...nager/complianceReportgenerator/report_gen_impl.go 17.96% 102 Missing and 3 partials ⚠️
...mplianceoperator/v2/report/manager/manager_impl.go 19.04% 17 Missing ⚠️
pkg/csv/writer.go 0.00% 10 Missing ⚠️
...rt/manager/complianceReportgenerator/report_gen.go 0.00% 5 Missing ⚠️
...ort/manager/complianceReportgenerator/singleton.go 0.00% 5 Missing ⚠️
.../complianceoperator/v2/report/manager/singleton.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11177      +/-   ##
==========================================
- Coverage   47.99%   47.97%   -0.03%     
==========================================
  Files        2335     2338       +3     
  Lines      167192   167357     +165     
==========================================
+ Hits        80248    80283      +35     
- Misses      80575    80704     +129     
- Partials     6369     6370       +1     
Flag Coverage Δ
go-unit-tests 47.97% <15.88%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ksurabhi91 ksurabhi91 force-pushed the generator branch 2 times, most recently from 97e638e to 48b96f9 Compare May 22, 2024 15:25
@ksurabhi91 ksurabhi91 marked this pull request as ready for review May 22, 2024 18:07
@ksurabhi91 ksurabhi91 changed the title Added compliance report generator to email report ROX-24172: Added compliance report generator to email report May 22, 2024
pkg/csv/writer.go Outdated Show resolved Hide resolved
@@ -57,6 +58,20 @@ func (c *GenericWriter) WriteBytes(buf *bytes.Buffer) error {
return nil
}

// WriteBytes writes out csv header and values to the provided buffer
func (c *GenericWriter) WriteCSV(w io.Writer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, why did you take the approach of adding a new method here instead of following the existing pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To write csv data in zip io writer and not create a new buffer like vuln reporting

Copy link
Contributor

Choose a reason for hiding this comment

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

cc: @charmik-redhat to shed light on why it was done differently for vuln. To get better understanding for myself.

return rg.sendEmail(zipData, formatEmailBody, formatEmailSub, req.notifiers, ctx)
}

func (rg *complianceReportGeneratorImpl) getDataforReport(req *ComplianceReportRequest, ctx context.Context) (*resultEmail, error) {
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 we should separate this even further, though that can wait for the follow on work. 1 func to get the overview stats for the body of the email and another to get the actual results of the checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes will do that in following prs

"Mixed:{{.Mixed}} checks \n" +
"Clusters {{.Clusters}} scanned"

defaultSubjectTemplate = "{{.BrandedPrefix}} Compliance Report For {{.ScanConfig}} Profiles {{.Profiles}}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious if adding the list of profiles might make the subject too long

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 can cap max number of profiles that will be added tot he subject

Copy link
Contributor

@dashrews78 dashrews78 left a comment

Choose a reason for hiding this comment

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

Left some comments. You should also write a test

@ksurabhi91 ksurabhi91 force-pushed the generator branch 2 times, most recently from 3107a58 to 8323807 Compare May 28, 2024 21:50
}

type resultEmail struct {
resultCSVs map[string][]*resultRow //map of cluster id to slice of *resultRow
Copy link
Contributor

Choose a reason for hiding this comment

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

This can get very large, need to vet the scale issues

Copy link
Contributor

Choose a reason for hiding this comment

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

Profiles: profiles,
}

return rg.sendEmail(zipData, formatEmailBody, formatEmailSub, req.notifiers, ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to send the email asynchronously and not wait for the send to complete - I think we need to use a go routine in sendEmail to just post it to the notifier and return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made sendemail async but dont know how to make sure that ProcessReportRequest does not exit before sendemail routine completes? I can add waitgroups but then that will block manager to call processreportrequest

@@ -57,6 +58,20 @@ func (c *GenericWriter) WriteBytes(buf *bytes.Buffer) error {
return nil
}

// WriteBytes writes out csv header and values to the provided buffer
func (c *GenericWriter) WriteCSV(w io.Writer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

cc: @charmik-redhat to shed light on why it was done differently for vuln. To get better understanding for myself.

@ksurabhi91 ksurabhi91 force-pushed the generator branch 6 times, most recently from f124c59 to 6afeb83 Compare May 30, 2024 20:44
// ProcessReportRequest will generate a csv report and send notification via email to attached scan config notifiers.
ProcessReportRequest(req *ComplianceReportRequest) error

getDataForReport(req *ComplianceReportRequest) (*resultEmail, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems odd that we have private funcs in an interface. Should this just be a struct and not an interface?

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 have removed private functions

@ksurabhi91 ksurabhi91 force-pushed the generator branch 3 times, most recently from 24b401b to 67cc1f3 Compare May 31, 2024 19:15
Copy link

openshift-ci bot commented May 31, 2024

@ksurabhi91: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ocp-4-candidate-qa-e2e-tests 977397f link false /test ocp-4-candidate-qa-e2e-tests
ci/prow/ocp-4-candidate-operator-e2e-tests 977397f link false /test ocp-4-candidate-operator-e2e-tests
ci/prow/ocp-4-candidate-compliance-e2e-tests 977397f link false /test ocp-4-candidate-compliance-e2e-tests

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@rhacs-bot
Copy link
Contributor

Images are ready for the commit at ffe9bc3.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.4.x-841-gffe9bc3bf9.

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

Successfully merging this pull request may close these issues.

None yet

4 participants