Skip to content

Commit

Permalink
[core][fix] Count failing resources correctly (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Oct 29, 2024
1 parent a0d35cb commit 6709108
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 6 additions & 4 deletions fixcore/fixcore/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,21 +386,23 @@ def visit_check_collection(collection: CheckCollectionResult) -> None:
return result

# score, failed_checks, failed_resources
def score_for(self, account: str) -> BenchmarkScore:
def score_for(self, account_id: str) -> BenchmarkScore:
failing_checks: Dict[ReportSeverity, int] = defaultdict(int)
failing_resources: Dict[ReportSeverity, int] = defaultdict(int)
failing_resource_ids: Dict[ReportSeverity, Set[str]] = defaultdict(set)
available: Dict[ReportSeverity, int] = defaultdict(int)

def available_failing(check: CheckCollectionResult) -> None:
for result in check.checks:
fr = result.number_of_resources_failing_by_account.get(account, 0)
fr = result.resources_failing_by_account.get(account_id, [])
available[result.check.severity] += 1
failing_checks[result.check.severity] += 1 if fr else 0
failing_resources[result.check.severity] += fr
for r in fr:
failing_resource_ids[result.check.severity].add(r["node_id"])
for child in check.children:
available_failing(child)

available_failing(self) # walk the benchmark hierarchy
failing_resources = {severity: len(ids) for severity, ids in failing_resource_ids.items()}
missing = sum(severity.score * count for severity, count in failing_checks.items())
total = sum(severity.score * count for severity, count in available.items())
return BenchmarkScore(
Expand Down
8 changes: 5 additions & 3 deletions fixcore/fixcore/report/inspector_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections import defaultdict
from functools import lru_cache
from typing import Optional, List, Dict, Tuple, Callable, AsyncIterator, cast
from typing import Optional, List, Dict, Tuple, Callable, AsyncIterator, cast, Set

from aiostream import stream, pipe
from aiostream.core import Stream
Expand Down Expand Up @@ -267,11 +267,13 @@ async def perform_benchmarks(

def account_failing(account_id: str) -> Json:
failing_checks: Dict[ReportSeverity, int] = defaultdict(int)
failing_resources: Dict[ReportSeverity, int] = defaultdict(int)
failing_resource_ids: Dict[ReportSeverity, Set[str]] = defaultdict(set)
for cr in all_checks.values():
if fr := cr.resources_failing_by_account.get(account_id, []):
failing_checks[cr.check.severity] += 1
failing_resources[cr.check.severity] += len(fr)
for r in fr:
failing_resource_ids[cr.check.severity].add(r["node_id"])
failing_resources = {sev: len(ids) for sev, ids in failing_resource_ids.items()}
return {
sev.value: {"checks": count, "resources": failing_resources[sev]}
for sev, count in failing_checks.items()
Expand Down

0 comments on commit 6709108

Please sign in to comment.