-
Notifications
You must be signed in to change notification settings - Fork 3
feat(vulnerability): add filter by region #1113
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| query{ | ||
| VulnerabilityFilterValues{ | ||
| region { | ||
| displayName | ||
| filterName | ||
| values | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
| -- SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| DROP EVENT IF EXISTS refresh_mvCountIssueRatingsRegion; | ||
|
|
||
| DROP PROCEDURE IF EXISTS refresh_mvCountIssueRatingsRegion_proc; | ||
|
|
||
| DROP TABLE IF EXISTS mvCountIssueRatingsRegion; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| -- SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
| -- SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| CREATE TABLE IF NOT EXISTS mvCountIssueRatingsRegion ( | ||
| region VARCHAR(1024) UNIQUE, | ||
| critical_count INT DEFAULT 0, | ||
| high_count INT DEFAULT 0, | ||
| medium_count INT DEFAULT 0, | ||
| low_count INT DEFAULT 0, | ||
| none_count INT DEFAULT 0, | ||
| is_active TINYINT(1) NOT NULL DEFAULT 1 | ||
| ); | ||
kanstantsinbuklis-sap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CREATE PROCEDURE IF NOT EXISTS refresh_mvCountIssueRatingsRegion_proc() | ||
| BEGIN | ||
| UPDATE mvCountIssueRatingsRegion | ||
kanstantsinbuklis-sap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SET is_active = 0 | ||
| WHERE is_active = 1; | ||
|
|
||
| INSERT INTO mvCountIssueRatingsRegion | ||
| (region, critical_count, high_count, medium_count, low_count, none_count, is_active) | ||
| SELECT | ||
| DISTINCT CI.componentinstance_region, | ||
| COUNT(DISTINCT CASE WHEN IV.issuevariant_rating = 'Critical' THEN IV.issuevariant_issue_id END), | ||
| COUNT(DISTINCT CASE WHEN IV.issuevariant_rating = 'High' THEN IV.issuevariant_issue_id END), | ||
| COUNT(DISTINCT CASE WHEN IV.issuevariant_rating = 'Medium' THEN IV.issuevariant_issue_id END), | ||
| COUNT(DISTINCT CASE WHEN IV.issuevariant_rating = 'Low' THEN IV.issuevariant_issue_id END), | ||
| COUNT(DISTINCT CASE WHEN IV.issuevariant_rating = 'None' THEN IV.issuevariant_issue_id END), | ||
| 1 | ||
| FROM Issue I | ||
| LEFT JOIN IssueVariant IV ON IV.issuevariant_issue_id = I.issue_id | ||
| RIGHT JOIN IssueMatch IM ON I.issue_id = IM.issuematch_issue_id | ||
| LEFT JOIN ComponentInstance CI ON CI.componentinstance_id = IM.issuematch_component_instance_id | ||
| WHERE I.issue_deleted_at IS NULL | ||
| GROUP BY CI.componentinstance_region | ||
| ON DUPLICATE KEY UPDATE | ||
| critical_count = VALUES(critical_count), | ||
| high_count = VALUES(high_count), | ||
| medium_count = VALUES(medium_count), | ||
| low_count = VALUES(low_count), | ||
| none_count = VALUES(none_count), | ||
| is_active = 1; | ||
|
|
||
| DELETE FROM mvCountIssueRatingsRegion | ||
| WHERE is_active = 0; | ||
| END; | ||
|
|
||
| CREATE EVENT IF NOT EXISTS refresh_mvCountIssueRatingsRegion | ||
| ON SCHEDULE EVERY 2 HOUR | ||
| DO | ||
| CALL refresh_mvCountIssueRatingsRegion_proc(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ func getCountTable(filter *entity.IssueFilter) string { | |
| } else if len(filter.ServiceCCRN) > 0 || len(filter.ServiceId) > 0 { | ||
| // Count issues that appear in single service | ||
| return "mvCountIssueRatingsServiceId" | ||
| } else if len(filter.Region) > 0 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| return "mvCountIssueRatingsRegion" | ||
| } else { | ||
| // Total count of issues | ||
| return "mvCountIssueRatingsOther" | ||
|
|
@@ -76,6 +78,11 @@ func (s *SqlDatabase) CountIssueRatings(filter *entity.IssueFilter) (*entity.Iss | |
| fl = append(fl, buildFilterQuery(filter.SupportGroupCCRN, "CIR.supportgroup_ccrn = ?", OP_OR)) | ||
| } | ||
|
|
||
| if len(filter.Region) > 0 { | ||
| filterParameters = buildQueryParameters(filterParameters, filter.Region) | ||
| fl = append(fl, buildFilterQuery(filter.Region, "CIR.region = ?", OP_OR)) | ||
| } | ||
kanstantsinbuklis-sap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| filterStr := combineFilterQueries(fl, OP_AND) | ||
| if filterStr != "" { | ||
| query = fmt.Sprintf("%s WHERE %s", query, filterStr) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,16 @@ var _ = Describe("Counting Issues by Severity", Label("IssueCounts"), func() { | |
| testIssueSeverityCount(filter, counts) | ||
| } | ||
|
|
||
| testRegionTotalCount := func(counts map[string]entity.IssueSeverityCounts) { | ||
| for _, cir := range seedCollection.ComponentInstanceRows { | ||
| filter := &entity.IssueFilter{ | ||
| Region: []*string{&cir.Region.String}, | ||
| } | ||
|
|
||
| testIssueSeverityCount(filter, counts[cir.Region.String]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not working as intended. All items in |
||
| } | ||
| } | ||
|
|
||
| insertRemediation := func(serviceRow *mariadb.BaseServiceRow, componentRow *mariadb.ComponentRow, expirationDate time.Time) *entity.Remediation { | ||
| remediation := test.NewFakeRemediation() | ||
| if serviceRow != nil { | ||
|
|
@@ -488,6 +498,13 @@ var _ = Describe("Counting Issues by Severity", Label("IssueCounts"), func() { | |
|
|
||
| testServicesTotalCount(totalCount) | ||
| }) | ||
|
|
||
| It("return the total count with region filter", func() { | ||
| severityCounts, err := test.LoadRegionIssueCounts(test.GetTestDataPath("../mariadb/testdata/issue_counts/issue_counts_per_region.json")) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| testRegionTotalCount(severityCounts) | ||
| }) | ||
kanstantsinbuklis-sap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| When("there is an active remediation for a vulnerability only in one service", Label("WithRemediations"), func() { | ||
| BeforeEach(func() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The database doesn't resolve the relations, so this check will never be executed. You need to collect the entities from the
seedCollection