← Back to Pull requests

[AAP-85133] XLAB Fix: disambiguate duplicate label names by organization instead of de-duplication #389

Closed
unknown closed this pull request without merging on Aug 04, 2026 12:07 UTC
View on GitHub
unknown unknown commented on Aug 04, 2026 11:33 UTC
Author

[AAP-85133] Fix: disambiguate duplicate label names by organization instead of de-duplication

Description


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

  • - removed commit from https://github.com/ansible/metrics-service/pull/387
    - modified label SQL query to also use organization name
  • Why is this change needed?

  • - PR https://github.com/ansible/metrics-service/pull/387 didn't provide the correct fix of de-duplicating labels in response. Labels have a unique ID but a non-unique name, causing the label name duplications within response. For this a different solution has been proposed and this PR is trying to apply it.
  • How does this change address the issue?

  • - By removing the commit from https://github.com/ansible/metrics-service/pull/387 and modifying label SQL query to also use the organization name. The response is also modified to put label-name (org1), label-name (org2) on the duplicate labels to avoid confusion (labels with the same name, different ID) , and label-name where there is a label which is the only one with that name (omitting the organization name)

    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

    Steps to Test


    1. Seed duplicate label rows in the  awx  DB (organization-scoped duplicates, mirrors the bug):
    python manage.py shell -c "
    from django.db import connections
    from django.utils import timezone
    now = timezone.now()
    with connections['awx'].cursor() as c:
        c.execute('DELETE FROM main_label WHERE name IN (%s, %s)', ['labelTest1', 'LabelTest2'])
        c.execute('''
            INSERT INTO main_label (id, created, modified, description, name, organization_id)
            VALUES
            (9001, %s, %s, %s, %s, 1),
            (9002, %s, %s, %s, %s, 2),
            (9003, %s, %s, %s, %s, 1),
            (9004, %s, %s, %s, %s, 2),
            (9005, %s, %s, %s, %s, 1)
        ''', [
            now, now, '', 'labelTest1',
            now, now, '', 'labelTest1',
            now, now, '', 'LabelTest2',
            now, now, '', 'LabelTest2',
            now, now, '', 'LabelTest3',
        ])
    print('seeded')
    "
    

    2. Curl to get a list of labels from the API
     curl -s -u superuser:password "http://localhost:8000/api/v1/dashboard_reports/labels/" | jq
    

    Expected Results


    <!-- Describe what should happen after following the steps -->
    {
      "count": 5,
      "next": null,
      "previous": null,
      "results": [
        {
          "id": 9001,
          "name": "labelTest1 (default_org_hostmetric_2025-06-13)"
        },
        {
          "id": 9002,
          "name": "labelTest1 (default_org_2025-06-13)"
        },
        {
          "id": 9003,
          "name": "LabelTest2 (default_org_hostmetric_2025-06-13)"
        },
        {
          "id": 9004,
          "name": "LabelTest2 (default_org_2025-06-13)"
        },
        {
          "id": 9005,
          "name": "LabelTest3"
        }
      ]
    }
    

    As you can see, labels with duplicate names have an added organization name to which they belong while labels with no duplicates, only have their name without the organization name included.

    Additional Context


    NOTE: The backport of #387 will also need to be reverted on the downstream.

    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: https://github.com/ansible/metrics-service/pull/390 - a revert of https://github.com/ansible/metrics-service/pull/387

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

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