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

Enhancements for XSC analytics metrics capabilities to support application in Frogbot #50

Merged
merged 35 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
12dbe00
Add Xsc General Event
gailazar300 Mar 24, 2024
cbc4fcd
Add Xsc General Event
gailazar300 Mar 26, 2024
1951727
Before review fixes.
gailazar300 Mar 26, 2024
c834ad1
Add UpdateGeneralEvent.
gailazar300 Mar 27, 2024
f9c9c0e
Set environments variables for analyzer manager.
gailazar300 Mar 27, 2024
a4f0534
Add tests.
gailazar300 Mar 28, 2024
abc6553
Remove error handling for analytics.
gailazar300 Mar 28, 2024
e79cb1e
Change AnalyticsMetricsService creation.
gailazar300 Mar 28, 2024
b45d003
Merge remote-tracking branch 'upstream/dev' into feature/XRAY-36905
gailazar300 Mar 31, 2024
b3452da
go.mod+sum
gailazar300 Mar 31, 2024
fdb5051
Minor fixes.
gailazar300 Mar 31, 2024
4c68943
Review fixes.
gailazar300 Apr 1, 2024
2c9fcba
Add integration test.
gailazar300 Apr 1, 2024
fc0f2df
Minor fixes.
gailazar300 Apr 1, 2024
b9560da
Change add general event flow for Frogbot.
gailazar300 Apr 2, 2024
040ce9b
Second review fixes.
gailazar300 Apr 2, 2024
40884cb
Remove Frogbot's MSI validation - there is no common flow for cli and…
gailazar300 Apr 2, 2024
51de09a
Minor fix.
gailazar300 Apr 2, 2024
df4ef8f
Minor fix.
gailazar300 Apr 3, 2024
08b1764
Minor fix.
gailazar300 Apr 3, 2024
afc8843
Change UpdateGeneralEvent & moving relevant code from core
gailazar300 Apr 3, 2024
b133a9a
go.mod+sum
gailazar300 Apr 3, 2024
1a2c652
minor fix
gailazar300 Apr 3, 2024
abea15c
minor fix
gailazar300 Apr 3, 2024
f0fdb3a
Fix sending scan to xsc if available.
gailazar300 Apr 3, 2024
e30c3d2
Add CountScanResultsFindings.
gailazar300 Apr 3, 2024
15164f4
adding function and methods to support analytics report in Frogbot
eranturgeman Apr 3, 2024
3c402ab
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Apr 8, 2024
bd25380
resolve conflicts
eranturgeman Apr 8, 2024
f2ccfe7
resolve conflicts
eranturgeman Apr 8, 2024
7a48891
resolve conflicts
eranturgeman Apr 8, 2024
fdc7dd5
fix tests issues
eranturgeman Apr 8, 2024
6d95759
fix CR comments
eranturgeman Apr 9, 2024
3b4cadf
fix go.mod
eranturgeman Apr 10, 2024
16cfb5c
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions utils/analyticsmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,20 @@ func (ams *AnalyticsMetricsService) CreateXscAnalyticsGeneralEventFinalizeFromAu
XscAnalyticsBasicGeneralEvent: basicEvent,
}
}

func (ams *AnalyticsMetricsService) UpdateXscAnalyticsGeneralEventFinalizeWithTotalScanDuration() {
totalDuration := time.Since(ams.GetStartTime())
ams.finalizeEvent.TotalScanDuration = totalDuration.String()
}

func (ams *AnalyticsMetricsService) UpdateXscAnalyticsGeneralEventFinalizeStatus(status xscservices.EventStatus) {
ams.finalizeEvent.EventStatus = status
}

func (ams *AnalyticsMetricsService) AddScanFindingsToXscAnalyticsGeneralEventFinalize(findingsAmount int) {
ams.finalizeEvent.TotalFindings += findingsAmount
}

func (ams *AnalyticsMetricsService) SetShouldReportEvents(shouldReportEvents bool) {
ams.shouldReportEvents = shouldReportEvents
}
eranturgeman marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 23 additions & 19 deletions utils/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,41 @@ func (r *Results) IsIssuesFound() bool {
return false
}

// Counts the total amount of findings in the provided results and updates the AnalyticsMetricsService with the amount of the new added findings
// Counts the total number of unique findings in the provided results.
// A unique SCA finding is identified by a unique pair of vulnerability's/violation's issueId and component id or by a result returned from one of JAS scans.
func (r *Results) CountScanResultsFindings() int {
findingsCountMap := make(map[string]int)
var totalFindings int
totalFindings += getScaResultsUniqueFindingsAmount(&r.ScaResults)

// Counting ScaResults
for _, scaResult := range r.ScaResults {
if r.ExtendedScanResults != nil {
totalFindings += len(r.ExtendedScanResults.SastScanResults)
totalFindings += len(r.ExtendedScanResults.IacScanResults)
totalFindings += len(r.ExtendedScanResults.SecretsScanResults)
}

return totalFindings
}

func getScaResultsUniqueFindingsAmount(scaScanResults *[]ScaScanResult) int {
uniqueXrayFindings := datastructures.MakeSet[string]()

for _, scaResult := range *scaScanResults {
for _, xrayResult := range scaResult.XrayResults {
// XrayResults may contain Vulnerabilities OR Violations, but not both. Therefore, only one of them will be counted
for _, vulnerability := range xrayResult.Vulnerabilities {
findingsCountMap[vulnerability.IssueId] += len(vulnerability.Components)
for compId := range vulnerability.Components {
uniqueXrayFindings.Add(vulnerability.IssueId + compId)
}
}

for _, violation := range xrayResult.Violations {
findingsCountMap[violation.IssueId] += len(violation.Components)
for compId := range violation.Components {
uniqueXrayFindings.Add(violation.IssueId + compId)
}
}
}
}

for _, issueIdCount := range findingsCountMap {
totalFindings += issueIdCount
}

// Counting ExtendedScanResults
if r.ExtendedScanResults != nil {
totalFindings += len(r.ExtendedScanResults.SastScanResults)
totalFindings += len(r.ExtendedScanResults.IacScanResults)
totalFindings += len(r.ExtendedScanResults.SecretsScanResults)
}

return totalFindings
return uniqueXrayFindings.Size()
}

type ScaScanResult struct {
Expand Down
Loading