@@ -589,12 +589,9 @@ async def issues_since(
589589 )
590590
591591 async def benchmark_summary (
592- benmark_account_summaries : Dict [BenchmarkId , Dict [CloudAccountId , BenchmarkAccountSummary ]]
593- ) -> Tuple [
594- BenchmarkById , Dict [ReportSeverity , Set [SecurityCheckId ]], Dict [SecurityCheckId , Set [BenchmarkId ]]
595- ]:
592+ bench_account_summaries : Dict [BenchmarkId , Dict [CloudAccountId , BenchmarkAccountSummary ]]
593+ ) -> Tuple [BenchmarkById , Dict [SecurityCheckId , Set [BenchmarkId ]]]:
596594 summaries : BenchmarkById = {}
597- failed_checks_by_severity : Dict [ReportSeverity , Set [SecurityCheckId ]] = defaultdict (set )
598595 benchmark_by_check_id : Dict [SecurityCheckId , Set [BenchmarkId ]] = defaultdict (set )
599596 benchmarks = await self .client .benchmarks (db , short = True , with_checks = True )
600597 for b in benchmarks :
@@ -607,15 +604,13 @@ async def benchmark_summary(
607604 clouds = b ["clouds" ],
608605 description = b ["description" ],
609606 nr_of_checks = len (b ["report_checks" ]),
610- account_summary = benmark_account_summaries .get (benchmark_id , {}),
607+ account_summary = bench_account_summaries .get (benchmark_id , {}),
611608 )
612609 summaries [summary .id ] = summary
613610 for check in b ["report_checks" ]:
614611 check_id = SecurityCheckId (check ["id" ])
615- severity = ReportSeverity (check ["severity" ])
616- failed_checks_by_severity [severity ].add (check_id )
617612 benchmark_by_check_id [check_id ].add (benchmark_id )
618- return summaries , failed_checks_by_severity , benchmark_by_check_id
613+ return summaries , benchmark_by_check_id
619614
620615 async def timeseries_infected () -> TimeSeries :
621616 start = now - timedelta (days = 62 if is_free else 14 )
@@ -628,13 +623,21 @@ async def timeseries_infected() -> TimeSeries:
628623 return TimeSeries (name = "infected_resources" , start = start , end = now , granularity = granularity , data = data )
629624
630625 async def top_issues (
631- checks_by_severity : Dict [ReportSeverity , Set [SecurityCheckId ]],
632626 benchmark_by_check_id : Dict [SecurityCheckId , Set [BenchmarkId ]],
633627 benchmarks : Dict [BenchmarkId , BenchmarkSummary ],
634628 num : int ,
635629 ) -> List [Json ]:
636- check_ids = dict_values_by (checks_by_severity , lambda x : ReportSeverityPriority [x ])
637- top = list (islice (check_ids , num ))
630+ query = (
631+ "aggregate(/security.issues[*].check, /security.issues[*].severity: sum(1) as count): "
632+ "/security.has_issues==true"
633+ )
634+ async with self .client .aggregate (db , query ) as ctx :
635+ all_failing = sorted (
636+ [e async for e in ctx ],
637+ key = lambda x : (ReportSeverityPriority [x ["group" ]["severity" ]], x ["count" ]),
638+ reverse = True ,
639+ )
640+ top = list (islice ((a ["group" ]["check" ] for a in all_failing ), num ))
638641 checks = await self .client .checks (db , check_ids = top )
639642 for check in checks :
640643 check ["benchmarks" ] = [
@@ -657,7 +660,7 @@ def overall_score(
657660 return total_score // total_accounts if total_accounts > 0 else 100
658661
659662 (
660- (benchmarks , failed_checks_by_severity , benchmark_by_check_id ),
663+ (benchmarks , benchmark_by_check_id ),
661664 vulnerable_changed ,
662665 compliant_changed ,
663666 infected_resources_ts ,
@@ -669,7 +672,7 @@ def overall_score(
669672 )
670673
671674 # get issues for the top 5 issue_ids
672- tops = await top_issues (failed_checks_by_severity , benchmark_by_check_id , benchmarks , num = 5 )
675+ tops = await top_issues (benchmark_by_check_id , benchmarks , num = 5 )
673676
674677 # sort top changed account by score
675678 vulnerable_changed .accounts_selection .sort (
0 commit comments