← Back to Pull requests

[AAP-101700] XLAB Unify hourly sync and backfill job definition and update existing data #543

Closed
unknown closed this pull request without merging on Nov 27, 2026 05:38 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 15:26 UTC
Author

[AAP-101700] Unify hourly sync and backfill job definition and update existing data

Description


<!-- Mandatory: Provide a clear, concise description of the changes and their purpose -->
  • What is being changed?

  • - added a new column launch_type to jobdata model - a new migration is added
  • Why is this change needed?

  • - to be able to unify hourly sync and backfill job definition
  • How does this change address the issue?

  • - see above

    Type of Change


    <!-- Mandatory: Check one or more boxes that apply -->
  • 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


    <!-- These items help ensure quality - they complement our automated CI checks -->
  • 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


    <!-- Optional for test-only changes. Mandatory for all other changes -->
    <!-- Must be detailed enough for reviewers to reproduce -->

    Prerequisites


  • metrics-utility>=0.8.20261118 (released; includes ansible/metrics-utility#640). uv sync installs it

  • .env sourced, compose stack up (make compose), then migrate and register tasks:

  •   python manage.py migrate
      python manage.py metrics_service init-service-id
      python manage.py metrics_service init-default-settings
      python manage.py metrics_service init-system-tasks
      

  • API and dispatcher running (tools/dev.sh --init, admin/admin).

  • Controller demo data in the AWX DB. Run these three SQL steps in order with any SQL client (e.g. psql -h <host> -U <user> -d <awx_db>):

  • 1. Stand-in template/project row. tools/seed-awx-demo.sql assumes template and project id 1 exist, and on an empty AWX DB they don't:
    <details><summary>SQL</summary>

         BEGIN;
         INSERT INTO main_unifiedjobtemplate (id, created, modified, description, name, last_job_failed, status, org_unique)
         VALUES (1, now(), now(), 'stand-in', 'demo-template-project', false, 'never updated', false);
         INSERT INTO main_project (unifiedjobtemplate_ptr_id, local_path, scm_type, scm_url, scm_branch, scm_clean, scm_delete_on_update, scm_update_on_launch, scm_update_cache_timeout, timeout, scm_revision, playbook_files, inventory_files, scm_refspec, allow_override, scm_track_submodules)
         VALUES (1, '', '', '', '', false, false, false, 0, 0, '', '[]', '[]', '', false, false);
         INSERT INTO main_jobtemplate (unifiedjobtemplate_ptr_id, job_type, playbook, forks, "limit", verbosity, extra_vars, job_tags, force_handlers, skip_tags, start_at_task, become_enabled, host_config_key, ask_variables_on_launch, survey_enabled, survey_spec, ask_limit_on_launch, ask_inventory_on_launch, ask_credential_on_launch, ask_job_type_on_launch, ask_tags_on_launch, allow_simultaneous, ask_skip_tags_on_launch, timeout, use_fact_cache, ask_verbosity_on_launch, ask_diff_mode_on_launch, diff_mode, job_slice_count, ask_scm_branch_on_launch, scm_branch, webhook_key, webhook_service, ask_execution_environment_on_launch, ask_forks_on_launch, ask_instance_groups_on_launch, ask_job_slice_count_on_launch, ask_labels_on_launch, ask_timeout_on_launch, prevent_instance_group_fallback)
         VALUES (1, 'run', 'site.yml', 5, '', 0, '{}', '', false, '', '', false, '', false, false, '{}', false, false, false, false, false, false, false, 0, false, false, false, false, 1, false, '', '', '', false, false, false, false, false, false, false);
         COMMIT;
         

    </details>
    2. Run the contents of tools/seed-awx-demo.sql (12 manual/scheduled jobs; safe to repeat). With psql: -f tools/seed-awx-demo.sql.
    3. The seed has no sync/workflow jobs, so set one of each:
         UPDATE main_unifiedjob SET launch_type = 'sync' WHERE id = (SELECT min(id) FROM main_unifiedjob WHERE launch_type = 'manual');
         UPDATE main_unifiedjob SET launch_type = 'workflow' WHERE id = (SELECT max(id) FROM main_unifiedjob WHERE launch_type = 'manual');
         

    Result: 12 jobs (6 manual, 4 scheduled, 1 sync, 1 workflow). The seed jobs have no polymorphic_ctype, so the collector logs returned N rows without a usable model. This is harmless.

    The snippets below run in manage.py shell with:

    from decimal import Decimal
    from apps.tasks.tasks import TASK_FUNCTIONS
    from apps.tasks.models import Task
    from apps.dashboard_reports.models import JobData, SubscriptionCost
    

    Steps to Test


    1. Migration: python manage.py makemigrations --check --dry-run reports no changes, and dashboard_reports.0005_jobdata_launch_type is applied (showmigrations dashboard_reports).
    2. Update task, existing install (initial collection completed):
       from apps.tasks.models import Task
       Task.objects.filter(name='initial_dashboard_collection').update(status='completed')
       TASK_FUNCTIONS['update_dashboard_job_definition']()   # run twice
       

    - The result has no skipped key and shows processed/updated/added/failed.
    - The second run adds nothing and JobData.objects.count() doesn't grow (idempotent).
    - To simulate pre-migration rows, run JobData.objects.update(launch_type=None) and run the task again. Expect updated: 12, added: 0 and no NULL launch_type left.
    3. Update task, any initial collection status: for each of pending, running, failed, cancelled, set the status of initial_dashboard_collection, run JobData.objects.update(launch_type=None), then run update_dashboard_job_definition. It always runs (no skipped key): the NULL rows get launch_type filled and missing jobs are added. Set the status back to completed afterwards.
    4. Backfill (cursor pagination): the batch size is the setting DASHBOARD_COLLECTION.BACKFILL_BATCH_SIZE, not a task parameter (default 5000).
       export METRICS_SERVICE_DASHBOARD_COLLECTION__BACKFILL_BATCH_SIZE=5
       

    In manage.py shell, run JobData.objects.all().delete(), then TASK_FUNCTIONS['collect_dashboard_reports_initial_data']().
    - The logs show Synced batch of 5 jobs (total so far: 5), then ... 10, then Synced batch of 2 jobs (total so far: 12).
    - JobData has all 12 jobs, with no gaps or repeats, and all four launch types.
    5. Hourly hook: with the dispatcher running, delete the old chunks and rows, then run the hook for each UTC hour that contains jobs (the seed uses the previous four full hours):
       from apps.tasks.models import Task
       Task.objects.filter(function_name='sync_dashboard_job_records').delete()
       JobData.objects.all().delete()
       TASK_FUNCTIONS['collect_hourly_metrics'](collector_type='unified_jobs', hour_timestamp='2026-11-16T05:00:00+00:00')  # one call per hour, ~20s apart
       

    The hook queues sync_dashboard_job_records tasks, which the dispatcher runs. Wait until they're completed. A task that hit Could not acquire lock 'sync_dashboard_job_records' retries after about 8 minutes (existing lock behavior). Then check that JobData holds all 12 jobs, including sync and workflow, with launch_type set.
    6. Read-time filtering:
       curl -su admin:admin localhost:8000/api/v1/dashboard_reports/report/
       

    - runs is 10 (6 successful, 4 failed) out of 12 stored jobs. JobData.objects.exclude(launch_type__in=['sync','workflow']).count() is 10.
    - The details, export and leaderboard endpoints use the same filter. sync and workflow jobs must not appear, and results for existing jobs are unchanged.
    7. Subscription cost (instance method):
       from decimal import Decimal
       from apps.dashboard_reports.models import SubscriptionCost
       sc = SubscriptionCost(monthly_subscription_cost=Decimal('1000'))
       sc.per_second_subscription_cost()          # 0.1388888889 (sync/workflow excluded)
       JobData.objects.filter(launch_type__in=['sync', 'workflow']).update(launch_type='manual')
       sc.per_second_subscription_cost()          # 0.1157407407 (sync/workflow counted)
       TASK_FUNCTIONS['update_dashboard_job_definition']()   # restores launch_type
       

    Rows with NULL launch_type (legacy) still count.

    Expected Results


  • The migration applies cleanly, with no pending model changes.

  • Backfill, update task and hourly hook use the same job definition (apps/dashboard_reports/job_definition.py).

  • The backfill pages through all jobs with no gaps or repeats.

  • The update task always runs, whatever the status of the initial collection. It fills in launch_type and missing jobs without duplicating rows, and a second run changes nothing.

  • The hourly hook stores sync and workflow jobs.

  • Dashboard endpoints return the same results as before: sync and workflow jobs are hidden at read time.

  • per_second_subscription_cost excludes sync/workflow rows. Legacy NULL rows still count.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: kcagran Review duration: 21012m
    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 #543"
    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%