← Back to Pull requests

[AAP-94021] XLAB Rename gamification to leaderboard and respond with 404 when disabled #437

Closed
unknown closed this pull request without merging on Sep 30, 2026 08:50 UTC
View on GitHub
unknown unknown commented on Sep 23, 2026 15:26 UTC
Author

[AAP-94021] Rename gamification to leaderboard and respond with 404 when disabled

Description


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

  • Renamed show_gamification to show_leaderboard (including the uppercase variant)
    with this change, I also added a migration script as suggested by the chai bot: https://github.com/ansible/metrics-service/pull/437#issuecomment-5833918255
    Made leaderboard API inaccesible for authenticated users if leaderboard is disabled - response status 404 with a detail message for admins
    Added last_sync to the collection status endpoint, which resolves AAP-92922
    Updated leaderboard and collection_status tests to reflect the changes
  • Why is this change needed?

  • it was decided that calling the feature "leaderboard" makes more sense than calling it "gamification"
    since leaderboard settings were not in yet when leaderboard API endpoint was made, there was no way of checking whether it was being enabled or not. Since this is now available, we needed a way to not allow authenticated users to see the leaderboard when it is disabled.
  • How does this change address the issue?

  • see descriptions 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 local environment. Make sure metrics_service is running.

    1. Run a local instance (or docker compose) for AWX and Metrics Service databases with all recent migrations
    2. Update your environment variables to match your local setup - https://github.com/ansible/metrics-service#quick-start-1
    3. To exercise the last_sync steps below, ensure AWX has at least one main_unifiedjob/main_job row with status IN ('successful','failed'), launch_type NOT IN ('sync','workflow'), and finished timestamp within the previously completed hour (e.g. if now is 11:15, finished between 10:00–11:00) — otherwise hourly_unified_jobs will find no data to sync.
    4. Django superuser superuser - system auditor or admin

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

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

    Steps to Test


    1. List collection status data (show_leaderboard should be set to true by default)
    curl -kv -s -u superuser:password \
      "http://localhost:8000/api/v1/dashboard_reports/collection_status/" | jq
    

    2. As normal user, try accessing leaderboard API endpoint (should get leaderboard data response with HTTP status 200)
    curl -kv -s -u normal:normal "http://localhost:8000/api/v1/dashboard_reports/leaderboard/" | jq
    

    3. Change show_leaderboard to false - should be true in previous step (by default)
    curl -kv -s -u superuser:password \
      -X POST "http://localhost:8000/api/v1/dashboard_reports/collection_status/" \
      -H "Content-Type: application/json" \
      -d '{"show_leaderboard": false}' | jq
    

    4. Repeat step 1 to verify
    5. Repeat step 2 once again as this time, you should get response 404 with a detail message
    6. Verify last_sync starts as None on a fresh instance (repeat step 1, check the field)
    7. Trigger an hourly sync task to produce a successful sync_dashboard_job_records execution
    uv run tools/tasks/run_task.py hourly_unified_jobs
    

    8. Repeat step 1 — last_sync should now show a timestamp (e.g. "2026-09-29T11:03:06.711039Z")
    9. (Optional) Simulate a failed sync execution afterwards and confirm last_sync still reflects the last successful run, not the failed one
    python manage.py shell -c '
    from apps.tasks.models import Task, TaskExecution
    task = Task.objects.filter(function_name="sync_dashboard_job_records").first()
    TaskExecution.objects.create(task=task, status="failed")
    '
    

    Expected Results


    curl calls on the collection status endpoint should now work with show_leaderboard instead of show_gamification
    before disabling the leaderboard (in step 3), the default value should be used and thus when trying to access the leaderboard endpoint (step 2), we should get a nice JSON data response with HTTP status 200
    after disabling the leaderboard (step 3) and then trying to access the leaderboard endpoint (step 5), this time, we should be met with a response code 404 and a JSON with a detail message for admins
    collection status response in step 1 should show last_sync as None (if it's a fresh instance with no syncs at all yet) or a timestamp similar to "2026-09-28T13:10:01.496367Z"

    Additional Context


    When the leaderboard endpoint was created, we didn't have the gamification (leaderboard) settings ready yet and the 404 status could not have been added at that point. With this in mind, I implemented this small fix alongside the renaming fix.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: kcagran Review duration: 9684m
    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 #437"
    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%