← Back to Pull requests

[AAP-103750] perf: optimize CCSPv2 fact/set merges and skip discarded node-usage columns #658

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

Description

Follow-up to #654 optimizing the remaining pure-Python hot paths in CCSP/CCSPv2 report aggregation and sheet building:

  • JSON/set merge fast-paths (metrics_utility/automation_controller_billing/helpers.py, dataframe_engine/base.py):

  • - In merge_json_sets() and combine_json_values(): skip calling make_hashable() on elements already inside a Python set (copying on first insert so caller sets are never mutated), fast-path exact primitive scalars (str, int, float, bool) past make_hashable(), replace setdefault(key, set()) with if key in merged: to avoid allocating throwaway sets on existing keys, and short-circuit empty/non-dict pairs in combine_json_values().
    - In combine_set(): fast-path two plain sets (set1 | set2).
  • Parse canonical_facts once (dataframe_engine/dataframe_inventory_scope.py): Parse billing_data['canonical_facts'] once with parse_json() before serial_from_facts() and self.group(), halving json.loads() calls on main_host.canonical_facts.

  • Skip aggregating & JSON-converting discarded columns (report/base.py): In _build_data_section_usage_by_node(), compute include_orgs, include_facts, and include_indirect upfront and only aggregate / JSON-convert organizations, managed_node_types_set, events, canonical_facts, and facts when those columns are rendered in the output sheet (previously all 5 were computed for every per-organization sheet and non-dedup direct sheet, then dropped by .reindex(columns=columns)).
  • Testing

    Steps to Test

    1. Run focused unit tests:

       pytest metrics_utility/test/test_helpers.py \
         metrics_utility/test/test_automation_controller_billing_helpers_pure.py \
         metrics_utility/test/test_dataframe_engine_base.py \
         metrics_utility/test/test_dataframe_inventory_scope.py \
         metrics_utility/test/test_report_base.py \
         metrics_utility/test/test_report_renderers.py -v
       

    2. Run paired alternating-order benchmarks (3 pairs in separate processes) of full 31-day / 124-archive synthetic CCSPv2 XLSX reports (all optional sheets, ccsp-experimental) on a containerized AAP cont_b Controller (automation-controller-task, Python 3.12.16, pandas 3.0.3).

    Expected Results

  • All 356 focused unit tests pass.

  • Fact/set fast-paths + single-parse canonical_facts: median full-report time dropped from 29.153 s to 27.100 s (−7.04%), peak RSS flat (279.05 → 279.25 MiB), all 6 workbook digests matched.

  • Skip discarded node-usage columns: median full-report time dropped from 26.980 s to 26.782 s (−0.73%), peak RSS flat (279.01 → 278.78 MiB), all 6 workbook digests matched (scales linearly with organization count in multi-org reports).
  • (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: 424 lines (+318 / -106) across 5 files Reviewer: redhat-chai-bot Review duration: 1166m
    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 · 424 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.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #658"
    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: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    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%