← Back to Pull requests

AAP-101932 XLAB Add POST report query endpoints with select_all/exclude #547

Closed
unknown closed this pull request without merging on Nov 23, 2026 05:34 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 11:10 UTC
Author

AAP-101932 XLAB Add POST report query endpoints with select_all/exclude

Description


  • What: The dashboard reports API gets read-only POST counterparts of the report endpoints and new selection

  • parameters for the report filters (select all, search, exclude).
  • Why: The UI sends the selected filter IDs in the query string. With large selections (hundreds of templates,

  • labels, organizations or projects) the URL exceeds the length limits of the gateway/proxies and the request fails.
    The UI also cannot express "all except N" or "everything matching a search" without listing every ID. The design
    was agreed in spike AAP-101273.
  • How:

  • - POST query endpoints in DashboardReportViewSet. They return the same data as the matching GET endpoints:
    - POST /dashboard_reports/report/query/ → GET report/
    - POST /dashboard_reports/report/details/query/ → GET report/details/
    - POST /dashboard_reports/report/export/query/ → GET report/export/ (CSV)

    Filters go in the JSON body and are validated by ReportQuerySerializer. Pagination and ordering stay in the
    query string (page, page_size, order_by). These are separate query actions because POST on the list route
    is reserved for create.
    - Shared parameter source: CustomReportFilter, the filter option helpers and the period parsing read their
    values from a single source. POST query actions use request.data and GET uses request.query_params. Both go
    through the same code path, so they return identical results.
    - Permissions: new apps/core/permissions.py::IsSystemAdminOrAuditorReadQuery. DAB's IsSystemAdminOrAuditor
    allows platform auditors only on safe methods, which would lock them out of the POST query endpoints. A view
    lists its side-effect-free actions in read_only_query_actions, and those actions need only the view
    permission. Every other action keeps the parent behaviour, so writes stay admin-only.
    - Selection parameters: for each filter field (template, label, organization, project), on both GET and
    POST:

    | Parameter | Meaning |
    |---|---|
    | <field>=<id> (existing) | explicitly selected IDs |
    | select_all_<field>=true | every item, the same as no filter on that field |
    | search_<field>=<term> | every item whose name matches the term |
    | excluded_<field>=<id> | explicitly deselected IDs |
    | excluded_search_<field>=<term> | deselected: every item whose name matches the term |

    - With select_all, every job is kept, then excluded IDs and excluded search matches are removed.
    - Without select_all, jobs matching the selected IDs or search matches are kept, then the exclusions are
    removed.
    - select_all includes historical runs of deleted items and rows with NULL IDs, the same as no filter.
    - Labels: excluding label X excludes every job that has X, even if it also has a selected label Y.
    - Search terms are resolved on every request, so a saved or shared selection also picks up items created later.
    Their number and length are capped on GET and POST alike (100 terms, 512 characters each; 400 otherwise).
    The terms of all fields are validated before the AWX connection is opened.
    - No writes from the query actions: the report cost calculation reads the subscription cost with the new
    SubscriptionCost.get_or_default(), which returns the existing row or unsaved defaults. On an empty table the
    POST query actions use the same default values as GET but never create the row. GET is unchanged.
    - OpenAPI: the request body and the selection parameters are documented. The checked-in schema files
    (tools/openapi-schema/metrics-service.{yaml,json}) are regenerated with tools/generate-openapi.sh.

    Type of Change


  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Documentation update

  • Test update

  • Refactoring (no functional changes)

  • Development environment change

  • Configuration change
  • Self-Review Checklist


  • I have performed a self-review of my code

  • I have added relevant comments to complex code sections

  • I have updated documentation where needed

  • I have considered the security impact of these changes

  • I have considered performance implications

  • I have thought about error handling and edge cases

  • I have tested the changes in my local environment
  • Testing Instructions


    Prerequisites


  • metrics-service with dashboard data (JobData) synced from AWX.

  • Users: a system admin, a platform auditor and a regular user.

  • For the gateway check: a local AAP deployment with Platform Gateway.
  • Steps to Test


    1. Run the unit tests:
    uv run pytest tests/unit/dashboard_reports/test_report_query_endpoints.py tests/unit/dashboard_reports/test_report_selection.py tests/unit/core/test_permissions.py
    2. As an admin, call GET /api/v1/dashboard_reports/report/?template=1&template=2 and
    POST /api/v1/dashboard_reports/report/query/ with the body {"template": [1, 2]}, and compare the responses.
    Repeat for report/details/ and report/export/.
    3. Call POST .../report/query/ with {"select_all_template": true, "excluded_template": [1]} and check that all
    templates except 1 are included.
    4. Call POST .../report/query/ with {"search_template": ["deploy"]} and check that only templates whose name
    matches "deploy" are included.
    5. Repeat step 2 as the platform auditor and as the regular user.
    6. Call GET .../report/details/ with 101 search_template values, or one value longer than 512 characters.
    7. On a database without a subscription cost row (SubscriptionCost.objects.all().delete()), call the three POST
    query endpoints and check SubscriptionCost.objects.exists().

    Expected Results


  • GET and POST return identical data for the same filters, including pagination and ordering.

  • "All except N" excludes exactly those N items. Excluding a label also excludes jobs that have another selected

  • label.
  • A search that matches nothing returns no data.

  • Admin: 200. Platform auditor: 200 on the query endpoints, 403 on any other POST/PATCH/PUT/DELETE. Regular user:

  • 403 everywhere.
  • Invalid bodies (wrong date format, non-integer IDs, too many search terms) return 400 with field errors.

  • Step 6 returns 400 keyed by the parameter name, and AWX is not queried. Exactly 100 terms or 512 characters

  • are accepted.
  • Step 7: the endpoints return 200 with the default costs, and SubscriptionCost.objects.exists() stays False.
  • Additional Context


  • Verified through the Platform Gateway on a local aap-dev deployment (admin, auditor and regular user, all three

  • POST endpoints including CSV export): 13/13 checks passed.
  • Verified against the UI branch xlab-dashboard-filters-select-all (ansible-ui). The UI never sends an empty list

  • (an empty selection means no filter) and builds page/page_size/order_by itself.
  • Pre-existing, not changed here: the next/previous pagination links do not include the gateway prefix. This is

  • the same on GET.
  • Full test suite passes locally (3323 passed; only the 2 Segment integration tests fail, they need the mock

  • Segment server), ruff clean, CI green.

    Required Actions


    <!-- Check if changes require work in other areas -->
    <!-- Remove section if no external actions needed -->
  • Requires documentation updates

  • <!-- API docs, feature docs, deployment guides -->
  • Requires downstream repository changes

  • <!-- Specify repos: django-ansible-base, eda-server, etc. -->
  • Requires infrastructure/deployment changes

  • <!-- CI/CD, installer updates, new services -->
  • Requires coordination with other teams

  • <!-- UI team, platform services, infrastructure -->
  • Blocked by PR/MR: #XXX

  • <!-- Reference blocking PRs/MRs with brief context -->

    Screenshots/Logs


    <!-- Add if relevant to demonstrate the changes -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: kcagran Review duration: 5424m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #547"
    general weight: 0.35
    Reviewers
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%