← Back to Pull requests

[AAP-99276] XLAB Make time-estimating fields configurable across all job templates #500

Closed
unknown closed this pull request without merging on Oct 28, 2026 07:18 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 13:55 UTC
Author

[AAP-99276] Make time-estimating fields configurable across all job templates

Description


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

  • - Added an additional PATCH endpoint to TemplateMetadata viewset that does a partial update across all template metadata objects. So if "Time taken to manually execute" and/or "Time taken to create automation" is updated through this endpoint, the change will be applied to all, not just one.
    - Added an additional GET endpoint to list all the TemplateMetadata objects (I used this mostly for e2e testing of the PATCH endpoint feature)
  • Why is this change needed?

  • - Users want to be able to set the time estimates across all job templates instead of just individual job templates
  • How does this change address the issue?

  • - See description 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


    <!-- List any specific setup required -->

    Follow README.md to set up a local environment. Make sure  metrics_service  is running on  localhost:8000 .

    1. Run local AWX and Metrics Service databases with all recent migrations.
    2. Create the Django superuser  superuser  (admin or system auditor):

    DJANGO_SUPERUSER_PASSWORD=password \
      .venv/bin/python manage.py createsuperuser \
      --username superuser --email superuser@user.com --noinput
    

    3. Create a normal user  normal :
    python manage.py shell -c '
    from django.contrib.auth import get_user_model
    
    User = get_user_model()
    User.objects.create_user(username="normal", email="normal@user.com", password="normal")
    '
    

    4. Create 5 AWX job templates and a matching  TemplateMetadata  row for each. The command prints each row's  metadata_id , which is the  <ID>  used in the steps below:
    python manage.py shell -c '
    from apps.dashboard_reports.models import TemplateMetadata
    from apps.tasks.utils import get_db_connection
    
    conn = get_db_connection("awx")
    with conn.cursor() as cur:
        for i in range(1, 6):
            name = f"manual-test-template-{i}"
            cur.execute(
                "INSERT INTO main_unifiedjobtemplate (created, modified, description, name, last_job_failed, status, org_unique) "
                "VALUES (now(), now(), %s, %s, false, %s, false) RETURNING id",
                ["", name, "never updated"],
            )
            tid = cur.fetchone()[0]
            cur.execute(
                "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 (%s, %s, %s, 0, %s, 0, %s, %s, false, %s, %s, false, %s, false, "
                "false, %s, false, false, false, false, false, false, false, 0, false, false, false, false, 1, false, %s, %s, %s, "
                "false, false, false, false, false, false, false)",
                [tid, "run", "hello.yml", "", "", "", "", "", "", "{}", "", "", ""],
            )
            meta, _ = TemplateMetadata.objects.get_or_create(template_id=tid, defaults={"template_name": name})
            print("template_id", tid, "metadata_id", meta.pk, name)
    '
    

    Steps to Test


    1. Check the current values of one metadata row. Both fields can be  null  for rows created in the prerequisites:
    curl -s -u superuser:password \
      "http://localhost:8000/api/v1/dashboard_reports/template_metadata/<ID>/" | jq
    

    2. Set one field on ALL template metadata records. Expect HTTP 200 and  {"updated": N} :
    curl -s -u superuser:password \
      -X PATCH "http://localhost:8000/api/v1/dashboard_reports/template_metadata/" \
      -H "Content-Type: application/json" \
      -d '{"time_taken_manually_execute_minutes": 30}' | jq
    

    3. Repeat step 1 for several of the 5  <ID> s.  time_taken_manually_execute_minutes  should be  30  for each, and  time_taken_create_automation_minutes  should be unchanged.
    4. Set both fields on all records:
    curl -s -u superuser:password \
      -X PATCH "http://localhost:8000/api/v1/dashboard_reports/template_metadata/" \
      -H "Content-Type: application/json" \
      -d '{"time_taken_manually_execute_minutes": 45, "time_taken_create_automation_minutes": 120}' | jq
    

    5. Repeat step 1 for several of the 5  <ID> s. Both fields should be  45  and  120 .
    6. Validation: a negative value should return HTTP 400:
    curl -s -w "\n%{http_code}\n" -u superuser:password \
      -X PATCH "http://localhost:8000/api/v1/dashboard_reports/template_metadata/" \
      -H "Content-Type: application/json" \
      -d '{"time_taken_create_automation_minutes": -1}'
    

    7. An empty body should return HTTP 400 with a message asking for at least one field:
    curl -s -w "\n%{http_code}\n" -u superuser:password \
      -X PATCH "http://localhost:8000/api/v1/dashboard_reports/template_metadata/" \
      -H "Content-Type: application/json" -d '{}'
    

    8. Unsupported methods: PUT and GET on the collection URL should return HTTP 405:
    curl -s -o /dev/null -w "%{http_code}\n" -u superuser:password -X PUT \
      "http://localhost:8000/api/v1/dashboard_reports/template_metadata/" \
      -H "Content-Type: application/json" -d '{}'
    curl -s -o /dev/null -w "%{http_code}\n" -u superuser:password \
      "http://localhost:8000/api/v1/dashboard_reports/template_metadata/"
    

    9. Permissions: as the  normal  user, repeat step 2. Expect HTTP 403 and no values changed:
    curl -s -w "\n%{http_code}\n" -u normal:normal \
      -X PATCH "http://localhost:8000/api/v1/dashboard_reports/template_metadata/" \
      -H "Content-Type: application/json" \
      -d '{"time_taken_manually_execute_minutes": 1}'
    

    10. Regression: the single-record endpoint still works. Expect HTTP 200 and only that record changed:
    curl -s -u superuser:password \
      -X PATCH "http://localhost:8000/api/v1/dashboard_reports/template_metadata/<ID>/" \
      -H "Content-Type: application/json" \
      -d '{"time_taken_manually_execute_minutes": 10}' | jq
    

    Expected Results


    <!-- Describe what should happen after following the steps -->
  • PATCH template_metadata/  updates only the fields you send, on every existing  TemplateMetadata  record, and returns  {"updated": <count>}. This includes records that were already in your database before the test.

  • Steps 3 and 5 show the new values on all 5 test records.

  • Negative values and an empty body return HTTP 400, PUT and GET on the collection URL return HTTP 405, and a normal user gets HTTP 403.

  • PATCH template_metadata/{id}/  still changes just that one record.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: kcagran Review duration: 8243m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    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
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #500"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    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: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    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: 29.7% · Safe to merge
    29.7%