Skip to content

Commit 6709108

Browse files
authored
[core][fix] Count failing resources correctly (#2269)
1 parent a0d35cb commit 6709108

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

fixcore/fixcore/report/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,21 +386,23 @@ def visit_check_collection(collection: CheckCollectionResult) -> None:
386386
return result
387387

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

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

403404
available_failing(self) # walk the benchmark hierarchy
405+
failing_resources = {severity: len(ids) for severity, ids in failing_resource_ids.items()}
404406
missing = sum(severity.score * count for severity, count in failing_checks.items())
405407
total = sum(severity.score * count for severity, count in available.items())
406408
return BenchmarkScore(

fixcore/fixcore/report/inspector_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from collections import defaultdict
33
from functools import lru_cache
4-
from typing import Optional, List, Dict, Tuple, Callable, AsyncIterator, cast
4+
from typing import Optional, List, Dict, Tuple, Callable, AsyncIterator, cast, Set
55

66
from aiostream import stream, pipe
77
from aiostream.core import Stream
@@ -267,11 +267,13 @@ async def perform_benchmarks(
267267

268268
def account_failing(account_id: str) -> Json:
269269
failing_checks: Dict[ReportSeverity, int] = defaultdict(int)
270-
failing_resources: Dict[ReportSeverity, int] = defaultdict(int)
270+
failing_resource_ids: Dict[ReportSeverity, Set[str]] = defaultdict(set)
271271
for cr in all_checks.values():
272272
if fr := cr.resources_failing_by_account.get(account_id, []):
273273
failing_checks[cr.check.severity] += 1
274-
failing_resources[cr.check.severity] += len(fr)
274+
for r in fr:
275+
failing_resource_ids[cr.check.severity].add(r["node_id"])
276+
failing_resources = {sev: len(ids) for sev, ids in failing_resource_ids.items()}
275277
return {
276278
sev.value: {"checks": count, "resources": failing_resources[sev]}
277279
for sev, count in failing_checks.items()

0 commit comments

Comments
 (0)