← Back to Pull requests

[AAP-103751] perf: fix tarball collection filtering, single-pass tar extraction, and S3 client caching #659

Closed
unknown closed this pull request without merging on Nov 27, 2026 11:13 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 15:46 UTC
Author

Description

  • Fix dead tarball collection filter (metrics_utility/automation_controller_billing/extract/base.py): Base.filter_tarball_paths() checked if s.find('-unknown.') or s.find('-config.'): return True. Because str.find() returns -1 when a substring is absent and -1 is truthy in Python, the filter always returned True and never excluded unrelated modern collection tarballs. Replaced with '-unknown.' in s or '-config.' in s and precompiled the legacy/modern suffix regexes with literal escaped dots (\.tar\.gz$). Legacy (<= 0.6.0), -unknown., -config., and unexpected filenames remain unconditionally included. Removed the obsolete # FIXME in extractor_s3.py.

  • Single-pass tar extraction (extract/base.py): Switched _safe_extract() from for member in tar.getmembers(): to for member in tar: and hoisted os.path.abspath(extract_path) out of the loop, avoiding decompressing .tar.gz archives twice when extractfile() rewinds a gzip stream.

  • Cache boto3 S3 client/resource (metrics_utility/automation_controller_billing/base/s3_handler.py): Cached self._s3_client and self._s3_resource on S3Handler, and updated upload_file() and list_files() to use self.get_s3_client() directly rather than creating a new ServiceResource per call.
  • Testing

    Steps to Test

    1. Run unit tests:

       pytest metrics_utility/test/test_extract_base.py metrics_utility/test/test_report_renderers.py
       pytest metrics_utility/test/validation/test_s3_env.py -k s3handler
       

    2. Run paired alternating-order benchmarks (3 pairs in separate processes) on a containerized AAP cont_b Controller (automation-controller-task, Python 3.12.16, pandas 3.0.3):
    - Full 31-day / 124-archive synthetic CCSPv2 XLSX report (all optional sheets, ccsp-experimental), checking workbook digests across all runs.
    - S3Handler workload simulating 124 list_files() + 248 download_file() calls using real boto3.Session with stubbed transport.

    Expected Results

  • All unit tests pass (102 passed locally).

  • Tarball filtering + single-pass extraction (synthetic local-disk 31-day CCSPv2 XLSX): median wall time dropped from 30.93 s to 29.41 s (−4.92%), process_tarballs() calls dropped from 496 to 248 (−50%) (eliminating 50%–75% of redundant S3 downloads on S3 targets), peak RSS unchanged (278.45 → 278.79 MiB), all 6 workbook digests matched.

  • S3Handler client caching (synthetic 124 list_files + 248 download_file): median wall time dropped from 1.51 s to 0.10 s (−93.22%), boto3 clients created 372 → 1, resources 124 → 0, peak RSS 62.18 → 59.30 MiB, output digests matched.
  • (Synthetic source-checkout measurements in a disposable Controller container; not a guarantee for every customer workload.)

    Self-Review Checklist

    Code Quality

  • Code is properly linted and formatted.

  • All tests (existing and new) pass successfully.

  • Tests are added or updated as needed.

  • Code includes relevant comments for complex sections.

  • Changes are reviewed and approved by at least two team members.

  • Documentation is updated where applicable.

  • - If updates are required in the handbook, create a separate PR for the handbook repo.

    Diff: 415 lines (+311 / -104) across 5 files Reviewer: redhat-chai-bot Review duration: 1167m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 415 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #659"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%